Importing matplotlib.pyplot in atom editor

本秂侑毒 提交于 2019-12-11 07:27:09

问题


I am using pyzo to run my python scripts. However I felt the need to switch over to the Atom code editor. I can run my python scripts without any problem.

At one point I need to use the library matplotlib. In pyzo I would do:

import matplotlib.pyplot as plt

But it doesn't work in Atom

Error message:

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

Where should I look for installing matplotlib? Why is it working on pyzo and not on atom?


回答1:


From 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.

Which means you should avoid naming your modules with the same name as standard-library or built-in module names.

So you should rename your script file instead of matplotlib.py.



来源:https://stackoverflow.com/questions/43306980/importing-matplotlib-pyplot-in-atom-editor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!