2017-04-09 199 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