我正在使用PyInstaller打包Django应用程序。当我尝试运行最终的exe时,我得到以下输出。
Traceback (most recent call last):
File "<string>", line 9, in <module>
File "c:\users\alex\.virtualenvs\pychampion\lib\site-packages\PyInstaller- 2.1.1dev_-py2.7.egg\PyInstaller\loader\pyi_importers.py", line 270, in load_module exec(bytecode, module.__dict__)
File "Z:\01. Python Development\pychamp\build\project\out00-PYZ.pyz\pychamp", line 4, in <module>
File "c:\users\alex\.virtualenvs\pychampion\lib\site-packages\PyInstaller-2.1.1dev_-py2.7.egg\PyInstaller\loader\pyi_importers.py", line 270, in load_module exec(bytecode, module.__dict__)
File "Z:\01. Python Development\pychamp\build\project\out00-PYZ.pyz\pychamp.settings", line 13, in <module>
File "c:\users\alex\.virtualenvs\pychampion\lib\site-packages\PyInstaller-2.1.1dev_-py2.7.egg\PyInstaller\loader\pyi_importers.py", line 270, in load_module exec(bytecode, module.__dict__)
File "Z:\01. Python Development\pychamp\build\project\out00-PYZ.pyz\djcelery", line 22, in <module>
ImportError: cannot import name current_app
奇怪的是,我在运行pyInstaller后才得到这个importerror。应用程序在冻结前运行良好。 This issue似乎与我所面临的非常类似,因为我也是从virtualenv运行,但重命名项目目录没有做任何事情。我目前的结构是
pychamp
\--pychamp
\--settings.py
\--pyapp
\--manage.py
我的猜测是PyInstaller没有捕获导入的另一个问题,但我无法弄清楚我缺少什么导入。引用Pyinstaller Recipe,我一直把一些导入到manage.py而没有任何运气。我已经阅读了尽可能多的不同谷歌搜索,但我已经没有想法了。任何帮助是极大的赞赏。
from django.conf import settings
from pychamp import settings
import djcelery
from django.template.loaders.filesystem import Loader
from django.template.loaders.app_directories import Loader
import django.template.defaulttags
import django.template.defaultfilters
import django.template.loader_tags
import django.test
import HTMLParser
import django.contrib.sessions.serializers
更新
我从未弄清楚Celery的情况。我最后重新编写代码以不使用Celery,这是我的manage.py所以pyinstaller将导入所有需要的库。
#!/usr/bin/env python
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "pychamp.settings")
from django.conf import settings
import Cookie
import django.test
import HTMLParser
import django.contrib.sessions.serializers
import django.contrib
import django.core.mail.backends.smtp
import django.core.management.commands.sql
import django.core.management.commands.sqlall
import django.core.management.commands.sqlclear
import django.core.management.commands.sqlinitialdata
import django.core.management.commands.sqlsequencereset
import django.template.loader
import django.views.defaults
import django.templatetags
import googlecharts
from googlecharts import templatetags
from googlecharts.templatetags import googlecharts
import django.core.serializers
from django.core.serializers import json
from django.templatetags import future
from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)