VS 代码无法识别我在 Mac 上安装的 Python 包 [英] VS code not recognize the Python package I installed on my Mac

查看:66
本文介绍了VS 代码无法识别我在 Mac 上安装的 Python 包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在 Visual Studio 上运行 python 脚本文件.但是终端一直弹出说我没有安装软件包......我不知道发生了什么.我通过自制软件安装了 Python,并通过 pip3 安装了所有软件包.我什至找到了我安装的所有软件包的路径,但它仍然无法正常工作..我在多个解释器之间切换,但没有一个工作,都说我的软件包未安装..但很明显我的软件包已安装... 我什至创建了一个新的 py 文件来运行 Pandas,它起作用了.. 有人可以帮我吗?这让我发疯..

I tried to run a python script file on Visual Studio. But the terminal keep pop up saying that I don't have the package installed... I don't know what is going on. I installed Python through homebrew and install all the package through pip3. I even find the path for all the package I have installed, and it's still not working.. I switched between multiple interpreter, and none of them worked, all said my package is not installed.. but it's clearly my package is installed... I even create a new py file to run pandas, and it worked.. Can someone help me with this? This is driving me crazy..

推荐答案

这只是因为你在 VSCode 中选择了错误的 Python 环境.

It just because you had chosen the wrong python environment in VSCode.

你说你已经创建了一个 python 文件来运行 Pandas 并且它工作正常.这意味着您已经安装了pandas"包并且它可以工作.但是你在你的 VSCode 中并没有选择这个环境.

You said you had created a python file to run pandas and it worked. This means you had installed the package 'pandas' and it worked. But you haven't chosen this environment in your VSCode.

在终端中:

通过命令pip3 --version";检查您使用的是哪个 pip.

By command "pip3 --version" to check which pip you are using.

通过命令python3"->"导入系统;sys.executable"检查您使用的是哪个python.

By command "python3" -> "import sys; sys.executable" to check which python you are using.

通过命令python3"->"导入系统;sys.path"检查解释器搜索的是哪个站点包".

By command "python3" -> "import sys; sys.path" to check which 'site-package' the interpreter searching for.

根据您的描述,您使用的是/usr/local"下的pip,使用/usr/local"的python解释器安装/usr/local/lib/python3.7/site-packages"下的包本地/bin/python3'.由于系统环境变量设置,这是默认的 python 解释器.但是在 VSCode 中你并没有选择这个环境.

From your description, you are using the pip which under '/usr/local', install the packages under '/usr/local/lib/python3.7/site-packages', using python interpreter of '/usr/local/bin/python3'. This is the default python interpreter because of the system environment variables settings. But in VSCode you haven't chosen this environment.

解决方案:

选择环境或创建虚拟环境(推荐).激活环境(Ctrl+Shift+`),通过命令'pip3 --version'查看你使用的是哪个pip3,然后安装你要导入的包.

Choose an environment or create a virtual environment(recommend). Activate the environment(Ctrl+Shift+`), by the command 'pip3 --version' to check which pip3 you are using, then install the package you want to import.

这篇关于VS 代码无法识别我在 Mac 上安装的 Python 包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆