简体   繁体   English

在另一台机器上运行可执行文件时,PyInstaller 错误加载 Python DLL

[英]PyInstaller error loading Python DLL when running executable on another machine

I'm trying to run a pyinstaller-built executable on another machine.我正在尝试在另一台机器上运行 pyinstaller 构建的可执行文件。 The error I see is Error loading Python DLL 'C:\Users\User\AppData\Local\Temp\_MEI70722\python39.dll我看到的错误是Error loading Python DLL 'C:\Users\User\AppData\Local\Temp\_MEI70722\python39.dll

I built the program like this, I also added -F to make sure the executable is standalone:我像这样构建了程序,我还添加了-F以确保可执行文件是独立的:

py -m PyInstaller script.py -F

I tried adding --add-binary and --add-data options with the path to python39.dll , but that didn't help.我尝试在python39.dll的路径中添加--add-binary--add-data选项,但这没有帮助。

The program is built on Windows 10 x64 , the machine I'm trying to run the program on is Windows 7 x64 .该程序建立在Windows 10 x64上,我尝试运行该程序的机器是Windows 7 x64 Even with such a difference and the fact that Python 3.9 is not for Windows 7, I really doubt this is the reason, otherwise I would expect another error.即使有这样的差异,而且Python 3.9不适用于 Windows 7,我真的怀疑这是不是这个原因,否则我会期待另一个错误。

What am I doing wrong?我究竟做错了什么?

Ok so here's solution that worked for me:好的,这是对我有用的解决方案:

  1. Install a Windows7-compatible version of python3.安装兼容 Windows7 的 python3 版本。 I did this from the Windows Store, which made it accessible in my command line as "python3."我是从 Windows 商店执行此操作的,这使得它可以在我的命令行中以“python3”的形式访问。

  2. Set up a virtual environment with your downgraded version of python.使用 python 的降级版本设置虚拟环境。 On command line, that's在命令行上,那是

    ...> python3 -m venv my_env ...> python3 -m venv my_env

  3. In command line, navigate to your newly created environment directory, and use pip to re-install pyinstaller in your new environment:在命令行中,导航到新创建的环境目录,然后使用 pip 在新环境中重新安装 pyinstaller:

    ...> cd my_env ...> cd my_env

    ...\my_env> pip install pyinstaller ...\my_env> pip 安装 pyinstaller

  4. From command line in my_env, use pyinstaller to compile your code.从 my_env 中的命令行,使用 pyinstaller 编译您的代码。 You should probably move script.py into your my_env directory.您可能应该将 script.py 移动到您的 my_env 目录中。

    ...\my_env> pyinstaller script.py -F ...\my_env> pyinstaller script.py -F

I was able to copy the standalone script created in \my_env onto a Windows 7 machine and run it successfully.我能够将在 \my_env 中创建的独立脚本复制到 Windows 7 机器上并成功运行。 Hope this helps!希望这可以帮助!

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

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