Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a package to python in Visual Studio 2017

Tags:

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.

like image 244
ze_netio Avatar asked Apr 23 '17 20:04

ze_netio


People also ask

How do I import a Python package into Visual Studio?

To install a package, right-click the desired environment in the Solution Explorer, then click Install Python Package. In the search box, type matplotlib, then click on pip install matplotlib from PyPI. Once installed, the package appears in the Python Environments window.

How do I import a package code into Visual Studio?

Import packages#Run the command Go: Add Import to get a list of packages that can be imported to your Go file. Choose one and it will get added in the import block of your Go file.


1 Answers

You can, however it is not perfect.

Firstly you need to bring up the Python Environments menu which can be accessed by going:

Tools -> Python -> Python Environments

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.

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.

Therefore, you are best off going to Christoph Gohlke's unofficial package site and 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.

like image 101
Derme302 Avatar answered Sep 17 '22 20:09

Derme302