python - 即使已安装,导入 matplotlib 也会出错
问题描述
我希望有人可以帮助我。
系统是 MacOS Catalina。Python 3.8 集成开发环境: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 脚本python your_file.py
,尝试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
命令
推荐阅读
- verilog - 何时在 SystemVerilog 中使用 `include
- vba - 如何使用 VBA 在 Powerpoint 中设置音频的启动选项
- reactjs - 如何模拟使用 Axios 进行的 API 调用?
- python - 如何使用 Tkinter 进行实时数据库更新
- python - 如果出现重复符号,如何选择要拆分的符号
- python - 根据试验数据绘制概率曲线
- html - 赛普拉斯:如何测试 HTML5 内置的验证弹出窗口?
- asp.net - 弹出窗口打开时禁用父页面
- sql - Querydsl-jpa 中的对象聚合
- java - 是否有一种自动方法可以将 json 有效负载反序列化为没有 POJO 的通用 JsonObject?