简体   繁体   English

在Atom编辑器中导入matplotlib.pyplot

[英]Importing matplotlib.pyplot in atom editor

I am using pyzo to run my python scripts. 我正在使用pyzo运行我的python脚本。 However I felt the need to switch over to the Atom code editor. 但是我觉得有必要切换到Atom代码编辑器。 I can run my python scripts without any problem. 我可以毫无问题地运行我的python脚本。

At one point I need to use the library matplotlib . 有一点我需要使用库matplotlib In pyzo I would do: 在pyzo中,我会做:

import matplotlib.pyplot as plt

But it doesn't work in Atom 但这在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'; 追溯(最近一次通话):文件“ C:\\ Users \\ ivanl \\ Desktop \\ python trade \\ matplotlib.py”,行1,在导入matplotlib.pyplot中作为plt文件“ C:\\ Users \\ ivanl \\ Desktop \\ python trade” \\ matplotlib.py“,第1行,在导入matplotlib.pyplot中作为plt ImportError:没有名为'matplotlib.pyplot'的模块; 'matplotlib' is not a package 'matplotlib'不是软件包

Where should I look for installing matplotlib? 我应该在哪里寻找安装matplotlib的地方? Why is it working on pyzo and not on atom? 为什么在pyzo而不是原子上起作用?

From The Module Search Path . 模块搜索路径

When a module named spam is imported, the interpreter first searches for a built-in module with that name. 导入名为spam的模块时,解释器首先搜索具有该名称的内置模块。 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给出的目录列表中搜索名为spam.py的文件。 sys.path is initialized from these locations: sys.path从以下位置初始化:

  • 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). PYTHONPATH (目录名称列表,语法与shell变量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 . 因此,您应该重命名脚本文件而不是matplotlib.py

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM