11

I have a python module module.pyd that works pretty fine once it is put manually onto the site-packages of python installation folder.

The problem starts when I upload my solution to a cloud enviroment, the buildpack requests that I pass every module as a package to be installed with pip install module. I ve created a folder with a simple __init__.py file that just imports everything of the module.pyd so that my module is treated like a folder.

Then I read here http://peterdowns.com/posts/first-time-with-pypi.html how to upload my own module and I succeeded, but when I install my module, the module.pyd file is not copied. I also tried to install it direct by the repository pip install git+repository but the same thing happened.

I have read here https://docs.python.org/2/distutils/sourcedist.html#specifying-the-files-to-distribute that I might have to explicitly say I want to copy *.pyd files in a MANIFEST.in file, I have done it, but it seems not working yet.

I currently using python 2.7.10

I am new on python so I d appreciate you guys help

2
  • Not much of this makes sense, unfortunately. Why do you not want to distribute the actual .py files? Why do you need to put it in site-packages, rather than in your project itself, if it's your own code? May 4, 2016 at 15:03
  • @daniel-roseman Actually I dont have the py files of this module (it is a C++ compilation I think). I just want to place it as a distribution or at least in a repository so the buildpack of the cloud enviroment can access it. But once it install the module, the 'init.py' file is dowloaded, but not the pyd file. I already tried to upload it together with the solution, but I dont know why, it doesn't work May 4, 2016 at 15:15

1 Answer 1

12

Just use the MANIFEST.in:

recursive-include module *.pyd

This will include all pyd files in the module directory.

Your package layout should be the following:

module/
--- __init__.py
--- _module.pyd
--- module.py
MANIFEST.in
README.rst
setup.py

And don't forget to add include_package_data=True in setup() in your setup.py in order to force using MANIFEST.in when building wheels and win32 installers (else MANIFEST.in will only be used for source tarball/zip).

Minimal example of setup():

README_rst = ''
with open('README.rst', mode='r', encoding='utf-8') as fd:
    README_rst = fd.read()

setup(
    name='module',
    version='0.0.1',
    description='Cool short description',
    author='Author',
    author_email='[email protected]',
    url='repo.com',
    packages=['module'],
    long_description=README_rst,
    include_package_data=True,
    classifiers=[
        # Trove classifiers
        # The full list is here: https://pypi.python.org/pypi?%3Aaction=list_classifiers
        'Development Status :: 3 - Alpha',
    ]
)
7
  • Can you elaborate on why you're using module.py and _module.pyd (why add the .py file and rename the .pyd file with an underscore)?
    – florisla
    Aug 9, 2017 at 13:56
  • @florisla ah sorry it might indeed be confusing, _module.pyd is here a SWIG-generated Python module interface to a C++ program, so there is no relation between _module.pyd and module.py, it would probably be less confusing to rename the pyd file to _core.pyd.
    – gaborous
    Aug 9, 2017 at 18:52
  • Then why keep the underscore? You want to make the *.pyd file public, right?
    – florisla
    Aug 11, 2017 at 19:09
  • We wanted to provide a more pythonic interface with docstrings and default named keywords, so the py file basically just redefined functions and classes of the pyd :-) Also the py file managed cross platform compatibility by loading the appropriate pyd, so in my concrete case i had multiple pyd files generated for various platforms.
    – gaborous
    Aug 12, 2017 at 8:20
  • @gaborous ... and you shipped every .pyd file to every platform? Why not just wheel the right .pyd to the right platform?
    – user6767685
    Aug 27, 2019 at 16:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.