为什么在导入模块时python给我一个错误?

时间:2019-12-29 15:39:15

标签: python import visual-studio-code

我今天安装了Python 3.8.1(几个月前我安装了3.7。*,但是现在不再使用它了),我尝试编写新代码,但是在导入类似matplotlib之类的模块时遇到了问题。它将始终将模块名称标记为黄色,并说:

  

未解决的导入“ matplotlib” Python(未解决的导入)

我检查了python是否包含在PATH中,我安装/重新安装了matplotlib模块,但没有任何效果。我正在使用Win 10 64位,Python 3.8.1 64位和VS代码。

3 个答案:

答案 0 :(得分:0)

最好的方法是在virtualenv中,看看this

python3.8 -m venv env-name # this will create a folder with executables of python, pip.

要激活它,您可以运行

source env-name/bin/activate # Linux/Mac
env\Scripts\activate.bat # For windows
pip install matplotlib # Matplotlib will be installed for the activated env only

答案 1 :(得分:0)

我通过卸载python并从python删除所有现有文件并安装了最新版本python的新的干净版本来解决了该问题。之后,我使用pip安装了所有必需的模块以进行编码。

感谢您的帮助!

答案 2 :(得分:0)

您还可以在管理模式下的cmd中使用以下命令:

python -m pip install matplotlib

如果您在安装python之后在命令提示符下运行它。