我正在尝试使用py2exe编译一个用Python 2.7(32位)编写的眼睛跟踪实验。这个实验使用了心理学图书馆。我使用PyCharm IDE编写了这个实验,当我在位于C:UsersphilPython_2.7_32-bit
的虚拟环境中使用解释器通过PyCharm IDE运行它时,这个实验就会运行。
当我在命令提示符中输入以下命令时,实验编译没有产生任何错误:C:UsersphilPython_2.7_32-bitScriptspython.exe C:UsersphilPycharmProjectsiTRACVisSearchsetup.py py2exe
。
当我运行由上述py2xe命令生成的可执行文件时,我会得到以下错误:
Traceback (most recent call last):
File "VisualSearch.py", line 3, in <module>
File "psychopy__init__.pyc", line 39, in <module>
File "psychopypreferences__init__.pyc", line 5, in <module>
File "psychopypreferencespreferences.pyc", line 172, in <module>
File "psychopypreferencespreferences.pyc", line 33, in __init__
File "psychopypreferencespreferences.pyc", line 98, in loadAll
File "psychopypreferencespreferences.pyc", line 146, in loadAppData
File "psychopypreferencesconfigobj.pyc", line 583, in __getitem__
KeyError: 'builder'
我的setup.py脚本如下:
from distutils.core import setup
import py2exe
setup(windows =['C:UsersphilPycharmProjectsiTRACVisSearchVisualSearch.py'])
我还尝试使用以下setup.py脚本,结果相同:
from distutils.core import setup
import py2exe
setup(windows = [{'script':'C:UsersphilPycharmProjectsiTRACVisSearchVisualSearch.py',
'options' : {'py2exe':{'includes':['psychopy'],
'compressed': True,
'bundle_files': 1,}}}])
我在谷歌上搜索了这个错误,得到了0个结果。
有人能告诉我为什么会遇到这个错误吗
这可能是一个丢失的config/prefs文件。PsychoPy使用configobj库来读取和验证首选项,但我的猜测是py2exe只是自动打包py/pyc文件,需要将.spec文件包含在PsychoPy/preferences文件夹中。