Python Pyinstaller Matplotlibrary

Python Pyinstaller Matplotlibrc(Python Pyinstaller Matplotlibrary)

本文介绍了Python Pyinstaller Matplotlibrary的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尊敬的万维网Python专家

我真的希望在我遇到的pyinstaller问题上得到帮助。

我希望将python脚本转换为可执行文件,以便可以分发给我的朋友和同事。 以前,我曾将相同的python脚本转换为.exe文件,但是我不小心删除了该文件,现在我有了一台安装了python 3.7.8、pyinstaller 3.6版和matplotlib 3.2.2版的新计算机。

.py文件上有用于简单图形用户界面的tkinter库,而睡觉只是使用numpy、pandas库和matplotlib fr数据可视化的数据分析。此外,还有一个yFinance库可以从雅虎财经网站上提取股票数据。此程序的输出只是所选股票指数的matplotlib图的pdf文件。

我可以在空闲或jupyter笔记本上很好地运行这段python代码。

但在我将其转换为可执行文件时,程序没有加载,并且在控制台中出现以下错误消息:

运行时错误:找不到matplotlibrary文件;matplotlib安装已损坏

我曾尝试将matplotlib软件包重新安装到其他版本,如3.0、3.1.3等,但结果显示相同的运行时错误消息。

您能告诉我哪里出了问题吗?如何克服这样的问题?

下面是我用来将python转换为.exe的pyinstaller代码:

C:UsersisamshahabDesktopWork StuffsCoCStockStockIndexSummaryTool>pyinstaller--onefile YFScrapping.py
'pyinstaller--onefile' is not recognized as an internal or external command,
operable program or batch file.

C:UsersisamshahabDesktopWork StuffsCoCStockStockIndexSummaryTool>pyinstaller --onefile YFScrapping.py
103 INFO: PyInstaller: 3.6
103 INFO: Python: 3.7.8
104 INFO: Platform: Windows-10-10.0.18362-SP0
106 INFO: wrote C:UsersisamshahabDesktopWork StuffsCoCStockStockIndexSummaryToolYFScrapping.spec
110 INFO: UPX is not available.
113 INFO: Extending PYTHONPATH with paths
['C:\Users\isamshahab\Desktop\Work '
 'Stuffs\CoC\Stock\StockIndexSummaryTool',
 'C:\Users\isamshahab\Desktop\Work '
 'Stuffs\CoC\Stock\StockIndexSummaryTool']
114 INFO: checking Analysis
114 INFO: Building Analysis because Analysis-00.toc is non existent
114 INFO: Initializing module dependency graph...
120 INFO: Caching module graph hooks...
133 INFO: Analyzing base_library.zip ...
3509 INFO: Processing pre-find module path hook   distutils
3510 INFO: distutils: retargeting to non-venv dir 'c:\users\isamshahab\appdata\local\programs\python\python37\lib'
5744 INFO: Caching module dependency graph...
5905 INFO: running Analysis Analysis-00.toc
5908 INFO: Adding Microsoft.Windows.Common-Controls to dependent assemblies of final executable
  required by c:usersisamshahabappdatalocalprogramspythonpython37python.exe
6047 INFO: Analyzing C:UsersisamshahabDesktopWork StuffsCoCStockStockIndexSummaryToolYFScrapping.py
11245 INFO: Processing pre-find module path hook   site
11246 INFO: site: retargeting to fake-dir 'c:\users\isamshahab\appdata\local\programs\python\python37\lib\site-packages\PyInstaller\fake-modules'
13580 INFO: Processing pre-safe import module hook   setuptools.extern.six.moves
31348 INFO: Processing pre-safe import module hook   six.moves
31905 INFO: Processing pre-safe import module hook   urllib3.packages.six.moves
64089 INFO: Processing module hooks...
64090 INFO: Loading module hook "hook-certifi.py"...
64092 INFO: Loading module hook "hook-distutils.py"...
64094 INFO: Loading module hook "hook-encodings.py"...
64226 INFO: Loading module hook "hook-importlib_metadata.py"...
64228 INFO: Loading module hook "hook-IPython.py"...
64830 INFO: Excluding import 'PyQt5'
64836 INFO:   Removing import of PyQt5 from module IPython.external.qt_loaders
64837 INFO: Excluding import 'PyQt4'
64844 INFO:   Removing import of PyQt4 from module IPython.external.qt_loaders
64845 INFO: Excluding import 'matplotlib'
64852 INFO:   Removing import of matplotlib from module IPython.core.pylabtools
64852 INFO:   Removing import of matplotlib.pyplot from module IPython.core.pylabtools
64853 INFO:   Removing import of matplotlib.backend_bases from module IPython.core.pylabtools
64853 INFO:   Removing import of matplotlib._pylab_helpers from module IPython.core.pylabtools
64853 INFO:   Removing import of matplotlib.figure from module IPython.core.pylabtools
64854 INFO: Excluding import 'gtk'
64866 INFO: Excluding import 'tkinter'
64874 INFO:   Removing import of tkinter from module IPython.lib.clipboard
64877 INFO: Excluding import 'PySide'
64885 INFO:   Removing import of PySide from module IPython.external.qt_loaders
64886 INFO: Loading module hook "hook-jedi.py"...
65251 INFO: Loading module hook "hook-jinja2.py"...
65282 INFO: Loading module hook "hook-jsonschema.py"...
65295 INFO: Loading module hook "hook-lib2to3.py"...
65302 INFO: Loading module hook "hook-lxml.etree.py"...
65308 INFO: Loading module hook "hook-matplotlib.backends.py"...
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "c:usersisamshahabappdatalocalprogramspythonpython37libsite-packagesmatplotlib\__init__.py", line 1015, in <module>
    rcParams = rc_params()
  File "c:usersisamshahabappdatalocalprogramspythonpython37libsite-packagesmatplotlib\__init__.py", line 878, in rc_params
    return rc_params_from_file(matplotlib_fname(), fail_on_error)
  File "c:usersisamshahabappdatalocalprogramspythonpython37libsite-packagesmatplotlib\__init__.py", line 731, in matplotlib_fname
    for fname in gen_candidates():
  File "c:usersisamshahabappdatalocalprogramspythonpython37libsite-packagesmatplotlib\__init__.py", line 728, in gen_candidates
    yield os.path.join(get_configdir(), 'matplotlibrc')
  File "c:usersisamshahabappdatalocalprogramspythonpython37libsite-packagesmatplotlib\__init__.py", line 276, in wrapper
    ret = func(**kwargs)
  File "c:usersisamshahabappdatalocalprogramspythonpython37libsite-packagesmatplotlib\__init__.py", line 609, in get_configdir
    return _get_config_or_cache_dir(_get_xdg_config_dir())
  File "c:usersisamshahabappdatalocalprogramspythonpython37libsite-packagesmatplotlib\__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'
66344 INFO: Loading module hook "hook-matplotlib.py"...
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "c:usersisamshahabappdatalocalprogramspythonpython37libsite-packagesmatplotlib\__init__.py", line 1015, in <module>
    rcParams = rc_params()
  File "c:usersisamshahabappdatalocalprogramspythonpython37libsite-packagesmatplotlib\__init__.py", line 878, in rc_params
    return rc_params_from_file(matplotlib_fname(), fail_on_error)
  File "c:usersisamshahabappdatalocalprogramspythonpython37libsite-packagesmatplotlib\__init__.py", line 731, in matplotlib_fname
    for fname in gen_candidates():
  File "c:usersisamshahabappdatalocalprogramspythonpython37libsite-packagesmatplotlib\__init__.py", line 728, in gen_candidates
    yield os.path.join(get_configdir(), 'matplotlibrc')
  File "c:usersisamshahabappdatalocalprogramspythonpython37libsite-packagesmatplotlib\__init__.py", line 276, in wrapper
    ret = func(**kwargs)
  File "c:usersisamshahabappdatalocalprogramspythonpython37libsite-packagesmatplotlib\__init__.py", line 609, in get_configdir
    return _get_config_or_cache_dir(_get_xdg_config_dir())
  File "c:usersisamshahabappdatalocalprogramspythonpython37libsite-packagesmatplotlib\__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'
67281 INFO: Loading module hook "hook-nbconvert.py"...
67303 INFO: Loading module hook "hook-nbformat.py"...
67321 INFO: Loading module hook "hook-notebook.py"...
69240 INFO: Loading module hook "hook-numpy.core.py"...
69470 INFO: Loading module hook "hook-numpy.py"...
69472 INFO: Loading module hook "hook-pandas.py"...
70787 INFO: Loading module hook "hook-PIL.Image.py"...
71389 INFO: Loading module hook "hook-PIL.py"...
71398 INFO: Excluding import 'PyQt5'
71425 INFO:   Removing import of PyQt5 from module PIL.ImageQt
71452 INFO: Excluding import 'PyQt4'
71491 INFO: Import to be excluded not found: 'FixTk'
71516 INFO: Excluding import 'tkinter'
71558 INFO:   Removing import of tkinter from module PIL.ImageTk
71583 INFO: Excluding import 'PySide'
71626 INFO: Loading module hook "hook-PIL.SpiderImagePlugin.py"...
71661 INFO: Excluding import 'tkinter'
71694 INFO: Import to be excluded not found: 'FixTk'
71719 INFO: Loading module hook "hook-pkg_resources.py"...
72388 INFO: Processing pre-safe import module hook   win32com
73076 INFO: Excluding import '__main__'
73082 INFO:   Removing import of __main__ from module pkg_resources
73109 INFO: Loading module hook "hook-pydoc.py"...
73135 INFO: Loading module hook "hook-pygments.py"...
76203 INFO: Loading module hook "hook-pythoncom.py"...
76821 INFO: Loading module hook "hook-pytz.py"...
76942 INFO: Loading module hook "hook-pywintypes.py"...
77544 INFO: Loading module hook "hook-scipy.linalg.py"...
77547 INFO: Loading module hook "hook-scipy.py"...
77588 INFO: Loading module hook "hook-scipy.sparse.csgraph.py"...
77621 INFO: Loading module hook "hook-scipy.special._ellip_harm_2.py"...
77652 INFO: Loading module hook "hook-scipy.special._ufuncs.py"...
77687 INFO: Loading module hook "hook-setuptools.py"...
78862 INFO: Loading module hook "hook-sqlite3.py"...
79012 INFO: Loading module hook "hook-sysconfig.py"...
79014 INFO: Loading module hook "hook-ttkthemes.py"...
79567 INFO: Loading module hook "hook-win32com.py"...
80368 INFO: Loading module hook "hook-xml.dom.domreg.py"...
80369 INFO: Loading module hook "hook-xml.etree.cElementTree.py"...
80401 INFO: Loading module hook "hook-xml.py"...
80435 INFO: Loading module hook "hook-zmq.py"...
80970 INFO: Loading module hook "hook-_tkinter.py"...
81232 INFO: checking Tree
81233 INFO: Building Tree because Tree-00.toc is non existent
81271 INFO: Building Tree Tree-00.toc
81416 INFO: checking Tree
81417 INFO: Building Tree because Tree-01.toc is non existent
81450 INFO: Building Tree Tree-01.toc
81872 INFO: Looking for ctypes DLLs
82072 INFO: Analyzing run-time hooks ...
82111 INFO: Including run-time hook 'pyi_rth_multiprocessing.py'
82116 INFO: Including run-time hook 'pyi_rth_pkgres.py'
82122 INFO: Including run-time hook 'pyi_rth_win32comgenpy.py'
82153 INFO: Including run-time hook 'pyi_rth_traitlets.py'
82188 INFO: Including run-time hook 'pyi_rth_mplconfig.py'
82221 INFO: Including run-time hook 'pyi_rth_mpldata.py'
82254 INFO: Including run-time hook 'pyi_rth__tkinter.py'
82287 INFO: Including run-time hook 'pyi_rth_certifi.py'
82401 INFO: Looking for dynamic libraries
85446 WARNING: lib not found: libzmq.cp37-win_amd64.pyd dependency of c:usersisamshahabappdatalocalprogramspythonpython37libsite-packageszmqackendcythonerror.cp37-win_amd64.pyd
85477 WARNING: lib not found: libzmq.cp37-win_amd64.pyd dependency of c:usersisamshahabappdatalocalprogramspythonpython37libsite-packageszmqackendcythonutils.cp37-win_amd64.pyd
85494 WARNING: lib not found: libzmq.cp37-win_amd64.pyd dependency of c:usersisamshahabappdatalocalprogramspythonpython37libsite-packageszmqackendcythonsocket.cp37-win_amd64.pyd
85522 WARNING: lib not found: libzmq.cp37-win_amd64.pyd dependency of c:usersisamshahabappdatalocalprogramspythonpython37libsite-packageszmqackendcython\_poll.cp37-win_amd64.pyd
85553 WARNING: lib not found: libzmq.cp37-win_amd64.pyd dependency of c:usersisamshahabappdatalocalprogramspythonpython37libsite-packageszmqackendcythonmessage.cp37-win_amd64.pyd
85578 WARNING: lib not found: libzmq.cp37-win_amd64.pyd dependency of c:usersisamshahabappdatalocalprogramspythonpython37libsite-packageszmqackendcython\_proxy_steerable.cp37-win_amd64.pyd
85609 WARNING: lib not found: libzmq.cp37-win_amd64.pyd dependency of c:usersisamshahabappdatalocalprogramspythonpython37libsite-packageszmqackendcython\_device.cp37-win_amd64.pyd
85644 WARNING: lib not found: libzmq.cp37-win_amd64.pyd dependency of c:usersisamshahabappdatalocalprogramspythonpython37libsite-packageszmqackendcython\_version.cp37-win_amd64.pyd
85672 WARNING: lib not found: libzmq.cp37-win_amd64.pyd dependency of c:usersisamshahabappdatalocalprogramspythonpython37libsite-packageszmqackendcythoncontext.cp37-win_amd64.pyd
87233 INFO: Looking for eggs
87233 INFO: Using Python library c:usersisamshahabappdatalocalprogramspythonpython37python37.dll
87267 INFO: Found binding redirects:
[]
87356 INFO: Warnings written to C:UsersisamshahabDesktopWork StuffsCoCStockStockIndexSummaryTooluildYFScrappingwarn-YFScrapping.txt
88104 INFO: Graph cross-reference written to C:UsersisamshahabDesktopWork StuffsCoCStockStockIndexSummaryTooluildYFScrappingxref-YFScrapping.html
88721 INFO: checking PYZ
88721 INFO: Building PYZ because PYZ-00.toc is non existent
88750 INFO: Building PYZ (ZlibArchive) C:UsersisamshahabDesktopWork StuffsCoCStockStockIndexSummaryTooluildYFScrappingPYZ-00.pyz
95698 INFO: Building PYZ (ZlibArchive) C:UsersisamshahabDesktopWork StuffsCoCStockStockIndexSummaryTooluildYFScrappingPYZ-00.pyz completed successfully.
95874 INFO: checking PKG
95875 INFO: Building PKG because PKG-00.toc is non existent
95913 INFO: Building PKG (CArchive) PKG-00.pkg
140236 INFO: Building PKG (CArchive) PKG-00.pkg completed successfully.
140777 INFO: Bootloader c:usersisamshahabappdatalocalprogramspythonpython37libsite-packagesPyInstallerootloaderWindows-64bit
un.exe
140777 INFO: checking EXE
140810 INFO: Building EXE because EXE-00.toc is non existent
140850 INFO: Building EXE from EXE-00.toc
140889 INFO: Appending archive to EXE C:UsersisamshahabDesktopWork StuffsCoCStockStockIndexSummaryTooldistYFScrapping.exe
141049 INFO: Building EXE from EXE-00.toc completed successfully.

下面是来自.exe文件控制台的错误消息的屏幕截图:

首先感谢您的时间和帮助。

致以最诚挚的问候, MH

推荐答案

总结如下: matplotlib要求在4个特定位置之一找到名为matplotlibrary的配置文件,第一个位置是Courant目录(参见https://matplotlib.org/tutorials/introductory/customizing.html#the-matplotlibrc-file) 根据需要准备此文件后,可以通过添加--add-data=matplotlibrary;将其嵌入到exe中。添加到生成命令(替换为:对于非Windows系统)

这篇关于Python Pyinstaller Matplotlibrary的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:Python Pyinstaller Matplotlibrary

基础教程推荐