Python 没有名为“numpy”的模块:Visual Studio Code
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/40185437/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
No module named 'numpy': Visual Studio Code
提问by billboard
I'm trying to setup Visual Studio Code for python development
我正在尝试为 python 开发设置 Visual Studio Code
to begin with, I've installed
首先,我已经安装
- Anaconda Python
- Visual Studio Code
- 蟒蛇蟒
- 视觉工作室代码
and in a new file I have the following code
在一个新文件中,我有以下代码
import numpy as np
import pandas as pd
from pandas import Series, DataFrame
upon hitting Ctrl+Shift+B I get the following error
按 Ctrl+Shift+BI 后出现以下错误
import numpy as np
ImportError: No module named 'numpy'
导入错误:没有名为“numpy”的模块
Also, is there python interactive window in VS Code? How to open it.
另外,VS Code 中是否有 python 交互窗口?如何打开它。
采纳答案by user3835290
You may not have numpy installed on the version of python you are running.
您可能没有在您运行的 python 版本上安装 numpy。
Try this:
尝试这个:
import sys
print(sys.version)
导入系统
打印(系统版本)
Is the printed version Anaconda? If you installed Anaconda python, it should come with numpy already installed. If it turns out to be another version of python you are accessing inside Visual Studio Code that doesn't have numpy installed, then that's what you need to fix.
Anaconda 是印刷版吗?如果你安装了 Anaconda python,它应该已经安装了 numpy。如果结果是你在 Visual Studio Code 中访问的另一个版本的 python 没有安装 numpy,那么这就是你需要修复的。
The version of python that is called depends on which version of python comes up in your PATH variable first. Type into a terminal: echo $PATH
.
The output should look like this with Anaconda bin first:
/Users/jlzhang/anaconda/bin:/usr/local/bin:/usr/bin:/bin
调用的 python 版本取决于首先出现在 PATH 变量中的 python 版本。输入终端:echo $PATH
。首先使用 Anaconda bin 的输出应如下所示:
/Users/jlzhang/anaconda/bin:/usr/local/bin:/usr/bin:/bin
If you do not have Anaconda bin first, you can add this to your ~/.bashrc file: echo
如果您首先没有 Anaconda bin,则可以将其添加到您的 ~/.bashrc 文件中:echo
# Use Anaconda python
export PATH="/Users/jlzhang/anaconda/bin:$PATH"
# 使用蟒蛇蟒
导出路径="/Users/jlzhang/anaconda/bin:$PATH"
Restart a terminal and Visual Studio Code and see if you are now running Anaconda python.
重新启动终端和 Visual Studio Code,看看您现在是否正在运行 Anaconda python。
Hope it helps/ Did it work?
希望它有帮助/有效吗?
回答by Madhukar Reddy
Changing python environment in VS code helped me. Default the visual studio code takes original Python environment, it requires numpy to install. If you have anaconda python (mumpy come with it) installed, you could switch the original python environment to anaconda python environment in visuals studio code. This can be done from the command pallete Ctrl+Shift+P
in visual studio
在 VS 代码中更改 python 环境对我有帮助。默认visual studio代码采用原始Python环境,需要安装numpy。如果你安装了 anaconda python(mumpy 自带),你可以在 Visuals Studio 代码中将原来的 python 环境切换到 anaconda python 环境。这可以从Ctrl+Shift+P
Visual Studio 中的命令面板完成
check the link for how to switch from original python to anaconda python environment https://code.visualstudio.com/docs/python/environments
检查如何从原始 python 切换到 anaconda python 环境的链接 https://code.visualstudio.com/docs/python/environments
回答by Informitics
回答by Yanwardo Sitanggang
On my laptop, i found that there are some version of python installed (checkout picture that i inserted below)
在我的笔记本电脑上,我发现安装了一些版本的 python(我在下面插入的结帐图片)
Picture for some version of python installed
One of them is python 3.7.6 which installed together when i installed Anaconda (I installed it the day before). I assumed that it was the updated version of python. So i changed my Jupyter kernel to that version of Python. It works for me.
其中之一是 python 3.7.6,它在我安装 Anaconda 时安装在一起(我前一天安装了它)。我认为这是python的更新版本。所以我将我的 Jupyter 内核更改为该版本的 Python。这个对我有用。