I have implemented a package names myUtils, it consists of folder 'myUtils', file 'init.py' and a number of *.py files with names != 'myUtils'. This package is included in myOtherProject.py and can be found/used when I run them from Eclipse.
我已经实现了一个包名myUtils,它由文件夹的myUtils、file 'init组成。和一些*。有名字的py文件!= 'myUtils'。这个包包含在myOtherProject中。当我从Eclipse运行它们时,可以找到/使用py。
However, when I run py2exe on myOtherProject.py, resulting exe cannot find this module(error message "ImportError: no module named myUtils"). Trimmed version of my setup.exe:
但是,当我在myOtherProject上运行py2exe时。py,结果exe无法找到这个模块(错误消息“ImportError: no模块命名为myUtils”)。精简版的我的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 could I fix this? I am using Python 2.7 on WinXP.
我怎么解决这个问题?我在WinXP上使用Python 2.7。
2 个解决方案
#1
2
put your sys.path.append()
line BEFORE the import
statement. Better yet, modify your PYTHONPATH (i'm not sure how to do this on windows, but i'm sure Google can tell you how)
在import语句之前添加sys.path.append()行。更好的是,修改您的PYTHONPATH(我不知道如何在windows上执行这个操作,但是我确信谷歌可以告诉您)
#2
2
I did not define PYTHONPATH properly; there were spaces after semicolons. Instead of
我没有恰当地定义PYTHONPATH;分号之后是空格。而不是
c:\aa\; c:\bb\; c:\cc\
it needed to be
它需要
c:\aa;c:\bb;c:\cc
For packages that are defined using init.py (package MyPackage corresponds to a folder MyPackage, that contains init.py and some other files, without MyPackage.py), path that I needed to add to PYTHONPATH was not
对于使用init定义的包。py(包MyPackage对应一个文件夹MyPackage,包含init)。py和其他一些文件,没有MyPackage.py),我需要添加到PYTHONPATH的路径不是。
<path_to_MyPackage>\MyPackage
but just
但就
<path_to_MyPackage>
...
…
#1
2
put your sys.path.append()
line BEFORE the import
statement. Better yet, modify your PYTHONPATH (i'm not sure how to do this on windows, but i'm sure Google can tell you how)
在import语句之前添加sys.path.append()行。更好的是,修改您的PYTHONPATH(我不知道如何在windows上执行这个操作,但是我确信谷歌可以告诉您)
#2
2
I did not define PYTHONPATH properly; there were spaces after semicolons. Instead of
我没有恰当地定义PYTHONPATH;分号之后是空格。而不是
c:\aa\; c:\bb\; c:\cc\
it needed to be
它需要
c:\aa;c:\bb;c:\cc
For packages that are defined using init.py (package MyPackage corresponds to a folder MyPackage, that contains init.py and some other files, without MyPackage.py), path that I needed to add to PYTHONPATH was not
对于使用init定义的包。py(包MyPackage对应一个文件夹MyPackage,包含init)。py和其他一些文件,没有MyPackage.py),我需要添加到PYTHONPATH的路径不是。
<path_to_MyPackage>\MyPackage
but just
但就
<path_to_MyPackage>
...
…