pip 可以与 Visual Studio 中的 Python 工具一起使用吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15185827/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-18 13:34:43  来源:igfitidea点击:

Can pip be used with Python Tools in Visual Studio?

pythonvisual-studiopipptvs

提问by Matt

I'm collaborating with some fellow students to build a python app, and was hoping to use the 'training wheels' of Visual Studio intelli-sense. They use python on mac and linux, so ideally our source control repo would consist of just *.pysource files that we wrote, and a requirements.txtexport of pip dependancies (using the pip freezemethod).

我正在与一些同学合作构建一个 python 应用程序,并希望使用 Visual Studio 智能感知的“训练轮”。他们在 mac 和 linux 上使用 python,所以理想情况下,我们的源代码控制库将只包含*.py我们编写的源文件和requirements.txtpip 依赖项的导出(使用该pip freeze方法)。

I would love to be able to create a new Visual Studio project, then be able to run the following commands (for instance) within that project:

我希望能够创建一个新的 Visual Studio 项目,然后能够在该项目中运行以下命令(例如):

pip install boto
pip install fabric
pip install cuisine
pip freeze > requirements.txt

And after that, be able to write some code that references these libraries and be able to run it from within Visual Studio.

之后,能够编写一些引用这些库的代码并能够从 Visual Studio 中运行它。

Is there any way to do this? Is Python within Visual Studio even able to handle modules in the format they are available within pip, or do all python libraries used in VS have to have been pre-compiled for Windows?

有没有办法做到这一点?Visual Studio 中的 Python 甚至能够以它们在 pip 中可用的格式处理模块,还是 VS 中使用的所有 Python 库都必须针对 Windows 进行预编译?

Thanks in advance for any help!

在此先感谢您的帮助!

采纳答案by Charles Clayton

Yep! Go to Tools-> Python Tools-> Python Environments.

是的!去Tools-> Python Tools-> Python Environments

This will open a new pane where you can select pipfrom the menu (it will say Overviewby default) and then you can enter your module and double click to install.

这将打开一个新窗格,您可以在其中pip从菜单中进行选择(Overview默认情况下会显示),然后您可以输入您的模块并双击进行安装。

enter image description here

在此处输入图片说明

Some packages have complex dependencies, and you might need to install them manually from these links:

某些软件包具有复杂的依赖关系,您可能需要从以下链接手动安装它们:

回答by Axel

Yes you can, here is a simple guide taken from here https://zignar.net/2012/06/17/install-python-on-windows/

是的,你可以,这是从这里获取的简单指南https://zignar.net/2012/06/17/install-python-on-windows/

Before you can install Pip, you'll need setuptools or distribute. If you're using Python3, you must use distribute as setuptools doesn't support Python 3.x

在安装 Pip 之前,您需要安装工具或分发。如果您使用的是 Python3,则必须使用分发,因为 setuptools 不支持 Python 3.x

To install distribute download the setup file here https://pypi.python.org/pypi/distribute/0.6.27and invoke it using python.

要安装分发,请在此处下载安装文件https://pypi.python.org/pypi/distribute/0.6.27并使用 python 调用它。

python.exe C:\Path\to\distribute_setup.py

python.exe C:\Path\to\distribute_setup.py

Now that distribute is installed, Pip can also be installed. Download get-pip.py here https://raw.github.com/pypa/pip/master/contrib/get-pip.pyand invoke it in the same way you invoked distribute_setup:

现在安装了分发,也可以安装 Pip。在这里下载 get-pip.py https://raw.github.com/pypa/pip/master/contrib/get-pip.py并以调用distribute_setup的相同方式调用它:

python.exe c:\Path\to\get-pip.py

python.exe c:\Path\to\get-pip.py

After that Pip is installed. But you might want to add C:\Python32\Scripts to the Path Systemvariable too (see step 1). So you can execute pip.exe from any location.

之后安装了 Pip。但您可能还想将 C:\Python32\Scripts 添加到路径系统变量中(请参阅步骤 1)。因此您可以从任何位置执行 pip.exe。

回答by Pavel Minaev

From the mention of Visual Studio, it sounds like you're using Python Tools for Visual Studio. If so, then support for pip, easy_install and virtualenvis one of the new features in PTVS 2.0 beta - get itand give it a try. Once you add an interpreter reference to your project, you'll find commands to install a package in context menu for that interpreter in Solution Explorer.

从提到 Visual Studio 来看,听起来您正在使用适用于 Visual Studio 的 Python 工具。如果是这样,那么对 pip、easy_install 和 virtualenv 的支持是 PTVS 2.0 测试版中的新功能之一 -获取并尝试一下。向项目添加解释器引用后,您将在解决方案资源管理器中为该解释器的上下文菜单中找到用于安装包的命令。

This way, you also do not have to set up pip yourself, since PTVS will do it for you the first time you try to install a package.

这样,您也不必自己设置 pip,因为 PTVS 会在您第一次尝试安装软件包时为您完成。

回答by Den-Jason

On VS 2017, switch to the "solution explorer" and right click as indicated:

在 VS 2017 上,切换到“解决方案资源管理器”并按指示右键单击:

enter image description here

在此处输入图片说明

回答by Synat Khim

and you can set your path to pip like this:

您可以像这样设置 pip 的路径:

Open cmd prompt

Run set PATH="C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64"

set PATH="C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64"

回答by Neil Highley

When you install Python support with Visual Studio, the PIP executable can be found in C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\Scripts If it isnt there, type the following at a command prompt to find out Pythons install location py --location Then either add the location to path, or run pip with the full path from powershell . "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\Scripts\pip.exe" install pillow

当您使用 Visual Studio 安装 Python 支持时,可以在以下位置找到 PIP 可执行文件 C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\Scripts 如果它不存在,请在命令提示符下键入以下内容以找出 Python 安装位置 py --location 然后将该位置添加到路径,或使用来自的完整路径运行 pip电源外壳 . "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\Scripts\pip.exe" install pillow