简体   繁体   English

VS 代码无法识别我在 Mac 上安装的 Python package

[英]VS code not recognize the Python package I installed on my Mac

I tried to run a python script file on Visual Studio.我尝试在 Visual Studio 上运行 python 脚本文件。 But the terminal keep pop up saying that I don't have the package installed... I don't know what is going on.但是终端不断弹出说我没有安装 package ......我不知道发生了什么。 I installed Python through homebrew and install all the package through pip3.我通过自制软件安装了 Python 并通过 pip3 安装了所有 package。 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? 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.. . 我什至创建了一个新的 py 文件来运行 pandas,它工作了.. 有人可以帮我吗? This is driving me crazy..这真让我抓狂.. 在此处输入图像描述 在此处输入图像描述

If you installed python via homebrew try using homebrew to install pandas instead of pip.如果您通过自制软件安装了 python,请尝试使用自制软件安装 pandas 而不是 pip。 I've seen things before that they get linked.我以前见过他们联系在一起的事情。 I would just recommend using pip to uninstall pandas first so there is only package.我只建议先使用 pip 卸载 pandas,所以只有 package。

It just because you had chosen the wrong python environment in VSCode.只是因为您在 VSCode 中选择了错误的 python 环境。

You said you had created a python file to run pandas and it worked.你说你已经创建了一个 python 文件来运行 pandas 并且它有效。 This means you had installed the package 'pandas' and it worked.这意味着您已经安装了 package 'pandas' 并且它工作正常。 But you haven't chosen this environment in your VSCode.但是你还没有在你的 VSCode 中选择这个环境。

In the terminal:在终端:

By command "pip3 --version" to check which pip you are using.通过命令“pip3 --version”检查您使用的是哪个 pip。

By command "python3" -> "import sys; sys.executable" to check which python you are using.通过命令 "python3" -> "import sys; sys.executable" 检查您使用的是哪个 python。

By command "python3" -> "import sys; sys.path" to check which 'site-package' the interpreter searching for.通过命令 "python3" -> "import sys; sys.path" 来检查解释器正在搜索哪个 'site-package'。

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'.根据您的描述,您使用的 pip 在“/usr/local”下,使用“/usr/local/bin”的 python 解释器在“/usr/local/lib/python3.7/site-packages”下安装软件包/蟒蛇3'。 This is the default python interpreter because of the system environment variables settings.由于系统环境变量设置,这是默认的 python 解释器。 But in VSCode you haven't chosen this environment.但是在 VSCode 中你没有选择这个环境。

Solution:解决方案:

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.激活环境(Ctrl+Shift+`),通过命令“pip3 --version”检查您使用的是哪个pip3,然后安装您要导入的package。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 python 3.2 已安装,但 MAC 无法识别 - python 3.2 installed, but MAC didn't recognize it 有没有办法让新安装的Python 3识别我在使用Python 2时安装的所有库? - Is there a way to get my newly installed Python 3 to recognize all of the libraries I had installed when I was using Python 2? 为什么我的 VS Code 无法将“python”识别为内部或外部命令 - Why does my VS Code not recognize 'python' as an internal or external command 如何从 VS Code 的 Python Extension 切换到我电脑上安装的 Python? - How do I switch from VS Code's Python Extention to the Python installed on my computer? 如何在 Mac 上使用 VS 代码在 python 中安装 openpyxl package - How to install openpyxl package in python using VS code on Mac 如何设置我的路径,以便它与作为 package 本地安装的 Python 代码一起使用 - How can I set my path so that it works with Python code that is locally installed as a package 我的Mac上安装了多个Python副本吗? - Do i have multiple copies of Python installed on my Mac? vsc python 调试器和 pylance 无法识别已安装的包 - vsc python debugger and pylance doesn't recognize installed package 如何在VS代码中找到新安装的python模块? - How can I find newly installed python module in VS code? Pylint 无法识别我在 VS Code 上的 Python 导入,但代码运行时没有任何错误 - Pylint doesn't recognize my Python imports on VS Code, but the code runs without any error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM