Python 无法让Pyinstaller使用Pandas创建单机版

Python 无法让Pyinstaller使用Pandas创建单机版,python,pandas,pyinstaller,Python,Pandas,Pyinstaller,当然,所以我的沮丧程度已经到了我必须寻求帮助的地步 我有一个单独的文件,它使用pandas读取报告并进行一些数据操作。我已经完成,并想为它创建一个独立的exe 不幸的是,当您创建可执行文件时,Pandas不能“开箱即用”,因为我得到一个错误声明:ModuleNotFounder:没有名为“Pandas”的模块 我上网查找解决方案,到目前为止,我已经完成了所有这些: 编辑了EGTReport.spec文件: # -*- mode: python ; coding: utf-8 -*- block

当然,所以我的沮丧程度已经到了我必须寻求帮助的地步

我有一个单独的文件,它使用pandas读取报告并进行一些数据操作。我已经完成,并想为它创建一个独立的exe

不幸的是,当您创建可执行文件时,Pandas不能“开箱即用”,因为我得到一个错误声明:ModuleNotFounder:没有名为“Pandas”的模块

我上网查找解决方案,到目前为止,我已经完成了所有这些:

编辑了EGTReport.spec文件:

# -*- mode: python ; coding: utf-8 -*-

block_cipher = None

def get_pandas_path():
    import pandas
    pandas_path = pandas.__path__[0]
    return pandas_path


a = Analysis(['EGTReports.py'],
         pathex=['C:\\Users\\User\\PycharmProjects\\TW2020'],
         binaries=[],
         datas=[],
         hiddenimports=[],
         hookspath=[],
         runtime_hooks=[],
         excludes=[],
         win_no_prefer_redirects=False,
         win_private_assemblies=False,
         cipher=block_cipher,
         noarchive=False)

dict_tree = Tree(get_pandas_path(), prefix='pandas', excludes=["*.pyc"])
a.datas += dict_tree
a.binaries = filter(lambda x: 'pandas' not in x[0], a.binaries)

pyz = PYZ(a.pure, a.zipped_data,
         cipher=block_cipher)
exe = EXE(pyz,
      a.scripts,
      a.binaries,
      a.zipfiles,
      a.datas,
      [],
      name='EGTReports',
      debug=False,
      bootloader_ignore_signals=False,
      strip=False,
      upx=True,
      upx_exclude=[],
      runtime_tmpdir=None,
      console=False )
然后我在熊猫钩上添加了以下内容:

#-----------------------------------------------------------------------------
# Copyright (c) 2017-2019, PyInstaller Development Team.
#
# Distributed under the terms of the GNU General Public License with exception
# for distributing bootloader.
#
# The full license is in the file COPYING.txt, distributed with this software.
#-----------------------------------------------------------------------------

from PyInstaller.utils.hooks import collect_submodules

# Pandas keeps Python extensions loaded with dynamic imports here.
hiddenimports = collect_submodules('pandas._libs')

hiddenimports = ['pandas._libs.tslibs.timedeltas',
                         'pandas._libs.tslibs.nattype',
                         'pandas._libs.tslibs.np_datetime',
                         'pandas._libs.skiplist']
然后将cmd打开到包含我的脚本和rand的目录中:

pyinstaller --onefile EGTReports.spec
产生了这个日志:

130 INFO: PyInstaller: 3.5
130 INFO: Python: 3.7.3
130 INFO: Platform: Windows-10-10.0.18362-SP0
140 INFO: UPX is not available.
150 INFO: Extending PYTHONPATH with paths
['C:\\Users\\User\\PycharmProjects\\TW2020',
 'C:\\Users\\User\\PycharmProjects\\TW2020']
150 INFO: checking Analysis
185 INFO: Building because inputs changed
185 INFO: Initializing module dependency graph...
189 INFO: Initializing module graph hooks...
189 INFO: Analyzing base_library.zip ...
6031 INFO: running Analysis Analysis-00.toc
6031 INFO: Adding Microsoft.Windows.Common-Controls to dependent assemblies of final executable
required by c:\users\user\appdata\local\programs\python\python37-32\python.exe
8509 INFO: Caching module hooks...
8534 INFO: Analyzing EGTReports.py
10060 INFO: Processing pre-find module path hook   distutils
13200 INFO: Processing pre-find module path hook   site
13200 INFO: site: retargeting to fake-dir 'c:\\users\\user\\appdata\\local\\programs\\python          \\python37-32\\lib\\site-packages\\PyInstaller\\fake-modules'
16145 INFO: Processing pre-safe import module hook   setuptools.extern.six.moves
22436 INFO: Loading module hooks...
22436 INFO: Loading module hook "hook-distutils.py"...
22439 INFO: Loading module hook "hook-encodings.py"...
22585 INFO: Loading module hook "hook-lib2to3.py"...
22594 INFO: Loading module hook "hook-numpy.core.py"...
22773 INFO: Loading module hook "hook-numpy.py"...
22775 INFO: Loading module hook "hook-PIL.Image.py"...
23254 INFO: Loading module hook "hook-PIL.py"...
23254 INFO: Import to be excluded not found: 'FixTk'
23254 INFO: Excluding import 'tkinter'
23254 INFO:   Removing import of tkinter from module PIL.ImageTk
23259 INFO: Excluding import 'PySide'
23259 INFO:   Removing import of PySide from module PIL.ImageQt
23259 INFO: Excluding import 'PyQt5'
23264 INFO:   Removing import of PyQt5 from module PIL.ImageQt
23264 INFO: Excluding import 'PyQt4'
23269 INFO:   Removing import of PyQt4 from module PIL.ImageQt
23269 INFO: Loading module hook "hook-PIL.SpiderImagePlugin.py"...
23269 INFO: Import to be excluded not found: 'FixTk'
23269 INFO: Excluding import 'tkinter'
23274 INFO: Loading module hook "hook-pkg_resources.py"...
23900 INFO: Processing pre-safe import module hook   win32com
24350 INFO: Loading module hook "hook-pydoc.py"...
24350 INFO: Loading module hook "hook-pythoncom.py"...
24909 INFO: Loading module hook "hook-pywintypes.py"...
25456 INFO: Loading module hook "hook-setuptools.py"...
26609 INFO: Loading module hook "hook-sqlite3.py"...
26829 INFO: Loading module hook "hook-sysconfig.py"...
26840 INFO: Loading module hook "hook-win32com.py"...
27744 INFO: Loading module hook "hook-xml.dom.domreg.py"...
27744 INFO: Loading module hook "hook-xml.etree.cElementTree.py"...
27744 INFO: Loading module hook "hook-xml.py"...
27744 INFO: Loading module hook "hook-_tkinter.py"...
28424 INFO: checking Tree
28544 INFO: checking Tree
28739 INFO: Looking for ctypes DLLs
28800 INFO: Analyzing run-time hooks ...
28819 INFO: Including run-time hook 'pyi_rth_multiprocessing.py'
28829 INFO: Including run-time hook 'pyi_rth_pkgres.py'
28829 INFO: Including run-time hook 'pyi_rth_win32comgenpy.py'
28839 INFO: Including run-time hook 'pyi_rth__tkinter.py'
28870 INFO: Looking for dynamic libraries
50560 INFO: Looking for eggs
50560 INFO: Using Python library c:\users\user\appdata\local\programs\python\python37-32 \python37.dll
50560 INFO: Found binding redirects:
[]
50584 INFO: Warnings written to C:\Users\User\PycharmProjects\TW2020\build\EGTReports\warn-   EGTReports.txt
50860 INFO: Graph cross-reference written to C:\Users\User\PycharmProjects\TW2020\build\EGTReports\xref-EGTReports.html
Traceback (most recent call last):
File "c:\users\user\appdata\local\programs\python\python37-32\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "c:\users\user\appdata\local\programs\python\python37-32\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Users\User\AppData\Local\Programs\Python\Python37-32\Scripts\pyinstaller.exe\__main__.py", line 9, in <module>
File "c:\users\user\appdata\local\programs\python\python37-32\lib\site-packages\PyInstaller\__main__.py", line 111, in run
run_build(pyi_config, spec_file, **vars(args))
File "c:\users\user\appdata\local\programs\python\python37-32\lib\site-packages\PyInstaller\__main__.py", line 63, in run_build
PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
File "c:\users\user\appdata\local\programs\python\python37-32\lib\site-packages\PyInstaller\building\build_main.py", line 844, in main
build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))
File "c:\users\user\appdata\local\programs\python\python37-32\lib\site-packages\PyInstaller\building\build_main.py", line 791, in build
exec(code, spec_namespace)
File "EGTReports.spec", line 24, in <module>
dict_tree = Tree(get_pandas_path(), prefix='pandas', excludes=["*.pyc"])
File "EGTReports.spec", line 6, in get_pandas_path
import pandas
ModuleNotFoundError: No module named 'pandas'
130信息:PyInstaller:3.5
130信息:Python:3.7.3
130信息:平台:Windows-10-10.0.18362-SP0
140信息:UPX不可用。
150信息:使用路径扩展PYTHONPATH
['C:\\Users\\User\\pycharm项目\\TW2020',
'C:\\Users\\User\\pycharm项目\\TW2020']
150信息:检查分析
185信息:由于输入更改而生成
185信息:正在初始化模块依赖关系图。。。
189信息:正在初始化模块图挂钩。。。
189信息:正在分析base_library.zip。。。
6031信息:运行分析-00.toc
6031信息:将Microsoft.Windows.Common-Controls添加到最终可执行文件的相关程序集
c:\users\user\appdata\local\programs\python37-32\python.exe所需
8509信息:缓存模块挂钩。。。
8534信息:正在分析egtreport.py
10060信息:处理预查找模块路径挂钩区
13200信息:正在处理预查找模块路径挂钩站点
13200信息:站点:重新定位到伪目录'c:\\users\\user\\appdata\\local\\programs\\python\\python37-32\\lib\\site packages\\PyInstaller\\fake modules'
16145信息:处理预安全导入模块hook setuptools.extern.six.moves
22436信息:正在加载模块挂钩。。。
22436信息:加载模块挂钩“hook distutils.py”。。。
22439信息:加载模块钩子“hook encodings.py”。。。
22585信息:加载模块挂钩“hook-lib2to3.py”。。。
22594信息:加载模块钩子“hook numpy.core.py”。。。
22773信息:加载模块挂钩“hook numpy.py”。。。
22775信息:加载模块挂钩“hook PIL.Image.py”。。。
23254信息:加载模块钩子“hook PIL.py”。。。
23254信息:未找到要排除的导入:“FixTk”
23254信息:不包括导入“tkinter”
23254信息:正在从模块PIL.ImageTk中删除tkinter的导入
23259信息:不包括导入“PySide”
23259信息:正在从模块PIL.ImageQt中删除PySide的导入
23259信息:不包括导入“PyQt5”
23264信息:正在从模块PIL.ImageQt中删除PyQt5的导入
23264信息:不包括导入“PyQt4”
23269信息:正在从模块PIL.ImageQt中删除PyQt4的导入
23269信息:加载模块hook“hook PIL.SpiderImagePlugin.py”。。。
23269信息:未找到要排除的导入:“FixTk”
23269信息:不包括导入“tkinter”
23274信息:加载模块hook“hook-pkg_resources.py”。。。
23900信息:正在处理预安全导入模块挂钩win32com
24350信息:加载模块钩子“hook pydoc.py”。。。
24350信息:加载模块hook“hook pythoncom.py”。。。
24909信息:加载模块钩子“hook pywintypes.py”。。。
25456信息:加载模块钩子“hook setuptools.py”。。。
26609信息:加载模块钩子“hook-sqlite3.py”。。。
26829信息:正在加载模块挂钩“hook sysconfig.py”。。。
26840信息:加载模块挂钩“hook-win32com.py”。。。
27744信息:加载模块钩子“hook xml.dom.domreg.py”。。。
27744信息:加载模块钩子“hook xml.etree.celementree.py”。。。
27744信息:加载模块钩子“hook xml.py”。。。
27744信息:加载模块挂钩“挂钩-\u tkinter.py”。。。
28424信息:正在检查树
28544信息:正在检查树
28739信息:正在查找ctypes DLL
28800信息:正在分析运行时挂钩。。。
28819信息:包括运行时钩子'pyi\u rth\u multiprocessing.py'
28829信息:包括运行时钩子'pyi_rth_pkgres.py'
28829信息:包括运行时钩子'pyi_rth_win32comgenpy.py'
28839信息:包括运行时钩子'pyi_rth_utkinter.py'
28870信息:寻找动态库
50560信息:寻找鸡蛋
50560信息:使用Python库c:\users\user\appdata\local\programs\Python\python37-32\python37.dll
50560信息:找到绑定重定向:
[]
50584信息:写入C:\Users\User\PycharmProjects\TW2020\build\EGTReports\warn-EGTReports.txt的警告
50860信息:图形交叉引用写入C:\Users\User\PycharmProjects\TW2020\build\EGTReports\xref-EGTReports.html
回溯(最近一次呼叫最后一次):
文件“c:\users\user\appdata\local\programs\python 37-32\lib\runpy.py”,第193行,在运行模块中作为主
“\uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu
文件“c:\users\user\appdata\local\programs\python37-32\lib\runpy.py”,第85行,在运行代码中
exec(代码、运行\全局)
文件“C:\Users\User\AppData\Local\Programs\Python37-32\Scripts\pyinstaller.exe\ \uuuuu main\uuuuuu.py”,第9行,在
文件“c:\users\user\appdata\local\programs\python37-32\lib\site packages\PyInstaller\\uuuuuu main\uuuuuu.py”,第111行,正在运行
运行构建(pyi\u配置,规范文件,**vars(args))
文件“c:\users\user\appdata\local\programs\python37-32\lib\site packages\PyInstaller\uuuuu main\uuuuuu.py”,第63行,在run\u build中
PyInstaller.building.build\u main.main(pyi\u配置,spec\u文件,**kwargs)
文件“c:\users\user\appdata\local\programs\python37-32\lib\site packages\PyInstaller\building\build\u main.py”,第844行,在main中
构建(specfile,kw.get('distpath'),kw.get('workpath'),kw.get('clean_build'))
文件“c:\users\user\appdata\local\programs\python37-32\lib\site packages\PyInstaller\building\build\u main.py”,第791行,内部版本
exec(代码、规范和命名空间)
文件“EGTReports.spec”,第24行,在
dict_tree=tree(get_pandas_path(),前缀='pandas',排除=[“*.pyc”])
文件“EGTReports.spec”,第6行,在get\u路径中
进口大熊猫
ModuleNotFoundError:没有名为“pandas”的模块
我不知所措。。关于如何使用Pandas从python创建独立的可执行文件有什么想法吗

我真的不想搬走
setup(
    name="abcd",
    version="1.0.0",
    long_description=README,
    long_description_content_type="text/markdown",
    url="https://github.com/realpython/reader",
    author="abcd",
    author_email="abcd.com",
    license="MIT",
    classifiers=[
        "License :: OSI Approved :: MIT License",
        "Programming Language :: Python",
        "Programming Language :: Python :: 2",
        "Programming Language :: Python :: 3",
    ],
    packages=["reader"],
    include_package_data=True,
    install_requires=[
        "pandas", "html2text", "importlib_resources", "typing"
    ],
    entry_points={"console_scripts": ["abc=reader.__main__:main"]},
)