日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python封装成exe后运行失败_Python的带pandas包的程序封装成exe 2018-01-11

發布時間:2024/2/28 python 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python封装成exe后运行失败_Python的带pandas包的程序封装成exe 2018-01-11 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

前言:

今天在網上看了很多教程,最后還是在運行pyinstaller命令行時解決

環境配置:python 2.7.9 32位,setuptools 19.2版,WIN 64位

1.安裝PyInstaller和pywin32

1.1 Pyinstaller

安裝略

可以只是生成單獨的可執行程序

且支持的版本也多:2.3到2.7都支持。以及x64也支持

也可以自定義圖標

1.2 pywin32

2. 封裝成exe

2.1 示范程序用了pandas包

import pandas as pd

import sys,os

import ConfigParser

2.2 pyinstaller使用封裝語句

基本語句

pyinstaller -F demo.py

一般來說用這個就可以了

-D, --one-dir打包成一個文件夾,默認

-F, --one-file打包成一個exe文件

-p DIR, --paths DIR添加路徑,一般用來添加程序所用到的包的所在位置

-c, --console, --nowindowed提供程序視窗,程序有輸入輸出的界面,默認

-w, --windowed, --noconsole無視窗,程序后臺運行

-i , --icon 添加icon圖標

3. 運行時遇到的問題

生成的exe出現ImportError

image.png

4. 解決方法

4.1 看CMD提示,在封裝時導入缺失的包

pyinstaller -F -w -i xxx.ico yyy.py --hidden-import=pandas._libs.tslibs.timedeltas

4.2 安裝對應的hook

太麻煩,此處略

其他注意的東西

文件夾注意...\dist(生成的exe所在文件位置)和...\build(生成的文件夾所在位置)

warnXXX.txt 里面包含錯誤信息,如

missing module named pyimod03_importers - imported by C:\Python27\lib\site-packages\pyinstaller-3.4.dev0_ab8fd9753-py2.7.egg\PyInstaller\loader\rthooks\pyi_rth_pkgres.py

missing module named 'multiprocessing.popen_fork' - imported by C:\Python27\lib\site-packages\pyinstaller-3.4.dev0_ab8fd9753-py2.7.egg\PyInstaller\loader\rthooks\pyi_rth_multiprocessing.py

missing module named 'multiprocessing.popen_spawn_win32' - imported by C:\Python27\lib\site-packages\pyinstaller-3.4.dev0_ab8fd9753-py2.7.egg\PyInstaller\loader\rthooks\pyi_rth_multiprocessing.py

missing module named 'multiprocessing.spawn' - imported by C:\Python27\lib\site-packages\pyinstaller-3.4.dev0_ab8fd9753-py2.7.egg\PyInstaller\loader\rthooks\pyi_rth_multiprocessing.py

附錄:正確生成exe時控制臺信息

c:\Python27>pyinstaller -F Df2Csv.py --hidden-import=pandas._libs.tslibs.timedeltas

116 INFO: PyInstaller: 3.4.dev0-ab8fd9753

116 INFO: Python: 2.7.9

116 INFO: Platform: Windows-8-6.2.9200

116 INFO: wrote c:\Python27\Df2Csv.spec

116 INFO: UPX is not available.

116 INFO: Extending PYTHONPATH with paths

['c:\\Python27', 'c:\\Python27']

116 INFO: checking Analysis

147 INFO: Building because c:\Python27\Df2Csv.py changed

147 INFO: Initializing module dependency graph...

147 INFO: Initializing module graph hooks...

162 INFO: Analyzing hidden import 'pandas._libs.tslibs.timedeltas'

209 INFO: Processing pre-find module path hook distutils

2348 INFO: Processing pre-safe import module hook _xmlplus

5984 INFO: Processing pre-safe import module hook six.moves

8680 INFO: Processing pre-find module path hook site

8680 INFO: site: retargeting to fake-dir 'C:\\Python27\\lib\\site-packages\\pyinstaller-3.4.dev0_ab8fd9753-py2.7.egg\\PyInstaller\\fake-modules'

8726 INFO: Processing pre-safe import module hook win32com

19948 INFO: running Analysis out00-Analysis.toc

19963 INFO: Adding Microsoft.VC90.CRT to dependent assemblies of final executable

required by C:\Python27\python.exe

20095 INFO: Found C:\Windows\WinSxS\Manifests\x86_policy.9.0.microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.1_none_8550c6b5d18a9128.manifest

20111 INFO: Found C:\Windows\WinSxS\Manifests\x86_policy.9.0.microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.4148_none_f47e1bd6f6571810.manifest

20111 INFO: Found C:\Windows\WinSxS\Manifests\x86_policy.9.0.microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.6161_none_f480bfaef65491a5.manifest

20111 INFO: Found C:\Windows\WinSxS\Manifests\x86_policy.9.0.microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.9158_none_f47f259ef656232a.manifest

20252 INFO: Searching for assembly x86_Microsoft.VC90.CRT_1fc8b3b9a1e18e3b_9.0.30729.9158_none ...

20267 INFO: Found manifest C:\Windows\WinSxS\Manifests\x86_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.9158_none_5091b51ebcb97cdc.manifest

20267 INFO: Searching for file msvcr90.dll

20267 INFO: Found file C:\Windows\WinSxS\x86_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.9158_none_5091b51ebcb97cdc\msvcr90.dll

20267 INFO: Searching for file msvcp90.dll

20267 INFO: Found file C:\Windows\WinSxS\x86_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.9158_none_5091b51ebcb97cdc\msvcp90.dll

20267 INFO: Searching for file msvcm90.dll

20267 INFO: Found file C:\Windows\WinSxS\x86_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.9158_none_5091b51ebcb97cdc\msvcm90.dll

20407 INFO: Found C:\Windows\WinSxS\Manifests\x86_policy.9.0.microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.1_none_8550c6b5d18a9128.manifest

20407 INFO: Found C:\Windows\WinSxS\Manifests\x86_policy.9.0.microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.4148_none_f47e1bd6f6571810.manifest

20407 INFO: Found C:\Windows\WinSxS\Manifests\x86_policy.9.0.microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.6161_none_f480bfaef65491a5.manifest

20407 INFO: Found C:\Windows\WinSxS\Manifests\x86_policy.9.0.microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.9158_none_f47f259ef656232a.manifest

20423 INFO: Adding redirect Microsoft.VC90.CRT version (9, 0, 21022, 8) -> (9, 0, 30729, 9158)

20564 INFO: Caching module hooks...

20580 INFO: Analyzing c:\Python27\Df2Csv.py

20595 INFO: Loading module hooks...

20595 INFO: Loading module hook "hook-distutils.py"...

20595 INFO: Loading module hook "hook-sysconfig.py"...

20595 INFO: Loading module hook "hook-xml.py"...

20689 INFO: Loading module hook "hook-httplib.py"...

20689 INFO: Loading module hook "hook-pydoc.py"...

20689 INFO: Excluding import 'Tkinter'

20705 INFO: Removing import of Tkinter from module pydoc

20705 INFO: Loading module hook "hook-_tkinter.py"...

20907 INFO: checking Tree

20955 INFO: checking Tree

20970 INFO: Loading module hook "hook-pkg_resources.py"...

21178 INFO: Loading module hook "hook-pytz.py"...

21281 INFO: Loading module hook "hook-pywintypes.py"...

21515 INFO: Loading module hook "hook-setuptools.py"...

21515 WARNING: Hidden import "setuptools.msvc" not found!

21515 INFO: Loading module hook "hook-encodings.py"...

22281 INFO: Loading module hook "hook-numpy.core.py"...

22344 INFO: Loading module hook "hook-sqlite3.py"...

22438 INFO: Loading module hook "hook-win32com.py"...

22536 INFO: Loading module hook "hook-pythoncom.py"...

22833 INFO: checking Tree

22927 INFO: checking Tree

22974 INFO: checking Tree

23046 INFO: Looking for ctypes DLLs

23126 INFO: Analyzing run-time hooks ...

23126 INFO: Including run-time hook 'pyi_rth_multiprocessing.py'

23141 INFO: Including run-time hook 'pyi_rth_win32comgenpy.py'

23141 INFO: Including run-time hook 'pyi_rth__tkinter.py'

23141 INFO: Including run-time hook 'pyi_rth_pkgres.py'

23173 INFO: Looking for dynamic libraries

23735 INFO: Found C:\Windows\WinSxS\Manifests\x86_policy.9.0.microsoft.vc90.mfc_1fc8b3b9a1e18e3b_9.0.30729.1_none_7dd1e0ebd6590e0b.manifest

23735 INFO: Found C:\Windows\WinSxS\Manifests\x86_policy.9.0.microsoft.vc90.mfc_1fc8b3b9a1e18e3b_9.0.30729.4148_none_ecff360cfb2594f3.manifest

23735 INFO: Found C:\Windows\WinSxS\Manifests\x86_policy.9.0.microsoft.vc90.mfc_1fc8b3b9a1e18e3b_9.0.30729.6161_none_ed01d9e4fb230e88.manifest

23876 INFO: Searching for assembly x86_Microsoft.VC90.MFC_1fc8b3b9a1e18e3b_9.0.30729.6161_none ...

23876 INFO: Found manifest C:\Windows\WinSxS\Manifests\x86_microsoft.vc90.mfc_1fc8b3b9a1e18e3b_9.0.30729.6161_none_4bf7e3e2bf9ada4c.manifest

23876 INFO: Searching for file mfc90.dll

23876 INFO: Found file C:\Windows\WinSxS\x86_microsoft.vc90.mfc_1fc8b3b9a1e18e3b_9.0.30729.6161_none_4bf7e3e2bf9ada4c\mfc90.dll

23876 INFO: Searching for file mfc90u.dll

23876 INFO: Found file C:\Windows\WinSxS\x86_microsoft.vc90.mfc_1fc8b3b9a1e18e3b_9.0.30729.6161_none_4bf7e3e2bf9ada4c\mfc90u.dll

23876 INFO: Searching for file mfcm90.dll

23876 INFO: Found file C:\Windows\WinSxS\x86_microsoft.vc90.mfc_1fc8b3b9a1e18e3b_9.0.30729.6161_none_4bf7e3e2bf9ada4c\mfcm90.dll

23876 INFO: Searching for file mfcm90u.dll

23876 INFO: Found file C:\Windows\WinSxS\x86_microsoft.vc90.mfc_1fc8b3b9a1e18e3b_9.0.30729.6161_none_4bf7e3e2bf9ada4c\mfcm90u.dll

24016 INFO: Found C:\Windows\WinSxS\Manifests\x86_policy.9.0.microsoft.vc90.mfc_1fc8b3b9a1e18e3b_9.0.30729.1_none_7dd1e0ebd6590e0b.manifest

24016 INFO: Found C:\Windows\WinSxS\Manifests\x86_policy.9.0.microsoft.vc90.mfc_1fc8b3b9a1e18e3b_9.0.30729.4148_none_ecff360cfb2594f3.manifest

24016 INFO: Found C:\Windows\WinSxS\Manifests\x86_policy.9.0.microsoft.vc90.mfc_1fc8b3b9a1e18e3b_9.0.30729.6161_none_ed01d9e4fb230e88.manifest

24016 INFO: Adding redirect Microsoft.VC90.MFC version (9, 0, 21022, 8) -> (9, 0, 30729, 6161)

40203 INFO: Looking for eggs

150687 INFO: Using Python library C:\Windows\system32\python27.dll

150687 INFO: Found binding redirects:

[BindingRedirect(name=u'Microsoft.VC90.CRT', language=None, arch=u'x86', oldVersion=(9, 0, 21022, 8), newVersion=(9, 0, 30729, 9158), publicKeyToken=u'1fc8b3b9a1e18e3b'), BindingRedirect(name=u'Microsoft.VC90.MFC', language=None, arch=u'x86', oldVersion=(9, 0, 21022, 8), newVersion=(9, 0, 30729, 6161), publicKeyToken=u'1fc8b3b9a1e18e3b')]

150718 INFO: Warnings written to c:\Python27\build\Df2Csv\warnDf2Csv.txt

150937 INFO: Graph cross-reference written to c:\Python27\build\Df2Csv\xref-Df2Csv.html

151749 INFO: checking PYZ

151796 INFO: checking PKG

151812 INFO: Building because c:\Python27\Df2Csv.py changed

151812 INFO: Building PKG (CArchive) out00-PKG.pkg

153285 INFO: Redirecting Microsoft.VC90.CRT version (9, 0, 21022, 8) -> (9, 0, 30729, 9158)

162986 INFO: Building PKG (CArchive) out00-PKG.pkg completed successfully.

163538 INFO: Bootloader C:\Python27\lib\site-packages\pyinstaller-3.4.dev0_ab8fd9753-py2.7.egg\PyInstaller\bootloader\Windows-32bit\run.exe

163538 INFO: checking EXE

163554 INFO: Rebuilding out00-EXE.toc because pkg is more recent

163554 INFO: Building EXE from out00-EXE.toc

163570 INFO: Appending archive to EXE c:\Python27\dist\Df2Csv.exe

163601 INFO: Building EXE from out00-EXE.toc completed successfully.

總結

以上是生活随笔為你收集整理的python封装成exe后运行失败_Python的带pandas包的程序封装成exe 2018-01-11的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。