2017-04-09 196 views
1

我正在使用pyzo来运行我的python脚本。但是我觉得需要切换到Atom代码编辑器。我可以运行我的Python脚本没有任何问题。在原子编辑器中导入matplotlib.pyplot

在某一点上,我需要使用库matplotlib。在pyzo我会做:

import matplotlib.pyplot as plt 

但它不能在凌动工作 enter image description here

错误消息:

Traceback (most recent call last): File "C:\Users\ivanl\Desktop\python trade\matplotlib.py", line 1, in import matplotlib.pyplot as plt File "C:\Users\ivanl\Desktop\python trade\matplotlib.py", line 1, in import matplotlib.pyplot as plt ImportError: No module named 'matplotlib.pyplot'; 'matplotlib' is not a package

我应该到什么地方安装matplotlib?为什么它在pyzo而不是在原子上工作?

回答

2

The Module Search Path

When a module named spam is imported, the interpreter first searches for a built-in module with that name. If not found, it then searches for a file named spam.py in a list of directories given by the variable sys.path . sys.path is initialized from these locations:

  • the directory containing the input script (or the current directory).
  • PYTHONPATH (a list of directory names, with the same syntax as the shell variable PATH).
  • the installation-dependent default.

这意味着你应该避免使用相同的名称作为标准库或命名你的模块内置模块名称。

所以你应该重命名你的脚本文件,而不是matplotlib.py

+0

那很快。非常感谢麦格雷迪! – Ivan