Python Pyinstaller Matplotlibrc

2024-09-29 19:24:23 发布

您现在位置:Python中文网/ 问答频道 /正文

尊敬的万维网python专家:

我真的很想在这个问题上得到帮助,我与pyinstaller

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

py文件上有tkinter库,用于简单的GUI,其余的只是使用numpy、pandas库和matplotlib fr数据可视化的数据分析。此外,还有一个yfinance库可以从雅虎财经网站上获取股票数据。该程序的输出只是所选股票指数matplotlib图的pdf文件

我可以在IDLE或jupyter笔记本中很好地运行这段python代码

但当我将其转换为可执行文件时,程序不会加载,在控制台中,我收到以下错误消息:

运行时错误:找不到matplotlibrc文件;您的matplotlib安装已中断

我曾尝试将matplotlib软件包重新安装到不同的版本,如3.0、3.1.3等,但最后出现了相同的运行时错误消息

你能告诉我出了什么问题以及如何克服这个问题吗

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

C:\Users\isamshahab\Desktop\Work Stuffs\CoC\Stock\StockIndexSummaryTool>pyinstaller--onefile YFScrapping.py
'pyinstaller--onefile' is not recognized as an internal or external command,
operable program or batch file.

C:\Users\isamshahab\Desktop\Work Stuffs\CoC\Stock\StockIndexSummaryTool>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:\Users\isamshahab\Desktop\Work Stuffs\CoC\Stock\StockIndexSummaryTool\YFScrapping.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:\users\isamshahab\appdata\local\programs\python\python37\python.exe
6047 INFO: Analyzing C:\Users\isamshahab\Desktop\Work Stuffs\CoC\Stock\StockIndexSummaryTool\YFScrapping.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:\users\isamshahab\appdata\local\programs\python\python37\lib\site-packages\matplotlib\__init__.py", line 1015, in <module>
    rcParams = rc_params()
  File "c:\users\isamshahab\appdata\local\programs\python\python37\lib\site-packages\matplotlib\__init__.py", line 878, in rc_params
    return rc_params_from_file(matplotlib_fname(), fail_on_error)
  File "c:\users\isamshahab\appdata\local\programs\python\python37\lib\site-packages\matplotlib\__init__.py", line 731, in matplotlib_fname
    for fname in gen_candidates():
  File "c:\users\isamshahab\appdata\local\programs\python\python37\lib\site-packages\matplotlib\__init__.py", line 728, in gen_candidates
    yield os.path.join(get_configdir(), 'matplotlibrc')
  File "c:\users\isamshahab\appdata\local\programs\python\python37\lib\site-packages\matplotlib\__init__.py", line 276, in wrapper
    ret = func(**kwargs)
  File "c:\users\isamshahab\appdata\local\programs\python\python37\lib\site-packages\matplotlib\__init__.py", line 609, in get_configdir
    return _get_config_or_cache_dir(_get_xdg_config_dir())
  File "c:\users\isamshahab\appdata\local\programs\python\python37\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'
66344 INFO: Loading module hook "hook-matplotlib.py"...
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "c:\users\isamshahab\appdata\local\programs\python\python37\lib\site-packages\matplotlib\__init__.py", line 1015, in <module>
    rcParams = rc_params()
  File "c:\users\isamshahab\appdata\local\programs\python\python37\lib\site-packages\matplotlib\__init__.py", line 878, in rc_params
    return rc_params_from_file(matplotlib_fname(), fail_on_error)
  File "c:\users\isamshahab\appdata\local\programs\python\python37\lib\site-packages\matplotlib\__init__.py", line 731, in matplotlib_fname
    for fname in gen_candidates():
  File "c:\users\isamshahab\appdata\local\programs\python\python37\lib\site-packages\matplotlib\__init__.py", line 728, in gen_candidates
    yield os.path.join(get_configdir(), 'matplotlibrc')
  File "c:\users\isamshahab\appdata\local\programs\python\python37\lib\site-packages\matplotlib\__init__.py", line 276, in wrapper
    ret = func(**kwargs)
  File "c:\users\isamshahab\appdata\local\programs\python\python37\lib\site-packages\matplotlib\__init__.py", line 609, in get_configdir
    return _get_config_or_cache_dir(_get_xdg_config_dir())
  File "c:\users\isamshahab\appdata\local\programs\python\python37\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'
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:\users\isamshahab\appdata\local\programs\python\python37\lib\site-packages\zmq\backend\cython\error.cp37-win_amd64.pyd
85477 WARNING: lib not found: libzmq.cp37-win_amd64.pyd dependency of c:\users\isamshahab\appdata\local\programs\python\python37\lib\site-packages\zmq\backend\cython\utils.cp37-win_amd64.pyd
85494 WARNING: lib not found: libzmq.cp37-win_amd64.pyd dependency of c:\users\isamshahab\appdata\local\programs\python\python37\lib\site-packages\zmq\backend\cython\socket.cp37-win_amd64.pyd
85522 WARNING: lib not found: libzmq.cp37-win_amd64.pyd dependency of c:\users\isamshahab\appdata\local\programs\python\python37\lib\site-packages\zmq\backend\cython\_poll.cp37-win_amd64.pyd
85553 WARNING: lib not found: libzmq.cp37-win_amd64.pyd dependency of c:\users\isamshahab\appdata\local\programs\python\python37\lib\site-packages\zmq\backend\cython\message.cp37-win_amd64.pyd
85578 WARNING: lib not found: libzmq.cp37-win_amd64.pyd dependency of c:\users\isamshahab\appdata\local\programs\python\python37\lib\site-packages\zmq\backend\cython\_proxy_steerable.cp37-win_amd64.pyd
85609 WARNING: lib not found: libzmq.cp37-win_amd64.pyd dependency of c:\users\isamshahab\appdata\local\programs\python\python37\lib\site-packages\zmq\backend\cython\_device.cp37-win_amd64.pyd
85644 WARNING: lib not found: libzmq.cp37-win_amd64.pyd dependency of c:\users\isamshahab\appdata\local\programs\python\python37\lib\site-packages\zmq\backend\cython\_version.cp37-win_amd64.pyd
85672 WARNING: lib not found: libzmq.cp37-win_amd64.pyd dependency of c:\users\isamshahab\appdata\local\programs\python\python37\lib\site-packages\zmq\backend\cython\context.cp37-win_amd64.pyd
87233 INFO: Looking for eggs
87233 INFO: Using Python library c:\users\isamshahab\appdata\local\programs\python\python37\python37.dll
87267 INFO: Found binding redirects:
[]
87356 INFO: Warnings written to C:\Users\isamshahab\Desktop\Work Stuffs\CoC\Stock\StockIndexSummaryTool\build\YFScrapping\warn-YFScrapping.txt
88104 INFO: Graph cross-reference written to C:\Users\isamshahab\Desktop\Work Stuffs\CoC\Stock\StockIndexSummaryTool\build\YFScrapping\xref-YFScrapping.html
88721 INFO: checking PYZ
88721 INFO: Building PYZ because PYZ-00.toc is non existent
88750 INFO: Building PYZ (ZlibArchive) C:\Users\isamshahab\Desktop\Work Stuffs\CoC\Stock\StockIndexSummaryTool\build\YFScrapping\PYZ-00.pyz
95698 INFO: Building PYZ (ZlibArchive) C:\Users\isamshahab\Desktop\Work Stuffs\CoC\Stock\StockIndexSummaryTool\build\YFScrapping\PYZ-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:\users\isamshahab\appdata\local\programs\python\python37\lib\site-packages\PyInstaller\bootloader\Windows-64bit\run.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:\Users\isamshahab\Desktop\Work Stuffs\CoC\Stock\StockIndexSummaryTool\dist\YFScrapping.exe
141049 INFO: Building EXE from EXE-00.toc completed successfully.

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

enter image description here

首先感谢您的时间和帮助

致以最良好的祝愿, MH


Tags: pyimportinfomatplotlibliblocalsitehook
2条回答

确保您在安装PySturier-Eng><强>之前使用的 >(VcLeReDist.x64 .exe),您可以构建可执行文件。 见Error after using PyInstaller for script with Matplotlib

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

相关问题 更多 >

    热门问题