简体   繁体   中英

Using Py2exe on whole package

I have a package that I am trying to package for Windows using py2exe. I can run the setup script and generate the executable just fine, but when I run it, I get an error that one of the modules in my package is not available for import. The error says: ImportError: No module named 'some_functions' This is the structure of the project:

project/
    setup.py
    icon.ico
    my_module/
        __init__.py
        some_functions.py
        __main__.py

This is my setup.py

from distutils.core import setup
import py2exe

setup(
    version='1.1.1',
    console=[{
        'script': 'my_module/__main__.py',
        'icon_resources': [(1, 'icon.ico')],
        'dest_base': 'module'
    }],
    options={
        'py2exe': {
            'includes': [
                'requests'
            ],
            'bundle_files': 1
        }
    }
)

This is my __main__.py

from some_functions import important

print(important(10, 20))

And some_functions.py

def important(x, y):
    return x * y

What am I doing wrong??

It's been quite a long time since this question was asked but I was stuck with the same problem recently and I happen to find a solution that worked for me.

The module is not found because the setup.py file is in the parent directory. To work around this problem I just add the module directory to the path before calling setup(...) in the setup.py file:

sys.path.insert(0, 'my_module')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM