Why does it keep saying ImportError: No module named pydot when I have already installed the module through pip?

Why does it keep saying ImportError: No module named pydot when I have already installed the module through pip?

我使用命令 pip install pydot 安装模块 pydot 但每当我尝试通过终端 运行 某个文件时它会提示以下错误。

Traceback (most recent call last):
  File "src/parser.py", line 3, in <module>
    import pydot
ImportError: No module named pydot

我进行了无休止的检查以确保它已正确安装。我确实在 python 文件夹中检查过它,确实存在。

有人知道我错过了什么吗?它的安装方式有问题吗?

我使用的是 macOS。

非常感谢!

首先,检查模块的安装位置(在控制台中键入以下内容):

pip show numpy

这returns以下对我来说(Macbook):

Name: numpy
Version: 1.14.0
Summary: NumPy: array processing for numbers, strings, records, and objects.
Home-page: http://www.numpy.org
Author: NumPy Developers
Author-email: numpy-discussion@python.org
License: BSD
Location: /Users/lab/miniconda2/lib/python2.7/site-packages
Requires:
Required-by: tensorly, tensorflow, tensorflow-tensorboard, scipy, patsy, pandas, nitime, nipype, mxnet, matplotlib, Keras, h5py

您可以看到位置字段:

Location: /Users/lab/miniconda2/lib/python2.7/site-packages

这意味着要使其 运行 正确,我需要使用:

python2 myscript.py

如果你想使用python 3.然后使用

pip3 install pydot

然后

python3 myscript.py