Python VSCode:所选环境中没有可用的 Pip 安装程序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/50993566/
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
VSCode: There is no Pip installer available in the selected environment
提问by ashgromnies
I'm trying to run the autopep8 linter on a Python file in VSCode.
我正在尝试在 VSCode 中的 Python 文件上运行 autopep8 linter。
I've followed the instructions here: https://code.visualstudio.com/docs/python/environmentsand selected my interpreter (??P): /usr/local/bin/python
我已按照此处的说明进行操作:https: //code.visualstudio.com/docs/python/environments并选择了我的解释器 (??P):/usr/local/bin/python
I then try to format my code, and VSCode says autopep8 isn't installed, and can be installed via Pip. However, when I try to install via Pip, it says There is no Pip installer available in the selected environment
.
然后我尝试格式化我的代码,VSCode 说没有安装 autopep8,可以通过 Pip 安装。但是,当我尝试通过 Pip 安装时,它显示There is no Pip installer available in the selected environment
.
I then tried launching a terminal in the current environment by selecting Python: Create Terminalfrom the Command Palette.
然后,我尝试通过从命令面板中选择Python: Create Terminal在当前环境中启动终端。
The terminal opens fine, pip
is present, and I'm even able to pip install autopep8
in the terminal that opened in VSCode, but when I try running the Format Documentcommand I get the same errors that autopep8
and pip
aren't available in the environment.
终端打开精细,pip
是目前,我甚至能够pip install autopep8
在在VSCode打开终端,但是当我试图运行格式文档命令我得到同样的错误,autopep8
而pip
不是在现有的环境。
回答by sean.wu
On Ubuntu16.04, I worked with Python3 in vscode and
在 Ubuntu16.04 上,我在 vscode 中使用 Python3 和
apt-get install python3-pip
solves my problem.
解决了我的问题。
That's because I discover that: Under my terminal, I type the pip -V
. It displays it's for Python2, not for Python3.
那是因为我发现:在我的终端下,我输入pip -V
. 它显示它适用于 Python2,而不是 Python3。
回答by elan lima
Man you can only change the interpreter.
伙计,您只能更改解释器。
Go in (ctrl + shift + p), then type Python: Select Interpreter, this way you choose the version that your extension needs.
进入 (ctrl + shift + p),然后输入 Python: Select Interpreter,这样你就可以选择你的扩展程序需要的版本。
This worked for me.
这对我有用。
回答by Manohar Reddy Poreddy
I have multiple python versions:
我有多个 python 版本:
2.7
3.6
3.7
- Tell the vscode/ visual studio code, which version to use:
- 告诉 vscode/visual studio 代码,使用哪个版本:
press the following (Show All Commands): Ctrl + Shift + P
paste the following: Python: Select Interpreter
Select one of the version that it shows, I have selected python 3.7.3 64-bit
按以下(显示所有命令):
粘贴以下内容:
选择它显示的版本之一,我已选择Ctrl + Shift + P
Python: Select Interpreter
python 3.7.3 64-bit
- Update python path in settings:
- 在设置中更新 python 路径:
press Ctrl + ,
to open Settings
search for python.pythonPath
change python
to /usr/bin/python3.7
按Ctrl + ,
打开设置
搜索
更改为python.pythonPath
python
/usr/bin/python3.7
Note: this may not be needed, however, make sure /usr/bin/python3.7
really exists for you, you may have at a different path like /usr/local/bin/python3.7
, etc.
注意:这可能不是必需的,但是,请确保/usr/bin/python3.7
确实为您存在,您可能有不同的路径,例如/usr/local/bin/python3.7
等。
- I had pip but it was 2.7, but since I am choosing python 3, it's pip needs to be installed
- 我有 pip 但它是 2.7,但是因为我选择了 python 3,所以需要安装它的 pip
Run the following command in Terminal: apt-get install python3-pip
在终端中运行以下命令: apt-get install python3-pip
- Restart vscode
- 重启vscode
With the above steps, all issues got resolved. Hope that helps.
通过以上步骤,所有问题都解决了。希望有帮助。
回答by Mohit Dabas
1.Select the File > Preferences > Settings command (?,) to open your User Settings.
1. 选择文件 > 首选项 > 设置命令 (?,) 打开您的用户设置。
2.Search and Create or modify an entry for python.pythonPath with the full path to the Python executable according to your requirements.For Example i changed it to python2.6 path to this path /usr/local/bin/python3.
2.根据您的要求搜索并创建或修改python.pythonPath的条目,其中包含Python可执行文件的完整路径。例如,我将其更改为此路径/usr/local/bin/python3的python2.6路径。
回答by u5746193
(on mac)if you are using python3 but vscode told you pip was not installed , you could change python version on vscode bottom. And I guess you are using another terminal but not bash , vscode's default terminal is bash. Bash don't know you have install pip@2.
(在 mac 上)如果你使用的是 python3 但 vscode 告诉你 pip 没有安装,你可以在 vscode 底部更改 python 版本。而且我猜您正在使用另一个终端而不是 bash ,vscode 的默认终端是 bash。Bash 不知道你已经安装了 pip@2。
回答by muhammad ali e
try Ctrl+Shift+Pthen type
尝试Ctrl+ Shift+P然后键入
Python: Select Interpreter
and select the python version.
并选择python版本。
回答by Rafik Saad
Installing python3-pip fixed the issue for me.
安装 python3-pip 为我解决了这个问题。
apt-get install python3-pip
回答by Ranjita Shetty
For Windows system check the environment variable>System variables check the Path variable for the python path.(if not found set the path variable for python)
对于 Windows 系统检查环境变量>系统变量检查 python 路径的 Path 变量。(如果没有找到为 python 设置路径变量)
Copy the path and paste under vscode>file>preferences>settings>python.pythonPath
复制路径并粘贴到 vscode>file>preferences>settings>python.pythonPath 下
It worked for me.
它对我有用。
回答by Kamil Naja
On Ubuntu:
在 Ubuntu 上:
Make sure, that you have Python and pip installed.
确保你已经安装了 Python 和 pip。
Go to Settings, type python.py in search input. This should find Python Path settings.
转到设置,在搜索输入中键入 python.py。这应该找到 Python 路径设置。
Remove this path (if it is currently setted), save. Exit Code and set this to current value.
删除此路径(如果当前已设置),保存。退出代码并将其设置为当前值。
For me is /usr/bin/python3
对我来说是 /usr/bin/python3
回答by liona
You can use the pycharm instead of it,ues Pycharm open the same DIR,it will add the .idea DIR in it , then close Pycharm or not,if you like it. you will get that,the question is gone.
您可以使用 pycharm 代替它,因为 Pycharm 打开相同的 DIR,它会在其中添加 .idea DIR,然后关闭 Pycharm,如果您喜欢它。你会明白的,问题消失了。