簡體   English   中英

cx_Freeze:“沒有名為'codecs'的模塊”

[英]cx_Freeze: “No module named 'codecs'”

我一直在拼命試圖將我的python pygame程序編譯為獨立的可執行文件,但沒有成功。 PyInstaller無法與pygame一起正常使用,Nuitka無法使獨立服務器正常工作,並且cx_Freeze正在尋找最佳選擇。 但是,當我使用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

)

還有main.py引用的其他python文件; 這有關系嗎?

非常感謝

編輯:根據要求,平台是Linux(Ubuntu 14.04); python版本是3.4.3; cx_Freeze是cxfreeze 5.0,可通過pip下載。 確切的錯誤為:

Fatal Python error: Py_Initialize: Unable to get locale encoding
Traceback (most recent call last):
File "usr/lib/python3.4/encodings/__init__.py", line 31, in <module>
ImportError: No module named 'codecs'
Aborted (core dumped)

我在Ubuntu 15.10上的cx_Freeze 5.0.1和python 3.4.4有完全相同的問題。 正如@Anthony Tuininga所建議的那樣,從源頭重新安裝python可解決此問題,例如, 從此源頭開始

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM