问题描述
使用py2exe,使用在找到的说明创建脚本的exe版本。 该脚本可以很好地编译并分别生成一个dist和build文件夹,但是当我在命令行上运行该程序时,会出现此错误。 注意,该脚本可以在我的IDE环境下正常运行,但是我打算给同事一个exe版本。如何解决此错误?
Traceback (most recent call last):
File "tester2.py", line 4, in <module>
ImportError: No module named mechanize
这是setup.py文件:
from distutils.core import setup
import py2exe
setup(
console = ['tester2.py'],
zipfile = None,
)
1楼
您必须声明您的依赖项。 这是我的设置
setup(
executables=executables,
options=options,
name='bla',
version='0.3',
packages=[...],
url='',
license='',
author='',
author_email='',
description='', requires=['pandas', 'unidecode', 'click',
'xlsxwriter'] // you would have to add mechanize here
)
2楼
您是否已将文件添加到内部版本?
请查看setup.py
中的include
选项:
另外,这是我针对类似问题的解决方案,该解决方案是如何添加文件以构建并稍后运行: