簡體   English   中英

即使已安裝,導入 matplotlib 也會出錯

[英]Importing matplotlib gives error even though installed

我希望有人可以幫助我。

系統是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'

我已經嘗試搜索不同的解決方案來源,但我現在被卡住了。

您主要使用命令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作為命令

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM