I cx_freeze
da Python程序(从cx_freeze 4.3.4迁移到5.0),我有一个问题,显然cx_freeze一直在寻找Python所需的库(Anaconda' s) )目录,而不是在它生成的可执行文件的目录中查找它。
我现在得到的错误如下,因为我正在使用multiprocessing
:
Traceback (most recent call last):
File "D:\Anaconda3\lib\site-packages\cx_Freeze\initscripts\__startup__.py", line 12, in <module>
__import__(name + "__init__")
File "D:\Anaconda3\lib\site-packages\cx_Freeze\initscripts\Console.py", line 21, in <module>
scriptModule = __import__(moduleName)
File "Main.py", line 4, in <module>
File "D:\Anaconda3\lib\multiprocessing\__init__.py", line 16, in <module>
from . import context
File "D:\Anaconda3\lib\multiprocessing\context.py", line 5, in <module>
from . import process
ImportError: cannot import name 'process'
你看到的目录是我的Python安装!!!!为什么看那里?现在在冻结的程序中,如果我转到:myFrozenProgram/multiprocessing/
,我会找到一个名为Process.pyc
的文件!
我的设置脚本如下。它比平时稍微复杂一点,因为我在numpy中添加了自定义dll,因为过去发生了一个问题。由于tcl:
的错误,我添加了TCL部分import sys
import os
import json
import glob
from cx_Freeze import setup, Executable
from GUI.Meta import *
import os
PythonPath = os.path.split(sys.executable)[0] #get python path
os.environ['TCL_LIBRARY'] = os.path.join(PythonPath,"tcl","tcl8.6")
os.environ['TK_LIBRARY'] = os.path.join(PythonPath,"tcl","tk8.6")
mkl_files_json_file = glob.glob(os.path.join(PythonPath, "conda-meta","mkl-[!service]*.json"))[0] #json files that has mkl files list (exclude the "service" file)
with open(mkl_files_json_file) as file:
mkl_files_json_data = json.load(file)
numpy_mkl_dlls = mkl_files_json_data["files"] #get the list of files from the json data file
np_dlls_fullpath = list(map(lambda currPath: os.path.join(PythonPath,currPath),numpy_mkl_dlls)) #get the full path of these files
includefiles = [("GUI/icon.png","GUI/icon.png") + np_dlls_fullpath
target = Executable("Main.py",
#base = "Win32GUI",
icon = "GUI/icon.ico",
targetName="MyProg.exe")
setup(
name = "My program",
version = SOFTWARE_VERSION,
description = "Program",
options = {'build_exe': {'include_files':includefiles, 'includes': ["sip","re","atexit","PyQt5.QtCore","PyQt5.QtGUI","PyQt5.QtWidgets","multiprocessing"]}},
executables = [target])
答案 0 :(得分:3)
事实证明,将Process.pyc
重命名为process.pyc
可以解决问题。另一个具有相同问题的文件来自QtGui库。 <{1}}文件必须重命名为QtGUI.pyd
,然后一切正常。