[英]How can I add a Python site-package folder (that's not being included) to a PyInstaller spec file?
[英]How to import the package being frozen in the PyInstaller spec file?
我有這個目錄結構:
mypackage/
|___ installer.spec
|___ package/
|___ __init__.py
和package.__init__.py
包含一些我想在我的installer.spec
文件中使用的變量。 所以這個文件包含一個import package
行。 但是,在 mypackage/ 中運行pyinstaller installer.spec
失敗並出現ModuleNotFoundError
。
如何從 package 中檢索變量我想在使用 PyInstaller 凍結時凍結它?
在規范文件中,更改
import package
foobar = package.foobar
至
import importlib.util
spec = importlib.util.spec_from_file_location(
"package", "/full/path/to/package/__init__.py"
)
package = importlib.util.module_from_spec(spec)
spec.loader.exec_module(package)
foobar = package.foobar
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.