Search code examples
pythonpyqtsetuptoolspyinstallercpython

Error during building setup script in Python


I have next case:

  1. Desktop application with Python + PySide
  2. Want to use PYD-file (mycore.pyd) in my application
  3. There is one dependency in mycore.pyx file to Padding module
    • this Padding module already installed to the system
  4. I build Setup.py and get converted PYX-file to PYD-file, that I use in application

What I got:

  • Once I run my application under PyCharm => everything is OK
  • when I build application with PyInstaller approach and run the application from cmd => I catch an error "No named module Padding (requests etc)"

Example of setup.py file:

from distutils.core import setup
from Cython.Build import cythonize


extensions = ["mycore.pyx"]

setup(
    name='mycore',
    version='1.0',
    ext_modules=cythonize(extensions),
    #packages=['Padding'], - once tried => "error: package directory 'Padding' does not exist"
)

Any ideas or advises would be great!

UPDATE

Also tried variant with setup_tools, also without success:

from Cython.Build import cythonize
from setuptools import setup, find_packages, Extension, Command


setup(name='mycore',
      packages = find_packages(),
      version=1.0,
      include_package_data=True,
      platforms=['all'],
      ext_modules=[Extension("mycore", ['mycore.c'])],
      #extra_require = {"Padding"} - also nothing
      )

Solution

  • Ask PyInstaller to include the required module during the build process. It seems that the easiest way to do so is with the --hidden-import argument:

    --hidden-import=modulename
    Name an imported Python module that is not visible in your code. The module will be included as if it was named in an import statement. This option can be given more than once.

    Thus, please add the following argument when building the application:

    --hidden-import=Padding


    EDIT:

    Try importing all required modules (that trigger an error) in a separate *.py file, rather than in a *.pyx \ *.pyd file. It's an ugly workaround but might solve the issue nonetheless.

    Consider using an __init__.py file for this scenario.