我有文件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 1.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对我来说,这是更多的学习练习,所以我不想在这里寻找其他更好的方法。
发布于 2017-10-25 12:31:08
PyInstaller没有看到matplotlib,所以它在编译时忽略它,因此在运行exe时看不到它。尝试将其添加为隐藏的导入:
pyinstaller --onefile --hidden-import=modulename import1.py模块名应该是它所在位置的完整路径。
https://stackoverflow.com/questions/46931743
复制相似问题