我在xubunutu和python 2.7和3.6.7上有vscode。我也用python 3.6.7制作了一个virtualenv。在python 3和virtualenv我安装了matplotlib。但是,当我导入matplotlib并运行代码时,我收到导入错误。更确定的是,我已经检查了终端中的导入,这没关系。由于我没有在python2.7中安装matplotlib,似乎vscode仍然没有使用python3,尽管在底部显示了python3.6.7。
在ctrl + shift + p之后的vscode中,我选择解释器,并将setting.json中的路径更改为相应的地址。例如对于python 3:
{
"python.pythonPath": "/usr/bin/python3"
}
并为我的virtualenv命名为“测试”:
{
"python.pythonPath": "/home/joudy/test/bin/python"
}
您是否检查过状态栏(位于左下角)是否显示您尝试使用的正确解释器/环境? (image of the status bar)
如果没有,请关注如何在VS Code中使用python环境的official guide。