cx_Freeze:“没有名为'codecs'的模块”

时间:2017-03-22 20:24:23

标签: python python-3.x pygame cx-freeze

我一直在拼命尝试将我的python pygame程序编译成独立的可执行文件,但没有占上风。 PyInstaller与pygame无法正常工作,Nuitka没有使standalones工作,cx_Freeze看起来是最好的选择。但是,当我使用In[34]: api.GetSearch(raw_query='q=gif&from=NHLJets') Out[34]: []进行编译时,它会生成一组文件,但setup.py可执行文件不会运行。

我的main如下:

setup.py

import sys import cx_Freeze executables = [cx_Freeze.Executable("main.py")] images =["assets/images/1.png","assets/images/2.png","assets/images/3.png","assets/images/4.png","assets/images/5.png","assets/images/6.png","assets/images/7.png","assets/images/8.png","assets/images/tile.png","assets/images/mark.png","assets/images/mine.png","assets/images/overlay.png","assets/images/overlay_2.png","assets/images/background.png"] cx_Freeze.setup( name="Minesweeper", options={"build_exe": {"packages":["pygame"], "include_files":images}}, executables = executables ) 引用了其他python文件;这有关系吗?

非常感谢

编辑: 根据要求,平台是Linux(Ubuntu 14.04); python版本是3.4.3; cx_Freeze是cxfreeze 5.0,通过pip下载。确切的错误如下:

main.py

1 个答案:

答案 0 :(得分:1)

我在Ubuntu 15.10上遇到与cx_Freeze 5.0.1,python 3.4.4完全相同的问题。正如@Anthony Tuininga所建议的,从源代码重新安装python修复了问题,例如来自this source

wget https://www.python.org/ftp/python/3.4.4/Python-3.4.4.tgz
tar xzf Python-3.4.4.tgz

# I had to specify the location of zlib in my case
cd Python-3.4.4
./configure --with-zlib-dir=/usr/lib/x86_64-linux-gnu
sudo make altinstall

然后,我从源代码安装了cx_Freeze

wget https://github.com/anthony-tuininga/cx_Freeze/archive/5.0.1.tar.gz
tar xzf 5.0.1.tar.gz
cd ./cx_Freeze-5.0.1/
python3.4 setup.py build
sudo python3.4 setup.py install

我还从源代码安装了pygame(因为您也在使用它):

wget https://github.com/pygame/pygame/archive/1.9.3.tar.gz
tar xzf 1.9.3.tar.gz
cd ./pygame-1.9.3/
python3.4 setup.py build
sudo python3.4 setup.py install