我的Django应用位于顶级公司名称导入结构下
src
mycomp
myapp
...
my apps
...
settings.py
manage.py
unreleated_package_1
unreleated_package_2
当我尝试使用以下命令编译为pyinstaller应用程序时:
./venv/bin/pyinstaller --name=foo src/mycomp/myapp/manage.py
我收到以下错误:
File "/opt/master/venv/lib/python3.6/site-packages/PyInstaller/utils/hooks/subproc/django_import_finder.py", line 27, in <module>
django.setup()
File "/opt/master/venv/lib/python3.6/site-packages/django/__init__.py", line 22, in setup
configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
File "/opt/master/venv/lib/python3.6/site-packages/django/conf/__init__.py", line 56, in __getattr__
self._setup(name)
File "/opt/master/venv/lib/python3.6/site-packages/django/conf/__init__.py", line 41, in _setup
self._wrapped = Settings(settings_module)
File "/opt/master/venv/lib/python3.6/site-packages/django/conf/__init__.py", line 110, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 941, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'myapp'
和
File "/opt/master/venv/lib/python3.6/site-packages/PyInstaller/compat.py", line 736, in importlib_load_source
return mod_loader.load_module()
File "<frozen importlib._bootstrap_external>", line 399, in _check_name_wrapper
File "<frozen importlib._bootstrap_external>", line 823, in load_module
File "<frozen importlib._bootstrap_external>", line 682, in load_module
File "<frozen importlib._bootstrap>", line 265, in _load_module_shim
File "<frozen importlib._bootstrap>", line 684, in _load
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/opt/master/venv/lib/python3.6/site-packages/PyInstaller/hooks/hook-django.py", line 76, in <module>
installed_apps = eval(get_module_attribute(package_name + '.settings', 'INSTALLED_APPS'))
File "<string>", line 0
^
SyntaxError: unexpected EOF while parsing
Pyinstaller 3.4在改善Django支持方面取得了长足的进步,但是https://github.com/pyinstaller/pyinstaller/wiki/Recipe-Executable-From-Django上的Wiki自此未更新。