Py2exe ImportError: there is no module named <package i immedmented>

I implemented myUtils package names, it consists of a folder "myUtils", a file " init .py" and several * .py files with the names! = 'MyUtils'. This package is included in myOtherProject.py and can be found / used when I run them from Eclipse.

However, when I run py2exe on myOtherProject.py, as a result, exe cannot find this module (error message "ImportError: no module named myUtils"). Trimmed versions of my setup.exe:

from distutils.core import setup import py2exe, sys sys.path.append(pathTo_myUtils) import myUtils # this line works fine even if I comment out sys.path.append(...) data_files_ = (('.', ["C:\\Python27\\DLLs\\MSVCP90.dll", "C:\\Python27\\lib\\site-packages\\Pythonwin\\mfc90.dll"])) setup(windows=['myOtherProject.py'], options={'py2exe': {'excludes': ['tcl'], 'includes': ['myUtils'], 'dll_excludes': ['tk85.dll', 'tcl85.dll'] }}, data_files=data_files_) 

How can i fix this? I am using Python 2.7 on WinXP.

+4
source share
2 answers

I did not correctly define PYTHONPATH; there were spaces after the comma. Instead

 c:\aa\; c:\bb\; c:\cc\ 

he needs to be

 c:\aa;c:\bb;c:\cc 

For packages that are defined using init .py (the MyPackage package corresponds to the MyPackage folder containing init .py and some other files without MyPackage.py), the path I needed to add to PYTHONPATH was not

 <path_to_MyPackage>\MyPackage 

but just

 <path_to_MyPackage> 

...

+2
source

put the line sys.path.append() BEFORE the import statement. Better yet, change your PYTHONPATH (I'm not sure how to do this on Windows, but I'm sure Google can tell you how)

+2
source

Source: https://habr.com/ru/post/1444168/


All Articles