如何在 Visual Studio 2017 中向 python 添加包
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/43575864/
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
How to add a package to python in Visual Studio 2017
提问by ze_netio
I just installed the new VS2017 Preview and imported a Python project. This project has many import statements but VS2017 does show error in some import packages like cv2, socketio, eventlet, eventlet.wsgi. This Python project runs fine, out of VS2017, in my Anaconda environment. Do I need to install OpenCV 2, socketio, etc in Windows? Or is there a solution like pip, anaconda, apt-get, in the VS2017 environment that can automate the installation of unresolved package? I also noticed that it is possible to add Anaconda to VS project created. Can this Anaconda inside VS help to install the missing packages? Regards.
我刚刚安装了新的 VS2017 Preview 并导入了一个 Python 项目。这个项目有很多导入语句,但是 VS2017 确实在一些导入包中显示错误,比如 cv2、socketio、eventlet、eventlet.wsgi。这个 Python 项目在 VS2017 之外在我的 Anaconda 环境中运行良好。我是否需要在 Windows 中安装 OpenCV 2、socketio 等?或者有没有像pip、anaconda、apt-get这样的解决方案,在VS2017环境下可以自动安装未解析包?我还注意到可以将 Anaconda 添加到创建的 VS 项目中。VS 中的这个 Anaconda 可以帮助安装丢失的软件包吗?问候。
回答by Derme302
You can, however it is not perfect.
你可以,但它并不完美。
Firstly you need to bring up the Python Environments menu which can be accessed by going:
首先,您需要调出可以通过以下方式访问的 Python Environments 菜单:
Tools -> Python -> Python Environments
工具 -> Python -> Python 环境
It should bring up a sidebar (depending on how you have VS setup). There should be a dropdown box about half way down with the text "Overview". Click on that and you can select "Packages". This will bring up a textbox under it that will allow you to use standard pip commands to install packages.
它应该会显示一个侧边栏(取决于您如何设置 VS)。中间应该有一个下拉框,上面写着“概览”。单击它,您可以选择“包”。这将在其下方显示一个文本框,允许您使用标准的 pip 命令来安装软件包。
If you are on Windows though there is one added step for some packages though. As pip does not work well on Windows, due to the fact that the standard Windows package site (PyPI) does not yet have Windows wheels for a lot of common packages.
如果您使用的是 Windows,尽管对于某些软件包还有一个额外的步骤。由于 pip 在 Windows 上不能很好地工作,因为标准 Windows 包站点 ( PyPI) 还没有用于许多常见包的 Windows 轮子。
Therefore, you are best off going to Christoph Gohlke's unofficial package siteand then downloading the package you need. Once it's downloaded locally just copy and paste the LOCAL address into the textbox under "Packages". It will then install the package and you'll be good to go.
因此,您最好前往Christoph Gohlke 的非官方软件包站点,然后下载您需要的软件包。在本地下载后,只需将本地地址复制并粘贴到“包”下的文本框中。然后它将安装该软件包,您就可以开始了。
回答by sumeet kumar
I had same problem and i could get it working with visual studio 2017 python v3.6 using following instructions
我遇到了同样的问题,我可以使用以下说明使用 Visual Studio 2017 python v3.6
Install appropriate .whl fileusing this link
(cpMNwhere you have Python M.N). contrib includes OpenCV-extra packages. For example, assuming you have Python 3.6, you might download **opencv_python-3.2.0+contrib-cp36-none-win_amd64.whl**
使用此链接安装适当的 .whl 文件(您拥有 Python MN 的cpMN)。contrib 包括 OpenCV-extra 包。例如,假设您有 Python 3.6,您可以下载**opencv_python-3.2.0+contrib-cp36-none-win_amd64.whl**
Then install it by running this command from installed folder
然后通过从已安装文件夹运行此命令来安装它
pip install opencv_python-3*win_amd64.whl