我有plot_file.py,它有:
import matplotlib.pyplot as plt
def plot_graph():
squares = [1, 4, 9, 16, 25]
plt.plot(squares)
plt.savefig('static/img/sqaure_plot.png', bbox_inches='tight')
当我运行这个,它的工作和保存文件正确。我正在Django的同一个app文件夹中的views.py中导入此函数
当我将import语句放入views.py
from myapp.plot_file import plot_graph as pg
保存并尝试从终端启动runserver,我得到:
ModuleNotFoundError: No module named 'matplotlib'
两个文件都在同一个文件夹中
myapp/plot_file.py
myapp/views.py
我已经使用pip3 install matplotlib安装了matplotlib。我正在使用MacOS和后来安装的python3。我使用的是在Python3上编译的崇高文本
我不明白如何在plot\u file.py而不是views.py文件中导入matplotlib
我是初学者。先谢谢你
应该是
或者
并确保在
myapp
文件夹中有__init__.py
文件相关问题 更多 >
编程相关推荐