如何在macOS Catalina上的VS Code中使用pip install安装依赖项 [英] How to install dependencies using pip install in VS Code on macOS Catalina

查看:215
本文介绍了如何在macOS Catalina上的VS Code中使用pip install安装依赖项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用python3 venv venv在python 3.6.2中的VS Code上创建了一个新的虚拟环境,并使用venv/bin/activate激活了它.然后我尝试使用pip install speechrecognition安装语音识别,但是它给我一个错误,提示:

I created a new virtual environment on VS Code in python 3.6.2 using python3 venv venv and activated it using venv/bin/activate. Then I tried to install speech recognition using pip install speechrecognition but, it give me an error saying:

bash: /Users/naman/Documents/Ai Assistant/assistant/bin/pip: "/Users/naman/Documents/Ai: bad interpreter: No such file or directory

我无法在新的虚拟环境中使用pip install安装任何内容.请帮忙! 我在macOS Catalina上使用VS Code

I cannot install anything using pip install in the new virtual environment. Please Help! Im using VS Code on macOS Catalina

推荐答案

您在/Users/naman/Documents/Ai Assistant/assistant/bin/中具有Python和pip.不幸的是,该路径包含空格,而Unix(在您的情况下为MacOS X)不喜欢可执行文件路径中的空格.

You have Python and pip in /Users/naman/Documents/Ai Assistant/assistant/bin/. Unfortunately that path contains a space and Unix (MacOS X in your case) doesn't like spaces in paths to executable files.

问题是 shebang .您的pip将此作为第一行:

The problem is shebang. Your pip has this as the first line:

#!/Users/naman/Documents/Ai Assistant/assistant/bin/python

当您执行pip时,操作系统的内核会看到#!并理解它是必须与解释器一起运行的脚本.操作系统采用第一行并将其用空格分隔.这是问题所在:操作系统尝试将/Users/naman/Documents/Ai作为解释器运行,并失败了.

When you execute pip the OS' kernel sees #! and understands it's a script that has to be run with an interpreter. The OS takes the first line and split it by spaces. Here is the problem: the OS tries to run /Users/naman/Documents/Ai as the interpreter and failed.

我的建议是将Python和pip重新安装到完整路径中没有空格的目录中.

My advice is to re-install Python and pip into a directory without spaces in its full path.

当前情况的解决方法是手动运行python.要么

A workaround for your current situation is to run python manually. Either

python -m pip install speechrecognition

"/Users/naman/Documents/Ai Assistant/assistant/bin/python" -m pip install speechrecognition

请注意引号-它们防止命令解释器以空格分隔,以便整个/Users/naman/Documents/Ai Assistant/assistant/bin/python成为到达解释器的一条路径.无法使用引号并避免在shebang行中分裂.

Please note quotes — they prevent the command interpreter to split by spaces so that the entire /Users/naman/Documents/Ai Assistant/assistant/bin/python becomes one path to the interpreter. There is no way to use quotes and avoid splitting in the shebang line.

这篇关于如何在macOS Catalina上的VS Code中使用pip install安装依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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