我正在尝试使用.exe
制作一个小cx_freeze
。之前我在构建过程中遇到了麻烦,因为它找不到某些自行创建的模块。我现在已经解决了这个问题,在运行Missing modules
后,我不再在python setup.py bdist_msi
输出中看到这些自制模块。
相反,现在在尝试运行生成的'main.exe`后,我看到:
ImportError No module named 'test'
我的项目结构是:
PROJECT
|
SRC
|
setup.py
main.py
test.py
service.py
setup.py
如下:
import sys
from cx_Freeze import setup, Executable
base = None
if sys.platform == "Win32":
base = "Win32GUI"
includes = ["test", "service"] #discovered that self made modules, even in the same directory, had to be added here to not appear in the 'Missing modules'
excludes = []
packages = []
path = []
setup(
name = "a thing",
version = "1.0",
description = "a things description",
author = "author",
author_email = "authors email",
url = "authors url",
options = {"build_exe": {"includes": includes,
"excludes": excludes,
"packages": packages,
"path": path}
},
executables = [Executable("main.py", base = base)]
)
答案 0 :(得分:0)
一般来说,您不需要为自己的模块做任何特殊处理。
我尝试了以下内容,对我来说它运行良好: main.py:
from test import *
if __name__ == "__main__":
mA=A()
mA.b();
test.py:
class A:
def b(self):
print("test")
setup.py:
like yours (without service.py)