cx_freeze 一直在 python/libs 中查找,而不是在已编译的库中查找
cx_freeze keeps looking in python/libs, not in compiled libs
我 cx_freeze
d 一个 Python 程序(从 cx_freeze 4.3.4 移动到 5.0),我有一个问题,显然 cx_freeze 一直在寻找库它需要在 Python 的(Anaconda 的)目录中,而不是在它生成的可执行文件的目录中查找它。
我得到的当前错误如下,因为我正在使用 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])
原来把Process.pyc
重命名为process.pyc
就解决了问题。另一个具有相同问题的文件来自 QtGui 库。文件 QtGUI.pyd
必须重命名为 QtGui.pyd
,然后一切正常。
我 cx_freeze
d 一个 Python 程序(从 cx_freeze 4.3.4 移动到 5.0),我有一个问题,显然 cx_freeze 一直在寻找库它需要在 Python 的(Anaconda 的)目录中,而不是在它生成的可执行文件的目录中查找它。
我得到的当前错误如下,因为我正在使用 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])
原来把Process.pyc
重命名为process.pyc
就解决了问题。另一个具有相同问题的文件来自 QtGui 库。文件 QtGUI.pyd
必须重命名为 QtGui.pyd
,然后一切正常。