pyinstaller导入错误与运行

扎南

我有档案import1.py

import os
import runpy
filename = r'C:\pyinstallerTest\test.py'
runpy.run_path(filename)

文件test.py是:

import matplotlib.pyplot as plt
import numpy as np
from astroML import *
from tkinter import *

t = np.arange(0.0, 2.0, 0.01)
s = 1 + np.sin(2*np.pi*t)
plt.plot(t, s)

plt.xlabel('time (s)')
plt.ylabel('voltage (mV)')
plt.title('About as simple as it gets, folks')
plt.grid(True)
plt.savefig(r"C:\pyinstallerTest\test.png")
plt.show()
print('hello world')

我尝试了以下命令从import1.py创建exe文件

pyinstaller --onefile import1.py

import1.exe文件创建成功。但是,当我运行import1.exe文件时,出现以下错误:

Traceback (most recent call last):
  File "import1.py", line 4, in <module>
  File "runpy.py", line 263, in run_path
  File "runpy.py", line 96, in _run_module_code
  File "runpy.py", line 85, in _run_code
  File "C:\pyinstallerTest\test.py", line 1, in <module>
    import matplotlib.pyplot as plt
ImportError: No module named 'matplotlib'
[1828] Failed to execute script import1

这对我来说是更多的学习练习,因此我在这里不是寻找其他更好的做事方式。

第四次冰人

PyInstaller没有看到,matplotlib因此在编译时将忽略它,因此在exe运行时看不到它。尝试将其添加为隐藏导入:

pyinstaller --onefile --hidden-import=modulename import1.py

无论模块名在哪里,模块名都应该是完整路径。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

运行pyinstaller应用时导入错误

在运行PyInstaller生成的二进制文件时出现模块导入错误

PyInstaller:导入geopandas时出现StopIteration错误

使用 pymeshlab 和 Pyinstaller 时导入错误

运行exe文件时出现Pyinstaller错误

Python导入错误-运行unittest

Pyinstaller:导入错误:DLL加载失败:找不到指定的模块

Pyinstaller 导入错误:DLL 加载失败:找不到指定的模块

在virtualenv中运行pytest时导入错误

Python运行Unittest作为包导入错误

运行示例游戏时,pygame导入错误

运行 tox 时导入不匹配错误

运行py.test时导入错误

PyInstaller不包括导入

Pyinstaller 无法导入 geopandas

pyinstaller在运行时导入/加载python代码,例如config.py

Pyinstaller 抛出“google.resumable media.requests 子包需要导入错误:requests> 2.18.0。”

PyInstaller生成的可执行文件中的Python SSL导入错误

Pyinstaller“导入错误:没有名为 xml.etree 的模块”

使用pyinstaller转换python脚本时出现问题。导入错误:库不兼容

pycharm项目可以在``运行''上运行,但是pyinstaller --onefile给出了与纸浆有关的错误

配置Pycharm以运行Pyinstaller

pyinstaller找不到隐藏的导入

带有相对导入的pyinstaller

PyInstaller不导入队列

Pyinstaller“无法导入站点模块”

Django项目的Pyinstaller错误“导入错误:没有名为'django.contrib.admin.apps'的模块”

使用PHP运行CSV导入MySQL时的错误处理

从终端运行单元测试时导入错误