问题描述
我正在运行以下代码:
pyinstaller --onefile main.py
main.py
看起来像:
import sys
import os
sys.path.append(r'C:\Model\Utilities')
from import_pythonpkg import *
......
import_pythonpkg.py
看起来像:
from astroML.density_estimation import EmpiricalDistribution
import calendar
import collections
from collections import Counter, OrderedDict, defaultdict
import csv
....
通过在main.py
上运行pyinstaller
,成功创建main.exe
文件.
By running the pyinstaller
on main.py
, main.exe
file is created successfully.
但是当我运行 main.exe
时,它给出了 astroML
错误.如果我将 astroML
从 import_pythonpkg.py
移动到 main.py
,astroML
就没有错误.现在,csv
出现错误.
But when I run main.exe
it gives error with astroML
. If I move astroML
to main.py
from import_pythonpkg.py
, there is no error with astroML
. Now I get error with csv
.
即如果我将 main.py
更改为:
i.e. if I change my main.py
to look as:
import sys
from astroML.density_estimation import EmpiricalDistribution
import os
sys.path.append(r'C:\Model\Utilities')
from import_pythonpkg import *
......
当我运行 main.exe
时,astroML
错误不再存在.
The astroML
error is no longer present when I run main.exe
.
import_pythonpkg.py
中的 import calendar
行完全没有错误.
There is no error with import calendar
line in import_pythonpkg.py
at all.
在运行 pyinstaller
后运行 main.exe
时,我不确定如何处理包的这个随机错误.
I am not sure how to handle this random error with packages when running main.exe
after pyinstaller
run.
import_pythonpkg
位于 r'C:\Model\Utilities'
main.exe
错误看起来如下,即使原始 main.py
运行良好.Pyinstaller 甚至可以让我毫无错误地创建 main.exe
.
Error with main.exe
looks as following even though the original main.py
runs fine. Pyinstaller was even able to let me create the main.exe
without error.
Traceback (most recent call last):
File "main.py", line 8, in <module>
File "C:\Model\Utilities\import_pythonpkg.py", line 1, in <module>
from astroML.density_estimation import EmpiricalDistribution
ImportError: No module named astroML.density_estimation
[29180] Failed to execute script main
推荐答案
即将加载到您计算机上的模块.如果您的 IDE 与您的环境不同,您必须通过 pip 在您的设备上加载相同的模块.检查 CMD 屏幕上的模块并完成缺少的模块.
It is about to module which loaeded on your computer. If your IDE is different from your environment, you have to load same modules on your device via pip. Check the modules on CMD screen and complete the missing modules.
有时您必须将模块加载到设备上的所有 IDE.就我而言,有两个 IDE(pycharm 和 anaconda).我使用了 pycharm,但 pyinstaller 使用了 anaconda 的模块,所以我卸载了 anaconda 并再次尝试.现在它可以工作了..
Sometimes you must load the modules all IDEs on your device. In my case, there were two IDEs (pycharm and anaconda). I used pycharm but pyinstaller used anaconda's modules so i unistalled anaconda and tried again. now it works..
这篇关于PyInstaller 运行良好,但 exe 文件错误:未命名模块,无法执行脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!