即使安装,导入matplotlib也会出现错误

时间:2020-03-26 13:01:44

标签: python python-3.x matplotlib

我希望有人能帮助我。

系统是MacOS Catalina。 Python 3.8 IDE:VS

我使用pip install matplotlib安装了matplotlib,我发现它在python2.7下卡住了。我卸载了matplotlib,然后使用pip3 install matplotlib将其重新安装,并收到以下消息:

Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.7/site-packages (from matplotlib) (0.10.0)
Requirement already satisfied: numpy>=1.11 in /usr/local/lib/python3.7/site-packages (from matplotlib) (1.18.1)
Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 in /usr/local/lib/python3.7/site-packages (from matplotlib) (2.4.6)
Requirement already satisfied: kiwisolver>=1.0.1 in /usr/local/lib/python3.7/site-packages (from matplotlib) (1.1.0)
Requirement already satisfied: python-dateutil>=2.1 in /usr/local/lib/python3.7/site-packages (from matplotlib) (2.8.1)
Requirement already satisfied: six in /Users/apple/Library/Python/3.7/lib/python/site-packages (from cycler>=0.10->matplotlib) (1.13.0)
Requirement already satisfied: setuptools in /usr/local/lib/python3.7/site-packages (from kiwisolver>=1.0.1->matplotlib) (46.0.0)

但是,当我尝试使用'import matplotlib'运行我的.py文件时,出现此错误:

    import matplotlib as mpl 
ModuleNotFoundError: No module named 'matplotlib'

我曾尝试从不同的来源中寻找解决方案,但现在陷入困境。

1 个答案:

答案 0 :(得分:0)

您通常使用命令python your_file.py运行python脚本,并尝试在终端中以python3 your_file.py的身份运行。 pip3在python3而非默认python2下安装软件包。

这是因为我相信您的mac终端默认情况下使用python 2.x,因此命令python使用python 2.x版本,而python3使用3.x版本可以执行文件。因此,如果要在python 2.x下安装任何软件包,请使用pip作为命令,并在python 3.x下安装软件包,请使用pip3作为命令