尝试从Django项目使用pyinstaller在ubuntu上为Windows构建可执行文件。 我已经安装了所有必需的依赖项,并环顾了我可能需要制作的钩子文件,但是我得到的堆栈跟踪并不是我可以在搜索中找到的常见跟踪。例如,跟踪的底部存在语法错误。
规格:
# -*- mode: python -*-
block_cipher = None
a = Analysis(['manage.py'],
pathex=['/home/timi95/Desktop/AlphaServer'],
binaries=[],
datas=[],
hiddenimports=[],
hookspath=[],
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher,
noarchive=False)
pyz = PYZ(a.pure, a.zipped_data,
cipher=block_cipher)
exe = EXE(pyz,
a.scripts,
[],
exclude_binaries=True,
name='manage',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
console=True )
coll = COLLECT(exe,
a.binaries,
a.zipfiles,
a.datas,
strip=False,
upx=True,
name='manage')
踪迹:
pyinstaller --onefile --name=alpha-server manage.py
45 INFO: PyInstaller: 3.4
45 INFO: Python: 3.6.8
46 INFO: Platform: Linux-4.15.0-45-generic-x86_64-with-Ubuntu-16.04-xenial
46 INFO: wrote /home/timi95/Desktop/AlphaServer/alpha-server.spec
49 INFO: UPX is not available.
50 INFO: Extending PYTHONPATH with paths
['/home/timi95/Desktop/AlphaServer', '/home/timi95/Desktop/AlphaServer']
50 INFO: checking Analysis
50 INFO: Building Analysis because Analysis-00.toc is non existent
50 INFO: Initializing module dependency graph...
51 INFO: Initializing module graph hooks...
53 INFO: Analyzing base_library.zip ...
3385 INFO: running Analysis Analysis-00.toc
3421 INFO: Caching module hooks...
3426 INFO: Analyzing /home/timi95/Desktop/AlphaServer/manage.py
3475 INFO: Processing pre-find module path hook distutils
7791 INFO: Processing pre-safe import module hook setuptools.extern.six.moves
8281 INFO: Processing pre-find module path hook site
8281 INFO: site: retargeting to fake-dir '/home/timi95/.local/lib/python3.6/site-packages/PyInstaller/fake-modules'
12103 INFO: Loading module hooks...
12103 INFO: Loading module hook "hook-django.core.management.py"...
12119 INFO: Import to be excluded not found: 'IPython'
12119 INFO: Import to be excluded not found: 'matplotlib'
12119 INFO: Import to be excluded not found: 'tkinter'
12119 INFO: Loading module hook "hook-PIL.Image.py"...
12630 INFO: Loading module hook "hook-PIL.py"...
12632 INFO: Excluding import 'tkinter'
12636 INFO: Removing import of tkinter from module PIL.ImageTk
12638 INFO: Excluding import 'PyQt5'
12641 INFO: Removing import of PyQt5 from module PIL.ImageQt
12643 INFO: Excluding import 'PyQt4'
12647 INFO: Removing import of PyQt4 from module PIL.ImageQt
12649 INFO: Excluding import 'PySide'
12653 INFO: Removing import of PySide from module PIL.ImageQt
12655 INFO: Import to be excluded not found: 'FixTk'
12655 INFO: Loading module hook "hook-django.core.cache.py"...
12760 INFO: Loading module hook "hook-numpy.py"...
12761 INFO: Loading module hook "hook-pytz.py"...
12781 INFO: Loading module hook "hook-pkg_resources.py"...
13290 INFO: Processing pre-safe import module hook win32com
13292 INFO: Loading module hook "hook-distutils.py"...
13293 INFO: Loading module hook "hook-lib2to3.py"...
13294 INFO: Loading module hook "hook-django.py"...
Traceback (most recent call last):
File "<string>", line 41, in <module>
File "<string>", line 36, in walk_packages
File "<string>", line 36, in walk_packages
File "<string>", line 20, in walk_packages
File "/usr/local/lib/python3.6/dist-packages/django/contrib/gis/admin/__init__.py", line 5, in <module>
from django.contrib.gis.admin.options import GeoModelAdmin, OSMGeoAdmin
File "/usr/local/lib/python3.6/dist-packages/django/contrib/gis/admin/options.py", line 2, in <module>
from django.contrib.gis.admin.widgets import OpenLayersWidget
File "/usr/local/lib/python3.6/dist-packages/django/contrib/gis/admin/widgets.py", line 10, in <module>
geo_context = {'LANGUAGE_BIDI': translation.get_language_bidi()}
File "/usr/local/lib/python3.6/dist-packages/django/utils/translation/__init__.py", line 189, in get_language_bidi
return _trans.get_language_bidi()
File "/usr/local/lib/python3.6/dist-packages/django/utils/translation/__init__.py", line 53, in __getattr__
if settings.USE_I18N:
File "/usr/local/lib/python3.6/dist-packages/django/conf/__init__.py", line 57, in __getattr__
self._setup(name)
File "/usr/local/lib/python3.6/dist-packages/django/conf/__init__.py", line 42, in _setup
% (desc, ENVIRONMENT_VARIABLE))
django.core.exceptions.ImproperlyConfigured: Requested setting USE_I18N, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
14153 INFO: Determining a mapping of distributions to packages...
23360 INFO: Packages required by django:
['pytz']
23360 INFO: Django root directory /home/timi95/Desktop/AlphaServer/AlphaServer
Traceback (most recent call last):
File "/home/timi95/.local/lib/python3.6/site-packages/PyInstaller/utils/hooks/subproc/django_import_finder.py", line 27, in <module>
django.setup()
File "/usr/local/lib/python3.6/dist-packages/django/__init__.py", line 19, in setup
configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
File "/usr/local/lib/python3.6/dist-packages/django/conf/__init__.py", line 57, in __getattr__
self._setup(name)
File "/usr/local/lib/python3.6/dist-packages/django/conf/__init__.py", line 44, in _setup
self._wrapped = Settings(settings_module)
File "/usr/local/lib/python3.6/dist-packages/django/conf/__init__.py", line 107, 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 955, in _find_and_load_unlocked
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 "/home/timi95/Desktop/AlphaServer/AlphaServer/__init__.py", line 1, in <module>
import corsheaders
ModuleNotFoundError: No module named 'corsheaders'
23701 INFO: Collecting Django migration scripts.
Traceback (most recent call last):
File "<string>", line 2, in <module>
File "/home/timi95/Desktop/AlphaServer/AlphaServer/__init__.py", line 1, in <module>
import corsheaders
ModuleNotFoundError: No module named 'corsheaders'
Traceback (most recent call last):
File "/home/timi95/.local/bin/pyinstaller", line 11, in <module>
sys.exit(run())
File "/home/timi95/.local/lib/python3.6/site-packages/PyInstaller/__main__.py", line 111, in run
run_build(pyi_config, spec_file, **vars(args))
File "/home/timi95/.local/lib/python3.6/site-packages/PyInstaller/__main__.py", line 63, in run_build
PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
File "/home/timi95/.local/lib/python3.6/site-packages/PyInstaller/building/build_main.py", line 838, in main
build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))
File "/home/timi95/.local/lib/python3.6/site-packages/PyInstaller/building/build_main.py", line 784, in build
exec(text, spec_namespace)
File "<string>", line 17, in <module>
File "/home/timi95/.local/lib/python3.6/site-packages/PyInstaller/building/build_main.py", line 241, in __init__
self.__postinit__()
File "/home/timi95/.local/lib/python3.6/site-packages/PyInstaller/building/datastruct.py", line 158, in __postinit__
self.assemble()
File "/home/timi95/.local/lib/python3.6/site-packages/PyInstaller/building/build_main.py", line 500, in assemble
module_hook.post_graph()
File "/home/timi95/.local/lib/python3.6/site-packages/PyInstaller/building/imphook.py", line 410, in post_graph
self._load_hook_module()
File "/home/timi95/.local/lib/python3.6/site-packages/PyInstaller/building/imphook.py", line 377, in _load_hook_module
self.hook_module_name, self.hook_filename)
File "/home/timi95/.local/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 "/home/timi95/.local/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
这是我的冻结点:
dataclasses==0.6
Django==2.1.7
django-cors-headers==2.4.1
djangorestframework==3.9.1
djangorestframework-jwt==1.11.0
djongo==1.2.31
numpy==1.16.2
py2exe==0.9.2.2
PyJWT==1.7.1
pymongo==3.7.2
pytz==2018.9
和settings.py
import os
import datetime
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.0/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '77fy+^i(n=2)tq$0)&31d@uf3t+ge##$aclyla&lmr@lpinc1&'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'accounts',
'rest_framework',
'rest_framework.authtoken',
'corsheaders'
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'corsheaders.middleware.CorsMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'AlphaServer.urls'
# REST_FRAMEWORK = {
# 'DEFAULT_AUTHENTICATION_CLASSES': (
# 'rest_framework.authentication.BasicAuthentication',
# 'rest_framework.authentication.SessionAuthentication',
# )
# }
JWT_AUTH = {
'JWT_ALLOW_REFRESH': True,
'JWT_EXPIRATION_DELTA': datetime.timedelta(seconds=3600),
}
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'AlphaServer.wsgi.application'
# Database
# https://docs.djangoproject.com/en/2.0/ref/settings/#databases
DATABASES = {
'default' : {
'ENGINE' : 'djongo',
'NAME' : 'account_database',
}
}
# Password validation
# https://docs.djangoproject.com/en/2.0/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Internationalization
# https://docs.djangoproject.com/en/2.0/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.0/howto/static-files/
STATIC_URL = '/static/'
CORS_ORIGIN_WHITELIST = (
'localhost:4200',
)
与Django上pyinstaller的django配方安装程序所提供的内容相比,任何想法或更具体的指导将不胜感激。
我还在wsgi.py中配置环境变量,甚至尝试将这些调用移至manage.py的开头
我仍然没有找到引发语法错误的答案。