目的
1、代码可以随处执行
2、方便迁移以及别人直接使用
形式1:单个py文件打包
使用python环境中的pyInstaller 进行py文件打包
下载pyinstaller,确认下载成功:
pip show Pyinstaller
在系统python环境site-packages中找到PyInstaller文件夹,然后将【待打包文件a.py】拷贝到PyInstaller文件夹下。
执行打包命令,生产打包之后的exe文件在PyInstaller文件夹下的dist文件下,点击exe文件可直接运行。
打包相关的命令以及参数:
在pyinstaller 对应目录下的cmd命令行输入pyinstaller -i my.ico -F -c a.py
其中:
-i: 表示要加载的图标(没有选择图标可以不用写)
my.ico:表示自己选择的图标名(没有选择图标可以不用写)
-F:表示打包成.exe可执行文件
-c:表示打包程序有窗口
a.py:表示你要打包的py文件
其他问题:
1> 指定窗口时不自动退出【或者闪退问题】:
在代码末尾添加cmd pause命令
os.system("pause")
保存后重新打包,运行:
形式2:django项目文件打包
使用conda环境中的pyInstaller 进行项目打包
查找安装包
anaconda search -t conda pyinstaller
anaconda show main/pyinstaller-hooks-contrib
anaconda show conda-forge/pyinstaller-hooks-contrib #后续install安装会失败可以show其他的安装源,进行安装
安装命令
conda install --channel https://conda.anaconda.org/conda-forge pyinstaller-hooks-contrib
执行打包命令
pyinstaller -D .\manage.py
打包过程中如果提示以下错误,但不影响打包进度,可以忽略。
django.core.exceptions.ImproperlyConfigured: Could not find the GDAL library (tried "gdal302", "gdal301", "gdal300", "gdal204", "gdal203", "gdal202", "gdal201", "gdal20"). Is GDAL installed? If it is, try setting GDAL_LIBRARY_PATH in your settings.
collect_submodules: failed to import 'django.contrib.gis.geos'!
PS D:\PycharmProject\my_code\项目文件\my_code\django_app> pyinstaller -D .\manage.py
894 INFO: PyInstaller: 4.5.1
894 INFO: Python: 3.6.5 (conda)
894 INFO: Platform: Windows-10-10.0.19041-SP0
895 INFO: wrote D:\PycharmProject\my_code\项目文件\my_code\django_app\manage.spec
897 INFO: UPX is not available.
899 INFO: Extending PYTHONPATH with paths
['D:\\PycharmProject\\my_code\\项目文件\\my_code\\django_app',
'D:\\PycharmProject\\my_code\\项目文件\\my_code\\django_app']
1220 INFO: checking Analysis
1220 INFO: Building Analysis because Analysis-00.toc is non existent
1220 INFO: Initializing module dependency graph...
1223 INFO: Caching module graph hooks...
1233 INFO: Analyzing base_library.zip ...
3937 INFO: Caching module dependency graph...
4075 INFO: running Analysis Analysis-00.toc
4089 INFO: Adding Microsoft.Windows.Common-Controls to dependent assemblies of final executable
required by D:\ProgramData\Anaconda3\python.exe
4272 INFO: Analyzing D:\PycharmProject\my_code\项目文件\my_code\django_app\manage.py
6414 INFO: Processing pre-find module path hook distutils from 'D:\\ProgramData\\Anaconda3\\lib\\site-packages\\PyInstaller\\hooks\\pre_find_module_path\\hook-distutils.py'.
6415 INFO: distutils: retargeting to non-venv dir 'D:\\ProgramData\\Anaconda3\\lib'
10880 INFO: Processing pre-safe import module hook setuptools.extern.six.moves from 'D:\\ProgramData\\Anaconda3\\lib\\site-packages\\PyInstaller\\hooks\\pre_safe_import_module\\hook-setuptools.extern.six.moves.py'.
11324 INFO: Processing pre-find module path hook site from 'D:\\ProgramData\\Anaconda3\\lib\\site-packages\\PyInstaller\\hooks\\pre_find_module_path\\hook-site.py'.
11324 INFO: site: retargeting to fake-dir 'D:\\ProgramData\\Anaconda3\\lib\\site-packages\\PyInstaller\\fake-modules'
12549 INFO: Processing module hooks...
12549 INFO: Loading module hook 'hook-jinja2.py' from 'D:\\ProgramData\\Anaconda3\\lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\stdhooks'...
12560 INFO: Loading module hook 'hook-pycparser.py' from 'D:\\ProgramData\\Anaconda3\\lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\stdhooks'...
12709 INFO: Loading module hook 'hook-difflib.py' from 'D:\\ProgramData\\Anaconda3\\lib\\site-packages\\PyInstaller\\hooks'...
12711 INFO: Loading module hook 'hook-distutils.py' from 'D:\\ProgramData\\Anaconda3\\lib\\site-packages\\PyInstaller\\hooks'...
12711 INFO: Loading module hook 'hook-distutils.util.py' from 'D:\\ProgramData\\Anaconda3\\lib\\site-packages\\PyInstaller\\hooks'...
12713 INFO: Loading module hook 'hook-django.core.cache.py' from 'D:\\ProgramData\\Anaconda3\\lib\\site-packages\\PyInstaller\\hooks'...
12842 INFO: Loading module hook 'hook-django.core.mail.py' from 'D:\\ProgramData\\Anaconda3\\lib\\site-packages\\PyInstaller\\hooks'...
12879 INFO: Loading module hook 'hook-django.core.management.py' from 'D:\\ProgramData\\Anaconda3\\lib\\site-packages\\PyInstaller\\hooks'...
16498 INFO: Processing pre-safe import module hook six.moves from 'D:\\ProgramData\\Anaconda3\\lib\\site-packages\\PyInstaller\\hooks\\pre_safe_import_module\\hook-six.moves.py'.
21309 INFO: Processing pre-safe import module hook urllib3.packages.six.moves from 'D:\\ProgramData\\Anaconda3\\lib\\site-packages\\PyInstaller\\hooks\\pre_safe_import_module\\hook-urllib3.packages.six.moves.py'.
33650 INFO: Processing pre-safe import module hook win32com from 'D:\\ProgramData\\Anaconda3\\lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\pre_safe_import_module\\hook-win32com.py'.
39365 INFO: Processing pre-safe import module hook gi from 'D:\\ProgramData\\Anaconda3\\lib\\site-packages\\PyInstaller\\hooks\\pre_safe_import_module\\hook-gi.py'.
42312 INFO: Loading module hook 'hook-django.db.backends.py' from 'D:\\ProgramData\\Anaconda3\\lib\\site-packages\\PyInstaller\\hooks'...
43293 WARNING: Hidden import "django.db.backends.__pycache__.base" not found!
43293 INFO: Loading module hook 'hook-django.py' from 'D:\\ProgramData\\Anaconda3\\lib\\site-packages\\PyInstaller\\hooks'...
Traceback (most recent call last):
File "<string>", line 21, in walk_packages
File "D:\ProgramData\Anaconda3\lib\site-packages\django\contrib\gis\admin\__init__.py", line 5, in <module>
from django.contrib.gis.admin.options import GeoModelAdmin, OSMGeoAdmin
File "D:\ProgramData\Anaconda3\lib\site-packages\django\contrib\gis\admin\options.py", line 2, in <module>
from django.contrib.gis.admin.widgets import OpenLayersWidget
File "D:\ProgramData\Anaconda3\lib\site-packages\django\contrib\gis\admin\widgets.py", line 3, in <module>
from django.contrib.gis.gdal import GDALException
File "D:\ProgramData\Anaconda3\lib\site-packages\django\contrib\gis\gdal\__init__.py", line 28, in <module>
from django.contrib.gis.gdal.datasource import DataSource
File "D:\ProgramData\Anaconda3\lib\site-packages\django\contrib\gis\gdal\datasource.py", line 40, in <module>
from django.contrib.gis.gdal.driver import Driver
File "D:\ProgramData\Anaconda3\lib\site-packages\django\contrib\gis\gdal\driver.py", line 5, in <module>
from django.contrib.gis.gdal.prototypes import ds as vcapi, raster as rcapi
File "D:\ProgramData\Anaconda3\lib\site-packages\django\contrib\gis\gdal\prototypes\ds.py", line 9, in <module>
from django.contrib.gis.gdal.libgdal import GDAL_VERSION, lgdal
File "D:\ProgramData\Anaconda3\lib\site-packages\django\contrib\gis\gdal\libgdal.py", line 49, in <module>
% '", "'.join(lib_names)
django.core.exceptions.ImproperlyConfigured: Could not find the GDAL library (tried "gdal302", "gdal301", "gdal300", "gdal204", "gdal203", "gdal202", "gdal201", "gdal20"). Is GDAL installed? If it is, try setting GDAL_LIBRARY_PATH in your settings.
collect_submodules: failed to import 'django.contrib.gis.admin'!
Traceback (most recent call last):
File "<string>", line 21, in walk_packages
File "D:\ProgramData\Anaconda3\lib\site-packages\django\contrib\gis\db\models\__init__.py", line 3, in <module>
import django.contrib.gis.db.models.functions # NOQA
File "D:\ProgramData\Anaconda3\lib\site-packages\django\contrib\gis\db\models\functions.py", line 3, in <module>
from django.contrib.gis.db.models.fields import BaseSpatialField, GeometryField
File "D:\ProgramData\Anaconda3\lib\site-packages\django\contrib\gis\db\models\fields.py", line 3, in <module>
from django.contrib.gis import forms, gdal
File "D:\ProgramData\Anaconda3\lib\site-packages\django\contrib\gis\forms\__init__.py", line 3, in <module>
from .fields import ( # NOQA
File "D:\ProgramData\Anaconda3\lib\site-packages\django\contrib\gis\forms\fields.py", line 2, in <module>
from django.contrib.gis.gdal import GDALException
File "D:\ProgramData\Anaconda3\lib\site-packages\django\contrib\gis\gdal\__init__.py", line 28, in <module>
from django.contrib.gis.gdal.datasource import DataSource
File "D:\ProgramData\Anaconda3\lib\site-packages\django\contrib\gis\gdal\datasource.py", line 40, in <module>
from django.contrib.gis.gdal.driver import Driver
File "D:\ProgramData\Anaconda3\lib\site-packages\django\contrib\gis\gdal\driver.py", line 5, in <module>
from django.contrib.gis.gdal.prototypes import ds as vcapi, raster as rcapi
File "D:\ProgramData\Anaconda3\lib\site-packages\django\contrib\gis\gdal\prototypes\ds.py", line 9, in <module>
from django.contrib.gis.gdal.libgdal import GDAL_VERSION, lgdal
File "D:\ProgramData\Anaconda3\lib\site-packages\django\contrib\gis\gdal\libgdal.py", line 49, in <module>
% '", "'.join(lib_names)
django.core.exceptions.ImproperlyConfigured: Could not find the GDAL library (tried "gdal302", "gdal301", "gdal300", "gdal204", "gdal203", "gdal202", "gdal201", "gdal20"). Is GDAL installed? If it is, try setting GDAL_LIBRARY_PATH in your settings.
collect_submodules: failed to import 'django.contrib.gis.db.models'!
Traceback (most recent call last):
File "<string>", line 21, in walk_packages
File "D:\ProgramData\Anaconda3\lib\site-packages\django\contrib\gis\forms\__init__.py", line 3, in <module>
from .fields import ( # NOQA
File "D:\ProgramData\Anaconda3\lib\site-packages\django\contrib\gis\forms\fields.py", line 2, in <module>
from django.contrib.gis.gdal import GDALException
File "D:\ProgramData\Anaconda3\lib\site-packages\django\contrib\gis\gdal\__init__.py", line 28, in <module>
from django.contrib.gis.gdal.datasource import DataSource
File "D:\ProgramData\Anaconda3\lib\site-packages\django\contrib\gis\gdal\datasource.py", line 40, in <module>
from django.contrib.gis.gdal.driver import Driver
File "D:\ProgramData\Anaconda3\lib\site-packages\django\contrib\gis\gdal\driver.py", line 5, in <module>
from django.contrib.gis.gdal.prototypes import ds as vcapi, raster as rcapi
File "D:\ProgramData\Anaconda3\lib\site-packages\django\contrib\gis\gdal\prototypes\ds.py", line 9, in <module>
from django.contrib.gis.gdal.libgdal import GDAL_VERSION, lgdal
File "D:\ProgramData\Anaconda3\lib\site-packages\django\contrib\gis\gdal\libgdal.py", line 49, in <module>
% '", "'.join(lib_names)
django.core.exceptions.ImproperlyConfigured: Could not find the GDAL library (tried "gdal302", "gdal301", "gdal300", "gdal204", "gdal203", "gdal202", "gdal201", "gdal20"). Is GDAL installed? If it is, try setting GDAL_LIBRARY_PATH in your settings.
collect_submodules: failed to import 'django.contrib.gis.forms'!
Traceback (most recent call last):
File "<string>", line 21, in walk_packages
File "D:\ProgramData\Anaconda3\lib\site-packages\django\contrib\gis\gdal\__init__.py", line 28, in <module>
from django.contrib.gis.gdal.datasource import DataSource
File "D:\ProgramData\Anaconda3\lib\site-packages\django\contrib\gis\gdal\datasource.py", line 40, in <module>
from django.contrib.gis.gdal.driver import Driver
File "D:\ProgramData\Anaconda3\lib\site-packages\django\contrib\gis\gdal\driver.py", line 5, in <module>
from django.contrib.gis.gdal.prototypes import ds as vcapi, raster as rcapi
File "D:\ProgramData\Anaconda3\lib\site-packages\django\contrib\gis\gdal\prototypes\ds.py", line 9, in <module>
from django.contrib.gis.gdal.libgdal import GDAL_VERSION, lgdal
File "D:\ProgramData\Anaconda3\lib\site-packages\django\contrib\gis\gdal\libgdal.py", line 49, in <module>
% '", "'.join(lib_names)
django.core.exceptions.ImproperlyConfigured: Could not find the GDAL library (tried "gdal302", "gdal301", "gdal300", "gdal204", "gdal203", "gdal202", "gdal201", "gdal20"). Is GDAL installed? If it is, try setting GDAL_LIBRARY_PATH in your settings.
collect_submodules: failed to import 'django.contrib.gis.gdal'!
Traceback (most recent call last):
File "<string>", line 21, in walk_packages
File "D:\ProgramData\Anaconda3\lib\site-packages\django\contrib\gis\geos\__init__.py", line 5, in <module>
from .collections import ( # NOQA
File "D:\ProgramData\Anaconda3\lib\site-packages\django\contrib\gis\geos\collections.py", line 8, in <module>
from django.contrib.gis.geos.geometry import GEOSGeometry, LinearGeometryMixin
File "D:\ProgramData\Anaconda3\lib\site-packages\django\contrib\gis\geos\geometry.py", line 8, in <module>
from django.contrib.gis import gdal
File "D:\ProgramData\Anaconda3\lib\site-packages\django\contrib\gis\gdal\__init__.py", line 28, in <module>
from django.contrib.gis.gdal.datasource import DataSource
File "D:\ProgramData\Anaconda3\lib\site-packages\django\contrib\gis\gdal\datasource.py", line 40, in <module>
from django.contrib.gis.gdal.driver import Driver
File "D:\ProgramData\Anaconda3\lib\site-packages\django\contrib\gis\gdal\driver.py", line 5, in <module>
from django.contrib.gis.gdal.prototypes import ds as vcapi, raster as rcapi
File "D:\ProgramData\Anaconda3\lib\site-packages\django\contrib\gis\gdal\prototypes\ds.py", line 9, in <module>
from django.contrib.gis.gdal.libgdal import GDAL_VERSION, lgdal
File "D:\ProgramData\Anaconda3\lib\site-packages\django\contrib\gis\gdal\libgdal.py", line 49, in <module>
% '", "'.join(lib_names)
django.core.exceptions.ImproperlyConfigured: Could not find the GDAL library (tried "gdal302", "gdal301", "gdal300", "gdal204", "gdal203", "gdal202", "gdal201", "gdal20"). Is GDAL installed? If it is, try setting GDAL_LIBRARY_PATH in your settings.
collect_submodules: failed to import 'django.contrib.gis.geos'!
Traceback (most recent call last):
File "<string>", line 21, in walk_packages
File "D:\ProgramData\Anaconda3\lib\site-packages\django\contrib\gis\sitemaps\__init__.py", line 2, in <module>
from django.contrib.gis.sitemaps.kml import KMLSitemap, KMZSitemap
File "D:\ProgramData\Anaconda3\lib\site-packages\django\contrib\gis\sitemaps\kml.py", line 2, in <module>
from django.contrib.gis.db.models import GeometryField
File "D:\ProgramData\Anaconda3\lib\site-packages\django\contrib\gis\db\models\__init__.py", line 3, in <module>
import django.contrib.gis.db.models.functions # NOQA
File "D:\ProgramData\Anaconda3\lib\site-packages\django\contrib\gis\db\models\functions.py", line 3, in <module>
from django.contrib.gis.db.models.fields import BaseSpatialField, GeometryField
File "D:\ProgramData\Anaconda3\lib\site-packages\django\contrib\gis\db\models\fields.py", line 3, in <module>
from django.contrib.gis import forms, gdal
File "D:\ProgramData\Anaconda3\lib\site-packages\django\contrib\gis\forms\__init__.py", line 3, in <module>
from .fields import ( # NOQA
File "D:\ProgramData\Anaconda3\lib\site-packages\django\contrib\gis\forms\fields.py", line 2, in <module>
from django.contrib.gis.gdal import GDALException
File "D:\ProgramData\Anaconda3\lib\site-packages\django\contrib\gis\gdal\__init__.py", line 28, in <module>
from django.contrib.gis.gdal.datasource import DataSource
File "D:\ProgramData\Anaconda3\lib\site-packages\django\contrib\gis\gdal\datasource.py", line 40, in <module>
from django.contrib.gis.gdal.driver import Driver
File "D:\ProgramData\Anaconda3\lib\site-packages\django\contrib\gis\gdal\driver.py", line 5, in <module>
from django.contrib.gis.gdal.prototypes import ds as vcapi, raster as rcapi
File "D:\ProgramData\Anaconda3\lib\site-packages\django\contrib\gis\gdal\prototypes\ds.py", line 9, in <module>
from django.contrib.gis.gdal.libgdal import GDAL_VERSION, lgdal
File "D:\ProgramData\Anaconda3\lib\site-packages\django\contrib\gis\gdal\libgdal.py", line 49, in <module>
% '", "'.join(lib_names)
django.core.exceptions.ImproperlyConfigured: Could not find the GDAL library (tried "gdal302", "gdal301", "gdal300", "gdal204", "gdal203", "gdal202", "gdal201", "gdal20"). Is GDAL installed? If it is, try setting GDAL_LIBRARY_PATH in your settings.
collect_submodules: failed to import 'django.contrib.gis.sitemaps'!
Traceback (most recent call last):
File "<string>", line 21, in walk_packages
File "D:\ProgramData\Anaconda3\lib\site-packages\django\contrib\gis\utils\__init__.py", line 4, in <module>
from django.contrib.gis.utils.ogrinfo import ogrinfo # NOQA
File "D:\ProgramData\Anaconda3\lib\site-packages\django\contrib\gis\utils\ogrinfo.py", line 7, in <module>
from django.contrib.gis.gdal import DataSource
File "D:\ProgramData\Anaconda3\lib\site-packages\django\contrib\gis\gdal\__init__.py", line 28, in <module>
from django.contrib.gis.gdal.datasource import DataSource
File "D:\ProgramData\Anaconda3\lib\site-packages\django\contrib\gis\gdal\datasource.py", line 40, in <module>
from django.contrib.gis.gdal.driver import Driver
File "D:\ProgramData\Anaconda3\lib\site-packages\django\contrib\gis\gdal\driver.py", line 5, in <module>
from django.contrib.gis.gdal.prototypes import ds as vcapi, raster as rcapi
File "D:\ProgramData\Anaconda3\lib\site-packages\django\contrib\gis\gdal\prototypes\ds.py", line 9, in <module>
from django.contrib.gis.gdal.libgdal import GDAL_VERSION, lgdal
File "D:\ProgramData\Anaconda3\lib\site-packages\django\contrib\gis\gdal\libgdal.py", line 49, in <module>
% '", "'.join(lib_names)
django.core.exceptions.ImproperlyConfigured: Could not find the GDAL library (tried "gdal302", "gdal301", "gdal300", "gdal204", "gdal203", "gdal202", "gdal201", "gdal20"). Is GDAL installed? If it is, try setting GDAL_LIBRARY_PATH in your settings.
collect_submodules: failed to import 'django.contrib.gis.utils'!
46844 INFO: Determining a mapping of distributions to packages...
119545 INFO: Packages required by django:
['asgiref', 'pytz', 'sqlparse']
119546 INFO: Django root directory D:\PycharmProject\my_code\项目文件\my_code\django_app\clue_graph
122480 INFO: Collecting Django migration scripts.
132540 WARNING: Hidden import "django.contrib.staticfiles.templatetags" not found!
132541 WARNING: Hidden import "django.contrib.sessions.context_processors" not found!
132666 WARNING: Hidden import "app.templatetags" not found!
132734 WARNING: Hidden import "corsheaders.templatetags" not found!
132744 WARNING: Hidden import "django.contrib.messages.templatetags" not found!
132744 WARNING: Hidden import "app.context_processors" not found!
132744 WARNING: Hidden import "django.contrib.contenttypes.context_processors" not found!
132749 WARNING: Hidden import "django.contrib.admin.context_processors" not found!
162007 WARNING: Hidden import "corsheaders.context_processors" not found!
162010 WARNING: Hidden import "django.contrib.sessions.templatetags" not found!
162013 WARNING: Hidden import "django.contrib.auth.templatetags" not found!
162019 WARNING: Hidden import "django.contrib.staticfiles.context_processors" not found!
162028 WARNING: Hidden import "django.contrib.contenttypes.templatetags" not found!
162031 INFO: Loading module hook 'hook-django.template.loaders.py' from 'D:\\ProgramData\\Anaconda3\\lib\\site-packages\\PyInstaller\\hooks'...
162086 INFO: Loading module hook 'hook-encodings.py' from 'D:\\ProgramData\\Anaconda3\\lib\\site-packages\\PyInstaller\\hooks'...
162150 INFO: Loading module hook 'hook-heapq.py' from 'D:\\ProgramData\\Anaconda3\\lib\\site-packages\\PyInstaller\\hooks'...
162158 INFO: Loading module hook 'hook-lib2to3.py' from 'D:\\ProgramData\\Anaconda3\\lib\\site-packages\\PyInstaller\\hooks'...
162183 INFO: Loading module hook 'hook-matplotlib.backends.py' from 'D:\\ProgramData\\Anaconda3\\lib\\site-packages\\PyInstaller\\hooks'...
162588 INFO: Matplotlib backend "GTK": ignored
Gtk* backend requires pygtk to be installed.
162913 INFO: Matplotlib backend "GTKAgg": ignored
Gtk* backend requires pygtk to be installed.
163123 INFO: Matplotlib backend "GTKCairo": ignored
No module named 'gtk'
163439 INFO: Matplotlib backend "GTK3Agg": ignored
The Gtk3 backend requires PyGObject or pgi
163649 INFO: Matplotlib backend "GTK3Cairo": ignored
cairo backend requires that cairocffi or pycairo is installed
163976 INFO: Matplotlib backend "MacOSX": ignored
cannot import name '_macosx'
164613 INFO: Matplotlib backend "nbAgg": added
164987 INFO: Matplotlib backend "Qt4Agg": added
165190 INFO: Matplotlib backend "Qt4Cairo": ignored
cairo backend requires that cairocffi or pycairo is installed
165541 INFO: Matplotlib backend "Qt5Agg": added
165749 INFO: Matplotlib backend "Qt5Cairo": ignored
cairo backend requires that cairocffi or pycairo is installed
166093 INFO: Matplotlib backend "TkAgg": added
166321 INFO: Matplotlib backend "TkCairo": ignored
cairo backend requires that cairocffi or pycairo is installed
166855 INFO: Matplotlib backend "WebAgg": added
167180 INFO: Matplotlib backend "WX": ignored
Matplotlib backend_wx and backend_wxagg require wxPython>=2.9
167395 INFO: Matplotlib backend "WXAgg": ignored
No module named 'wx'
167615 INFO: Matplotlib backend "WXCairo": ignored
No module named 'wx'
167943 INFO: Matplotlib backend "agg": added
168163 INFO: Matplotlib backend "cairo": ignored
cairo backend requires that cairocffi or pycairo is installed
168377 INFO: Matplotlib backend "gdk": ignored
No module named 'gobject'
168711 INFO: Matplotlib backend "pdf": added
169106 INFO: Matplotlib backend "pgf": added
169435 INFO: Matplotlib backend "ps": added
169751 INFO: Matplotlib backend "svg": added
170071 INFO: Matplotlib backend "template": added
170311 INFO: Loading module hook 'hook-matplotlib.py' from 'D:\\ProgramData\\Anaconda3\\lib\\site-packages\\PyInstaller\\hooks'...
170516 INFO: Loading module hook 'hook-multiprocessing.util.py' from 'D:\\ProgramData\\Anaconda3\\lib\\site-packages\\PyInstaller\\hooks'...
170521 INFO: Import to be excluded not found: 'test'
170521 INFO: Loading module hook 'hook-numpy.py' from 'D:\\ProgramData\\Anaconda3\\lib\\site-packages\\PyInstaller\\hooks'...
170555 WARNING: Hidden import "numpy.core._dtype_ctypes" not found!
170606 INFO: Import to be excluded not found: 'f2py'
170613 INFO: Loading module hook 'hook-packaging.py' from 'D:\\ProgramData\\Anaconda3\\lib\\site-packages\\PyInstaller\\hooks'...
170614 INFO: Loading module hook 'hook-pandas.io.formats.style.py' from 'D:\\ProgramData\\Anaconda3\\lib\\site-packages\\PyInstaller\\hooks'...
171010 INFO: Loading module hook 'hook-pandas.py' from 'D:\\ProgramData\\Anaconda3\\lib\\site-packages\\PyInstaller\\hooks'...
171419 INFO: Loading module hook 'hook-pickle.py' from 'D:\\ProgramData\\Anaconda3\\lib\\site-packages\\PyInstaller\\hooks'...
171427 INFO: Loading module hook 'hook-PIL.Image.py' from 'D:\\ProgramData\\Anaconda3\\lib\\site-packages\\PyInstaller\\hooks'...
171735 INFO: Loading module hook 'hook-PIL.ImageFilter.py' from 'D:\\ProgramData\\Anaconda3\\lib\\site-packages\\PyInstaller\\hooks'...
171744 INFO: Loading module hook 'hook-PIL.py' from 'D:\\ProgramData\\Anaconda3\\lib\\site-packages\\PyInstaller\\hooks'...
171750 INFO: Import to be excluded not found: 'PySide6'
171760 INFO: Import to be excluded not found: 'PyQt6'
171765 INFO: Loading module hook 'hook-PIL.SpiderImagePlugin.py' from 'D:\\ProgramData\\Anaconda3\\lib\\site-packages\\PyInstaller\\hooks'...
171774 INFO: Loading module hook 'hook-pkg_resources.py' from 'D:\\ProgramData\\Anaconda3\\lib\\site-packages\\PyInstaller\\hooks'...
172477 WARNING: Hidden import "pkg_resources.py2_warn" not found!
172490 WARNING: Hidden import "pkg_resources.markers" not found!
172499 INFO: Loading module hook 'hook-platform.py' from 'D:\\ProgramData\\Anaconda3\\lib\\site-packages\\PyInstaller\\hooks'...
172509 INFO: Loading module hook 'hook-py2neo.py' from 'D:\\ProgramData\\Anaconda3\\lib\\site-packages\\PyInstaller\\hooks'...
172537 INFO: Loading module hook 'hook-pygments.py' from 'D:\\ProgramData\\Anaconda3\\lib\\site-packages\\PyInstaller\\hooks'...
173806 INFO: Loading module hook 'hook-PyQt5.py' from 'D:\\ProgramData\\Anaconda3\\lib\\site-packages\\PyInstaller\\hooks'...
174166 WARNING: Hidden import "PyQt5.sip" not found!
174168 INFO: Loading module hook 'hook-PyQt5.QtCore.py' from 'D:\\ProgramData\\Anaconda3\\lib\\site-packages\\PyInstaller\\hooks'...
174224 INFO: Loading module hook 'hook-PyQt5.QtGui.py' from 'D:\\ProgramData\\Anaconda3\\lib\\site-packages\\PyInstaller\\hooks'...
174357 INFO: Loading module hook 'hook-PyQt5.QtSvg.py' from 'D:\\ProgramData\\Anaconda3\\lib\\site-packages\\PyInstaller\\hooks'...
174762 INFO: Loading module hook 'hook-PyQt5.QtWidgets.py' from 'D:\\ProgramData\\Anaconda3\\lib\\site-packages\\PyInstaller\\hooks'...
175132 INFO: Loading module hook 'hook-pytz.py' from 'D:\\ProgramData\\Anaconda3\\lib\\site-packages\\PyInstaller\\hooks'...
175249 INFO: Loading module hook 'hook-scipy.linalg.py' from 'D:\\ProgramData\\Anaconda3\\lib\\site-packages\\PyInstaller\\hooks'...
175250 INFO: Loading module hook 'hook-scipy.py' from 'D:\\ProgramData\\Anaconda3\\lib\\site-packages\\PyInstaller\\hooks'...
175252 INFO: Loading module hook 'hook-scipy.sparse.csgraph.py' from 'D:\\ProgramData\\Anaconda3\\lib\\site-packages\\PyInstaller\\hooks'...
175255 INFO: Loading module hook 'hook-scipy.special._ellip_harm_2.py' from 'D:\\ProgramData\\Anaconda3\\lib\\site-packages\\PyInstaller\\hooks'...
175255 INFO: Loading module hook 'hook-scipy.special._ufuncs.py' from 'D:\\ProgramData\\Anaconda3\\lib\\site-packages\\PyInstaller\\hooks'...
175256 INFO: Loading module hook 'hook-scipy.stats._stats.py' from 'D:\\ProgramData\\Anaconda3\\lib\\site-packages\\PyInstaller\\hooks'...
175257 INFO: Loading module hook 'hook-setuptools.py' from 'D:\\ProgramData\\Anaconda3\\lib\\site-packages\\PyInstaller\\hooks'...
175894 INFO: Loading module hook 'hook-sphinx.py' from 'D:\\ProgramData\\Anaconda3\\lib\\site-packages\\PyInstaller\\hooks'...
179606 INFO: Loading module hook 'hook-sqlalchemy.py' from 'D:\\ProgramData\\Anaconda3\\lib\\site-packages\\PyInstaller\\hooks'...
179749 INFO: Found 3 sqlalchemy hidden imports
179764 WARNING: Hidden import "sqlalchemy.sql.functions.func" not found!
179777 INFO: Loading module hook 'hook-sqlite3.py' from 'D:\\ProgramData\\Anaconda3\\lib\\site-packages\\PyInstaller\\hooks'...
179841 INFO: Loading module hook 'hook-sysconfig.py' from 'D:\\ProgramData\\Anaconda3\\lib\\site-packages\\PyInstaller\\hooks'...
179842 INFO: Loading module hook 'hook-wcwidth.py' from 'D:\\ProgramData\\Anaconda3\\lib\\site-packages\\PyInstaller\\hooks'...
179846 INFO: Loading module hook 'hook-xml.dom.domreg.py' from 'D:\\ProgramData\\Anaconda3\\lib\\site-packages\\PyInstaller\\hooks'...
179846 INFO: Loading module hook 'hook-xml.etree.cElementTree.py' from 'D:\\ProgramData\\Anaconda3\\lib\\site-packages\\PyInstaller\\hooks'...
179847 INFO: Loading module hook 'hook-xml.py' from 'D:\\ProgramData\\Anaconda3\\lib\\site-packages\\PyInstaller\\hooks'...
179847 INFO: Loading module hook 'hook-_tkinter.py' from 'D:\\ProgramData\\Anaconda3\\lib\\site-packages\\PyInstaller\\hooks'...
179963 INFO: checking Tree
179963 INFO: Building Tree because Tree-00.toc is non existent
179963 INFO: Building Tree Tree-00.toc
179990 INFO: checking Tree
179990 INFO: Building Tree because Tree-01.toc is non existent
179990 INFO: Building Tree Tree-01.toc
180053 INFO: checking Tree
180053 INFO: Building Tree because Tree-02.toc is non existent
180053 INFO: Building Tree Tree-02.toc
180058 INFO: Loading module hook 'hook-certifi.py' from 'D:\\ProgramData\\Anaconda3\\lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\stdhooks'...
180061 INFO: Loading module hook 'hook-cryptography.py' from 'D:\\ProgramData\\Anaconda3\\lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\stdhooks'...
180275 INFO: Loading module hook 'hook-cx_Oracle.py' from 'D:\\ProgramData\\Anaconda3\\lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\stdhooks'...
180276 INFO: Loading module hook 'hook-docutils.py' from 'D:\\ProgramData\\Anaconda3\\lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\stdhooks'...
181148 INFO: Loading module hook 'hook-IPython.py' from 'D:\\ProgramData\\Anaconda3\\lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\stdhooks'...
181489 INFO: Loading module hook 'hook-jedi.py' from 'D:\\ProgramData\\Anaconda3\\lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\stdhooks'...
181519 INFO: Loading module hook 'hook-jsonschema.py' from 'D:\\ProgramData\\Anaconda3\\lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\stdhooks'...
181529 INFO: Loading module hook 'hook-lxml.etree.py' from 'D:\\ProgramData\\Anaconda3\\lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\stdhooks'...
181529 INFO: Loading module hook 'hook-lxml.py' from 'D:\\ProgramData\\Anaconda3\\lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\stdhooks'...
181804 INFO: Loading module hook 'hook-nbconvert.py' from 'D:\\ProgramData\\Anaconda3\\lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\stdhooks'...
181885 INFO: Loading module hook 'hook-nbformat.py' from 'D:\\ProgramData\\Anaconda3\\lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\stdhooks'...
181920 INFO: Loading module hook 'hook-notebook.py' from 'D:\\ProgramData\\Anaconda3\\lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\stdhooks'...
183385 INFO: Loading module hook 'hook-openpyxl.py' from 'D:\\ProgramData\\Anaconda3\\lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\stdhooks'...
183454 INFO: Loading module hook 'hook-parso.py' from 'D:\\ProgramData\\Anaconda3\\lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\stdhooks'...
183465 INFO: Loading module hook 'hook-py.py' from 'D:\\ProgramData\\Anaconda3\\lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\stdhooks'...
183771 INFO: Loading module hook 'hook-pytest.py' from 'D:\\ProgramData\\Anaconda3\\lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\stdhooks'...
184171 INFO: Loading module hook 'hook-pythoncom.py' from 'D:\\ProgramData\\Anaconda3\\lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\stdhooks'...
184547 INFO: Loading module hook 'hook-pywintypes.py' from 'D:\\ProgramData\\Anaconda3\\lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\stdhooks'...
184908 INFO: Loading module hook 'hook-tables.py' from 'D:\\ProgramData\\Anaconda3\\lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\stdhooks'...
184909 INFO: Loading module hook 'hook-win32com.py' from 'D:\\ProgramData\\Anaconda3\\lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\stdhooks'...
185000 INFO: Loading module hook 'hook-zmq.py' from 'D:\\ProgramData\\Anaconda3\\lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\stdhooks'...
185786 INFO: Loading module hook 'hook-babel.py' from 'D:\\ProgramData\\Anaconda3\\lib\\site-packages\\PyInstaller\\hooks'...
185888 INFO: Loading module hook 'hook-django.contrib.sessions.py' from 'D:\\ProgramData\\Anaconda3\\lib\\site-packages\\PyInstaller\\hooks'...
185959 INFO: Loading module hook 'hook-django.db.backends.mysql.base.py' from 'D:\\ProgramData\\Anaconda3\\lib\\site-packages\\PyInstaller\\hooks'...
185960 INFO: Loading module hook 'hook-django.db.backends.oracle.base.py' from 'D:\\ProgramData\\Anaconda3\\lib\\site-packages\\PyInstaller\\hooks'...
185960 WARNING: Hidden import "django.db.backends.oracle.compiler" not found!
185961 INFO: Loading module hook 'hook-gevent.py' from 'D:\\ProgramData\\Anaconda3\\lib\\site-packages\\PyInstaller\\hooks'...
186103 INFO: Packages required by gevent:
['greenlet', 'cffi']
186423 INFO: Import to be excluded not found: 'gevent.testing'
186424 INFO: Import to be excluded not found: 'gevent.tests'
186424 INFO: Loading module hook 'hook-setuptools.msvc.py' from 'D:\\ProgramData\\Anaconda3\\lib\\site-packages\\PyInstaller\\hooks'...
186436 INFO: Loading module hook 'hook-lxml.isoschematron.py' from 'D:\\ProgramData\\Anaconda3\\lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\stdhooks'...
186441 INFO: Loading module hook 'hook-lxml.objectify.py' from 'D:\\ProgramData\\Anaconda3\\lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\stdhooks'...
186636 INFO: Looking for ctypes DLLs
186770 INFO: Including run-time hook 'D:\\ProgramData\\Anaconda3\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_inspect.py'
186771 INFO: Including run-time hook 'D:\\ProgramData\\Anaconda3\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_multiprocessing.py'
186773 INFO: Including run-time hook 'D:\\ProgramData\\Anaconda3\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_pkgres.py'
186776 INFO: Including run-time hook 'D:\\ProgramData\\Anaconda3\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_win32api.py'
186777 INFO: Including run-time hook 'D:\\ProgramData\\Anaconda3\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_django.py'
186779 INFO: Including run-time hook 'D:\\ProgramData\\Anaconda3\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth__tkinter.py'
186780 INFO: Including run-time hook 'D:\\ProgramData\\Anaconda3\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_pyqt5.py'
186781 INFO: Including run-time hook 'D:\\ProgramData\\Anaconda3\\lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\rthooks\\pyi_rth_traitlets.py'
186782 INFO: Including run-time hook 'D:\\ProgramData\\Anaconda3\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_win32comgenpy.py'
186783 INFO: Including run-time hook 'D:\\ProgramData\\Anaconda3\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_mplconfig.py'
186849 INFO: Looking for dynamic libraries
188435 INFO: Looking for eggs
188436 INFO: Using Python library D:\ProgramData\Anaconda3\python36.dll
188436 INFO: Found binding redirects:
[]
188485 INFO: Warnings written to D:\PycharmProject\my_code\项目文件\my_code\django_app\build\manage\warn-manage.txt
189132 INFO: Graph cross-reference written to D:\PycharmProject\my_code\项目文件\my_code\django_app\build\manage\xref-manage.html
189456 INFO: checking PYZ
189458 INFO: Building PYZ because PYZ-00.toc is non existent
189458 INFO: Building PYZ (ZlibArchive) D:\PycharmProject\my_code\项目文件\my_code\django_app\build\manage\PYZ-00.pyz
196397 INFO: Building PYZ (ZlibArchive) D:\PycharmProject\my_code\项目文件\my_code\django_app\build\manage\PYZ-00.pyz completed successfully.
196505 INFO: checking PKG
196505 INFO: Building PKG because PKG-00.toc is non existent
196505 INFO: Building PKG (CArchive) PKG-00.pkg
196549 INFO: Building PKG (CArchive) PKG-00.pkg completed successfully.
196551 INFO: Bootloader D:\ProgramData\Anaconda3\lib\site-packages\PyInstaller\bootloader\Windows-64bit\run.exe
196552 INFO: Building EXE because EXE-00.toc is non existent
196552 INFO: Building EXE from EXE-00.toc
196553 INFO: Copying icons from ['D:\\ProgramData\\Anaconda3\\lib\\site-packages\\PyInstaller\\bootloader\\images\\icon-console.ico']
196554 INFO: Writing RT_GROUP_ICON 0 resource with 104 bytes
196554 INFO: Writing RT_ICON 1 resource with 3752 bytes
196554 INFO: Writing RT_ICON 2 resource with 2216 bytes
196554 INFO: Writing RT_ICON 3 resource with 1384 bytes
196554 INFO: Writing RT_ICON 4 resource with 37019 bytes
196555 INFO: Writing RT_ICON 5 resource with 9640 bytes
196555 INFO: Writing RT_ICON 6 resource with 4264 bytes
196555 INFO: Writing RT_ICON 7 resource with 1128 bytes
196557 INFO: Appending archive to EXE D:\PycharmProject\my_code\项目文件\my_code\django_app\build\manage\manage.exe
201350 INFO: Building EXE from EXE-00.toc completed successfully.
201364 INFO: checking COLLECT
201365 INFO: Building COLLECT because COLLECT-00.toc is non existent
201365 INFO: Building COLLECT COLLECT-00.toc
212652 INFO: Building COLLECT COLLECT-00.toc completed successfully.
打包完成之后,开始测试是否打包可以使用
切换打包后生成的dist/manage目录,执行manage.exe runserver 8000
RuntimeError: Script runserver does not exist.
[11304] Failed to execute script 'manage' due to unhandled exception!提示以上异常时可尝试使用
manage.exe runserver 8000 --noreload 启动
PS D:\PycharmProject\my_code\项目文件\django项目\django_app\dist\manage> .\manage.exe runserver 8000 --noreload
Performing system checks...
***START AT 2022-06-15 10:08:42***
***END AT 2022-06-15 10:08:42***
Neo4j Init ...
--Neo4j connecting--
System check identified no issues (0 silenced).
You have 18 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
Run 'python manage.py migrate' to apply them.
June 15, 2022 - 10:08:42
Django version 3.2.13, using settings 'clue_graph.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
相关问题与解决方法:
1、ERROR conda.core.link:_execute_actions(337): An error occurred while installing package 'conda-forge::tqdm-4.64.0-pyhd8ed1ab_0'.
CondaError: Cannot link a source that does not exist. D:\ProgramData\Anaconda3\Scripts\conda.exe
Running `conda clean --packages` may resolve your problem.
Attempting to roll back.CondaError: Cannot link a source that does not exist. D:\ProgramData\Anaconda3\Scripts\conda.exe
Running `conda clean --packages` may resolve your problem.
解决方法:
安装tqdm
conda install tqdm -f
重新安装pip
conda install pip
2、RuntimeError: No metadata path found for distribution 'greenlet'.
使用以下命令重新安装:
pip install --ignore-installed greenlet
3、No such file or directory: 'D:\\PycharmProject\\ZZSN_code01\\图谱项目\\金融图谱\\shenji_graph_app1\\dist\\manage\\py2neo\\VERSION' [10644] Failed to execute script 'manage' due to unhandled exception!
原因:打包的时候没有将py2neo打包进去。
创建文件D:\ProgramData\Anaconda3\Lib\site-packages\PyInstaller\hooks\hook-py2neo.py
文件中添加内容:
from PyInstaller.utils.hooks import collect_submodules, collect_data_files
datas = collect_data_files('py2neo')然后重新打包
4、pyinstaller 打包参数
-F, –onefile 打包成一个exe文件。
-D, –onedir 创建一个目录,包含exe文件,但会依赖很多文件(默认选项)。
-c, –console, –nowindowed 使用控制台,无界面(默认)
-w, –windowed, –noconsole 使用窗口,无控制台