简体   繁体   English

PyInstaller exe文件可以分发吗?

[英]Can PyInstaller exe file be distributed?

I converted a.py file to.exe using pyinstaller and made a copy of the whole directory on another machine (same version of OS).我使用 pyinstaller 将 a.py 文件转换为 .exe,并在另一台机器(相同版本的操作系统)上复制了整个目录。 What happen is that when I run it, it will prompt some errors.发生的是,当我运行它时,它会提示一些错误。

developer1 is the machine that developed the script, user1 is the machine where I distribute the program to. 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

I checked the .spec file and found out that the pathex path is actually the developer machine path, I believe this is actually causing all these errors?我检查了.spec文件,发现pathex路径实际上是开发人员机器路径,我相信这实际上是导致所有这些错误的原因吗? Is there a fix for this or the.exe is meant to be run on the developer machine only?是否有解决此问题的方法,或者 .exe 只能在开发人员机器上运行?

Just a side info:只是一个侧面信息:

  1. I did not use virtual environment when building the application, not sure if this is causing these errors.我在构建应用程序时没有使用虚拟环境,不确定这是否会导致这些错误。
  2. The user1 machine do not have python installed user1机器没有安装 python

In this .spec file在这个.spec文件中

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

Do I need bother about the pathex being the path of developer machine?我需要担心pathex是开发者机器的路径吗?

Update:更新:

  1. Yes pyinstaller exe file can be distributed是的 pyinstaller exe 文件可以分发
  2. Most ModuleNotFoundError can be solved by using --hiddenimport as mentioned in the answer accepted.大多数ModuleNotFoundError可以通过使用--hiddenimport来解决,如接受的答案中所述。
  3. There's no need to bother about the pathex being different from user path无需担心 pathex 与用户路径不同

type pyinstaller app.py --hiddenimport=pandas._libs.tslibs.offsets when building the app构建应用程序时键入pyinstaller app.py --hiddenimport=pandas._libs.tslibs.offsets

since you posted the spec file... you can put this in and just use pyinstaller app.spec既然您发布了规范文件...您可以将其放入并使用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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM