Pyinstaller-Matplotlib安装已损坏-无法执行scrypt

时间:2020-05-06 12:54:31

标签: python python-3.x matplotlib pyinstaller

随时检查我的存储库中的代码。

尝试命令: pyinstaller -y file.py

发生了什么事: 我一直试图从.py制作.exe文件。 Kinda的大型项目一切正常,但是即使我没有做任何改动,它也停止了工作。 尝试了数百万种可能的解决方案(更新所有软件包,安装pyinstaller的开发版本,修改命令,重新安装matplotlib,重新启动计算机...),经过5个小时的研究,我决定在此处发布问题。 正如我所说的,它正在工作...文件目录也很好,即使我将它们放在其他目录中,原始.py代码也可以正常工作。它是多个文件和多个包,所有文件和包均已导入到我正在编译的这个文件中(代码)。 运行.exe文件后,我收到了这样的输出:(在存储库中)。 很抱歉放置屏幕截图,而不是代码,但在关闭之前会显示一半的发送时间。

问题几乎肯定在matplotlib内,因为即使我不使用它(在其他程序中尝试过),但包含import matplotlib.pyplot as plt,该程序也不会像同一个程序(另一个一),没有列入顺利进行。我说的当然是.exe文件,因为.py始终有效。

其他信息: 我正在使用: Python 32位3.8.2。 Matplotlib 3.2.1 Pyinstaller 4.0.dev0 + 3010fdfaa0 (每个软件包的最新信息,我今天都更新了-2020年5月2日)

带有文件的存储库,并在启动.exe文件时显示错误: https://github.com/jakubedzior/MyPortfolio/tree/master/Koronawirus

(代码):

# Packages that are used in files below
from bs4 import BeautifulSoup
import requests
from pathlib import Path
import csv
import glob
import os
from time import sleep
from pathlib import Path
import numpy as np
import matplotlib.pyplot as plt
from PIL import Image
from datetime import date, timedelta

# My files I import (functions):
from Wiki_update import *
from Csv_edit import *
from Reproduction import *
from Predictions_weekly import *

PS:文件名为Koronawirus.py(/ exe)。

我从pyinstaller获得的输出

PS C:\Users\jakub\Desktop\Programming\Python files\Koronawirus> pyinstaller -y Koronawirus.py                  78 INFO: PyInstaller: 4.0.dev0+3010fdfaa0
78 INFO: Python: 3.8.2
78 INFO: Platform: Windows-10-10.0.18362-SP0
78 INFO: wrote C:\Users\jakub\Desktop\Programming\Python files\Koronawirus\Koronawirus.spec
78 INFO: UPX is not available.
78 INFO: Extending PYTHONPATH with paths
['C:\\Users\\jakub\\Desktop\\Programming\\Python files\\Koronawirus',
 'C:\\Users\\jakub\\Desktop\\Programming\\Python files\\Koronawirus']
93 INFO: checking Analysis
93 INFO: Building Analysis because Analysis-00.toc is non existent
93 INFO: Initializing module dependency graph...
93 INFO: Caching module graph hooks...
109 INFO: Analyzing base_library.zip ...
5179 INFO: Processing pre-find module path hook distutils from 'c:\\users\\jakub\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages\\PyInstaller\\hooks\\pre_find_module_path\\hook-distutils.py'.
5181 INFO: distutils: retargeting to non-venv dir 'c:\\users\\jakub\\appdata\\local\\programs\\python\\python38-32\\lib'
8786 INFO: Caching module dependency graph...
8944 INFO: running Analysis Analysis-00.toc
8966 INFO: Adding Microsoft.Windows.Common-Controls to dependent assemblies of final executable
  required by c:\users\jakub\appdata\local\programs\python\python38-32\python.exe
9081 INFO: Analyzing C:\Users\jakub\Desktop\Programming\Python files\Koronawirus\Koronawirus.py
10333 INFO: Processing pre-safe import module hook urllib3.packages.six.moves from 'c:\\users\\jakub\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages\\PyInstaller\\hooks\\pre_safe_import_module\\hook-urllib3.packages.six.moves.py'.
12449 INFO: Processing pre-find module path hook site from 'c:\\users\\jakub\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages\\PyInstaller\\hooks\\pre_find_module_path\\hook-site.py'.
12450 INFO: site: retargeting to fake-dir 'c:\\users\\jakub\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages\\PyInstaller\\fake-modules'
15004 INFO: Processing pre-safe import module hook setuptools.extern.six.moves from 'c:\\users\\jakub\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages\\PyInstaller\\hooks\\pre_safe_import_module\\hook-setuptools.extern.six.moves.py'.
20241 INFO: Processing pre-safe import module hook six.moves from 'c:\\users\\jakub\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages\\PyInstaller\\hooks\\pre_safe_import_module\\hook-six.moves.py'.
22307 INFO: Processing module hooks...
22307 INFO: Loading module hook 'hook-certifi.py' from 'c:\\users\\jakub\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages\\PyInstaller\\hooks'...
22307 INFO: Loading module hook 'hook-Crypto.py' from 'c:\\users\\jakub\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages\\PyInstaller\\hooks'...
22323 INFO: Loading module hook 'hook-distutils.py' from 'c:\\users\\jakub\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages\\PyInstaller\\hooks'...
22323 INFO: Loading module hook 'hook-encodings.py' from 'c:\\users\\jakub\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages\\PyInstaller\\hooks'...
22445 INFO: Loading module hook 'hook-lib2to3.py' from 'c:\\users\\jakub\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages\\PyInstaller\\hooks'...
22454 INFO: Loading module hook 'hook-lxml.etree.py' from 'c:\\users\\jakub\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages\\PyInstaller\\hooks'...
22456 INFO: Loading module hook 'hook-matplotlib.backends.py' from 'c:\\users\\jakub\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages\\PyInstaller\\hooks'...
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "c:\users\jakub\appdata\local\programs\python\python38-32\lib\site-packages\matplotlib\__init__.py", line 1015, in <module>
    rcParams = rc_params()
  File "c:\users\jakub\appdata\local\programs\python\python38-32\lib\site-packages\matplotlib\__init__.py", line 878, in rc_params
    return rc_params_from_file(matplotlib_fname(), fail_on_error)
  File "c:\users\jakub\appdata\local\programs\python\python38-32\lib\site-packages\matplotlib\__init__.py", line 731, in matplotlib_fname
    for fname in gen_candidates():
  File "c:\users\jakub\appdata\local\programs\python\python38-32\lib\site-packages\matplotlib\__init__.py", line 728, in gen_candidates
    yield os.path.join(get_configdir(), 'matplotlibrc')
  File "c:\users\jakub\appdata\local\programs\python\python38-32\lib\site-packages\matplotlib\__init__.py", line 276, in wrapper
    ret = func(**kwargs)
  File "c:\users\jakub\appdata\local\programs\python\python38-32\lib\site-packages\matplotlib\__init__.py", line 609, in get_configdir
    return _get_config_or_cache_dir(_get_xdg_config_dir())
  File "c:\users\jakub\appdata\local\programs\python\python38-32\lib\site-packages\matplotlib\__init__.py", line 562, in _get_xdg_config_dir
    return os.environ.get('XDG_CONFIG_HOME') or str(Path.home() / ".config")
AttributeError: type object 'Path' has no attribute 'home'
22929 INFO: Loading module hook 'hook-matplotlib.py' from 'c:\\users\\jakub\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages\\PyInstaller\\hooks'...
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "c:\users\jakub\appdata\local\programs\python\python38-32\lib\site-packages\matplotlib\__init__.py", line 1015, in <module>
    rcParams = rc_params()
  File "c:\users\jakub\appdata\local\programs\python\python38-32\lib\site-packages\matplotlib\__init__.py", line 878, in rc_params
    return rc_params_from_file(matplotlib_fname(), fail_on_error)
  File "c:\users\jakub\appdata\local\programs\python\python38-32\lib\site-packages\matplotlib\__init__.py", line 731, in matplotlib_fname
    for fname in gen_candidates():
  File "c:\users\jakub\appdata\local\programs\python\python38-32\lib\site-packages\matplotlib\__init__.py", line 728, in gen_candidates
    yield os.path.join(get_configdir(), 'matplotlibrc')
  File "c:\users\jakub\appdata\local\programs\python\python38-32\lib\site-packages\matplotlib\__init__.py", line 276, in wrapper
    ret = func(**kwargs)
  File "c:\users\jakub\appdata\local\programs\python\python38-32\lib\site-packages\matplotlib\__init__.py", line 609, in get_configdir
    return _get_config_or_cache_dir(_get_xdg_config_dir())
  File "c:\users\jakub\appdata\local\programs\python\python38-32\lib\site-packages\matplotlib\__init__.py", line 562, in _get_xdg_config_dir
    return os.environ.get('XDG_CONFIG_HOME') or str(Path.home() / ".config")
AttributeError: type object 'Path' has no attribute 'home'
23633 INFO: Loading module hook 'hook-numpy.core.py' from 'c:\\users\\jakub\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages\\PyInstaller\\hooks'...
23756 INFO: Loading module hook 'hook-numpy.py' from 'c:\\users\\jakub\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages\\PyInstaller\\hooks'...
23758 INFO: Loading module hook 'hook-PIL.Image.py' from 'c:\\users\\jakub\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages\\PyInstaller\\hooks'...
24366 INFO: Loading module hook 'hook-PIL.py' from 'c:\\users\\jakub\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages\\PyInstaller\\hooks'...
24382 INFO: Import to be excluded not found: 'PyQt4'
24382 INFO: Import to be excluded not found: 'PySide'
24382 INFO: Excluding import 'tkinter'
24401 INFO:   Removing import of tkinter from module PIL.ImageTk
24404 INFO: Import to be excluded not found: 'FixTk'
24404 INFO: Excluding import 'PyQt5'
24426 INFO:   Removing import of PyQt5 from module PIL.ImageQt
24429 INFO: Loading module hook 'hook-PIL.SpiderImagePlugin.py' from 'c:\\users\\jakub\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages\\PyInstaller\\hooks'...
24429 INFO: Import to be excluded not found: 'FixTk'
24449 INFO: Excluding import 'tkinter'
24463 INFO: Loading module hook 'hook-pkg_resources.py' from 'c:\\users\\jakub\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages\\PyInstaller\\hooks'...
24987 INFO: Processing pre-safe import module hook win32com from 'c:\\users\\jakub\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages\\PyInstaller\\hooks\\pre_safe_import_module\\hook-win32com.py'.
Traceback (most recent call last):
  File "<string>", line 2, in <module>
ModuleNotFoundError: No module named 'win32com'
25088 INFO: Processing pre-safe import module hook win32com from 'c:\\users\\jakub\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages\\PyInstaller\\hooks\\pre_safe_import_module\\hook-win32com.py'.
Traceback (most recent call last):
  File "<string>", line 2, in <module>
ModuleNotFoundError: No module named 'win32com'
25410 INFO: Excluding import '__main__'
25414 INFO:   Removing import of __main__ from module pkg_resources
25415 INFO: Loading module hook 'hook-pycparser.py' from 'c:\\users\\jakub\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages\\PyInstaller\\hooks'...
25432 INFO: Loading module hook 'hook-setuptools.py' from 'c:\\users\\jakub\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages\\PyInstaller\\hooks'...
26113 INFO: Loading module hook 'hook-sysconfig.py' from 'c:\\users\\jakub\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages\\PyInstaller\\hooks'...
26129 INFO: Loading module hook 'hook-xml.dom.domreg.py' from 'c:\\users\\jakub\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages\\PyInstaller\\hooks'...
26129 INFO: Loading module hook 'hook-xml.etree.cElementTree.py' from 'c:\\users\\jakub\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages\\PyInstaller\\hooks'...
26144 INFO: Loading module hook 'hook-xml.py' from 'c:\\users\\jakub\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages\\PyInstaller\\hooks'...
26144 INFO: Loading module hook 'hook-_tkinter.py' from 'c:\\users\\jakub\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages\\PyInstaller\\hooks'...
26383 INFO: checking Tree
26389 INFO: Building Tree because Tree-00.toc is non existent
26397 INFO: Building Tree Tree-00.toc
26542 INFO: checking Tree
26542 INFO: Building Tree because Tree-01.toc is non existent
26545 INFO: Building Tree Tree-01.toc
26654 INFO: Looking for ctypes DLLs
26732 INFO: Analyzing run-time hooks ...
26732 INFO: Including run-time hook 'c:\\users\\jakub\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth__tkinter.py'
26748 INFO: Including run-time hook 'c:\\users\\jakub\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_multiprocessing.py'
26780 INFO: Including run-time hook 'c:\\users\\jakub\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_pkgres.py'
26786 INFO: Including run-time hook 'c:\\users\\jakub\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_mplconfig.py'
26797 INFO: Including run-time hook 'c:\\users\\jakub\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_mpldata.py'
26814 INFO: Including run-time hook 'c:\\users\\jakub\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_certifi.py'
26851 INFO: Looking for dynamic libraries
27717 INFO: Looking for eggs
27717 INFO: Using Python library c:\users\jakub\appdata\local\programs\python\python38-32\python38.dll
27717 INFO: Found binding redirects:
[]
27748 INFO: Warnings written to C:\Users\jakub\Desktop\Programming\Python files\Koronawirus\build\Koronawirus\warn-Koronawirus.txt
28024 INFO: Graph cross-reference written to C:\Users\jakub\Desktop\Programming\Python files\Koronawirus\build\Koronawirus\xref-Koronawirus.html
28169 INFO: checking PYZ
28170 INFO: Building PYZ because PYZ-00.toc is non existent
28172 INFO: Building PYZ (ZlibArchive) C:\Users\jakub\Desktop\Programming\Python files\Koronawirus\build\Koronawirus\PYZ-00.pyz
30186 INFO: Building PYZ (ZlibArchive) C:\Users\jakub\Desktop\Programming\Python files\Koronawirus\build\Koronawirus\PYZ-00.pyz completed successfully.
30223 INFO: checking PKG
30223 INFO: Building PKG because PKG-00.toc is non existent
30226 INFO: Building PKG (CArchive) PKG-00.pkg
30265 INFO: Building PKG (CArchive) PKG-00.pkg completed successfully.
30269 INFO: Bootloader c:\users\jakub\appdata\local\programs\python\python38-32\lib\site-packages\PyInstaller\bootloader\Windows-32bit\run.exe
30277 INFO: checking EXE
30279 INFO: Building EXE because EXE-00.toc is non existent
30284 INFO: Building EXE from EXE-00.toc
30297 INFO: Appending archive to EXE C:\Users\jakub\Desktop\Programming\Python files\Koronawirus\build\Koronawirus\Koronawirus.exe
30322 INFO: Building EXE from EXE-00.toc completed successfully.
30336 INFO: checking COLLECT
30337 INFO: Building COLLECT because COLLECT-00.toc is non existent
30345 INFO: Building COLLECT COLLECT-00.toc
36861 INFO: Building COLLECT COLLECT-00.toc completed successfully.
PS C:\Users\jakub\Desktop\Programming\Python files\Koronawirus>

3 个答案:

答案 0 :(得分:0)

我和你有完全一样的错误。

执行exe文件时,它关闭,没有任何错误代码

我可以通过删除anaconda环境来修复它

如果它是anaconda开发环境,则将其替换为普通的python环境。

答案 1 :(得分:0)

检查您是否在使用 pyinstaller 的机器上安装了 Visual C++ Redistributable Package (vc_redist.x64.exe) 在构建之前可执行文件。 见Error after using PyInstaller for script with Matplotlib

答案 2 :(得分:0)

通过在使用 pip uninstall pathlib 的环境中执行 pyinstaller,我能够解决此问题。

这应该适用于任何使用 python >=3.5 的人

问题的原因是从python 3.5及更高版本开始,pathlib与python的所有标准库捆绑在一起。这将是具有 Path.home() 的较新版本。但是,如果出于某种原因,像我一样,您还通过 pathlib 作为独立软件包安装了 pip,它将是没有 pathlib.Path.home() 的旧版本,因此会中断当 home() 被调用时。

在使用 pip uninstall pathlib 卸载 pathlib 之前,请确保:

  1. 通过运行 python --version,您实际上拥有了 python >= 3.5。
  2. 通过运行 pathlib
  3. ,您实际上对“旧”pip show pathlib 进行了冗余安装