Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 可以分发PyInstaller exe文件吗?_Python_Python 3.x_Pyinstaller - Fatal编程技术网

Python 可以分发PyInstaller exe文件吗?

Python 可以分发PyInstaller exe文件吗?,python,python-3.x,pyinstaller,Python,Python 3.x,Pyinstaller,我使用pyinstaller将一个.py文件转换为.exe,并在另一台机器(相同版本的操作系统)上复制了整个目录。当我运行它时,它会提示一些错误 developer1是开发脚本的机器,user1是我将程序分发到的机器 C:\Users\user1\Downloads\MyApp\dist\app>app.exe c:\users\developer1\appdata\local\programs\python\python38-32\lib\site-packages\PyInstalle

我使用pyinstaller将一个.py文件转换为.exe,并在另一台机器(相同版本的操作系统)上复制了整个目录。当我运行它时,它会提示一些错误

developer1
是开发脚本的机器,
user1
是我将程序分发到的机器

C:\Users\user1\Downloads\MyApp\dist\app>app.exe
c:\users\developer1\appdata\local\programs\python\python38-32\lib\site-packages\PyInstaller\loader\pyimod03_importers.py:493: MatplotlibDeprecationWarning:
The MATPLOTLIBDATA environment variable was deprecated in Matplotlib 3.1 and will be removed in 3.3.
Traceback (most recent call last):
  File "pandas\__init__.py", line 32, in <module>
  File "c:\users\developer1\appdata\local\programs\python\python38-32\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 493, in exec_module
  File "pandas\_libs\__init__.py", line 3, in <module>
  File "c:\users\developer1\appdata\local\programs\python\python38-32\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 493, in exec_module
  File "pandas\_libs\tslibs\__init__.py", line 3, in <module>
  File "pandas\_libs\tslibs\c_timestamp.pxd", line 7, in init pandas._libs.tslibs.conversion
  File "pandas\_libs\tslibs\c_timestamp.pyx", line 1, in init pandas._libs.tslibs.c_timestamp
  File "pandas\_libs\tslibs\tzconversion.pyx", line 1, in init pandas._libs.tslibs.tzconversion
  File "pandas\_libs\tslibs\timedeltas.pyx", line 1, in init pandas._libs.tslibs.timedeltas
ModuleNotFoundError: No module named 'pandas._libs.tslibs.offsets'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "app.py", line 6, in <module>
  File "c:\users\developer1\appdata\local\programs\python\python38-32\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 493, in exec_module
  File "pandas\__init__.py", line 36, in <module>
ImportError: C extension: No module named 'pandas._libs.tslibs.offsets' not built. If you want to import pandas from the source directory, you may need to run 'python setup.py build_ext --inplace --force' to build the C extensions first.
[10460] Failed to execute script app
我需要担心
pathex
是开发人员机器的路径吗

更新:

  • 是,可以分发pyinstaller exe文件
  • 大多数
    modulenofounderror
    可以通过使用回答中提到的
    --hiddenimport
    来解决
  • 无需担心pathex与用户路径不同

  • 键入
    pyinstaller app.py--hiddenimport=pandas.\u libs.tslibs.offset
    在构建应用程序时

    因为你发布了规范文件。。。您可以将其放入,只需使用
    pyinstaller app.spec

    a = Analysis(['app.py'],
             pathex=['C:\\Users\\developer1\\App1'],
             binaries=[],
             datas=[],
             hiddenimports=['pandas._libs.tslibs.offsets'],
             hookspath=[],
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher,
             noarchive=False)
    

    .spec文件中可能缺少“hiddenimports”。您使用的是“一个目录”模式还是“单个文件”模式?您正在键入哪一行来构建pyinstaller应用程序?user1不需要安装python,pathx是特定于开发人员机器的。Pyinstaller构建应用程序确实意味着易于分发。此外,您应该检查是否在app.py模块中导入了熊猫。Pyinstaller通过导入推断包中包含哪些包。此外,您还应该明确使用virtual envsjust basic
    pyinstaller app.py
    ,默认情况下,它只有一个目录模式add--hiddenimport=pandas.\u libs.tslibs。offsets@b0lleb我不太明白你的意思,你是想问我是否在py脚本中导入了熊猫?如果问题是这样的,是的,我确实导入了脚本中的所有模块,并且脚本工作得很好。是否可以解释为什么熊猫模块只有此错误,而没有其他模块,如matplotlib?正如b0lle所说,pyinstaller尽其所能找到代码使用的“导入”内容。由于pandas在其代码中使用了一个额外的库(一个C库,而不是python),pyinstaller很难自动找到它。pyinstaller的管理人员在幕后对许多库(PyQt、MatPlotlib、tkinter、许多pandas)的发现进行硬编码方面做得非常好,但一些库却在不知不觉中溜走了
    a = Analysis(['app.py'],
             pathex=['C:\\Users\\developer1\\App1'],
             binaries=[],
             datas=[],
             hiddenimports=['pandas._libs.tslibs.offsets'],
             hookspath=[],
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher,
             noarchive=False)