auto-py-to-exe似乎是一个非常简单的转换器,每次都对我有用。
请注意,如果您的脚本中有任何路径(导致纹理、声音等),您需要通过执行以下操作获取它们的绝对路径以使用包:
def resource_path(relative_path):
# Get absolute path to resource, works for dev and for PyInstaller
try:
# PyInstaller creates a temp folder and stores path in _MEIPASS
base_path = sys._MEIPASS
except AttributeError:
base_path = os.path.abspath(".")
return os.path.join(base_path, relative_path)
特定于 modulenotfound 错误,检查这是否有帮助:https ://nitratine.net/blog/post/issues-when-using-auto-py-to-exe/#how-to-fix-specific-issues
“这意味着一个特定的模块(在这种情况下是'x')没有添加到包中。我已经看到熊猫库和win32api中的包发生这种情况;只要你能识别包(例如'x'),然后很容易修复。要在 UI 中修复此问题,请打开高级选项卡并找到 --hidden-import 输入。只需将模块名称粘贴到此输入中,然后重新打包即可。如果仍然出现原始错误,您这样做不正确。例如,如果您缺少 pandas._libs.tslib,请通过 --hidden-import 在输入中添加“pandas._libs.tslib”。此外,您可以添加多个模块,例如 pandas ._libs.tslib,win32api"
因此,在您的情况下,我假设您会将 CPLEX 库放入隐藏的导入中。