Skip to content

Install Python and libraries with Visual Studio

This tutorial explains how to install Python and libraries with Visual Studio. I will also show how to install libraries in the command prompt (CMD). Python is a very powerful language for machine learning as it has many libraries that can be used to help you develop great models for prediction.

Visual Studio Installer

Use Visual Studio Installer to install Python with Visual Studio. Modify your Visual Studio Version, check Python development and click on the Modify button. Python will be installed to “C:\Program Files (x86)\Microsoft Visual Studio\Shared”.

Visual Studio Installer

Add to path environment variable

You need to add the path to the Python folder and to the Scripts folder in environment variables, if you want to be able to use Python and Pip (install libraries) from anywhere in the Command Prompt. It is also useful to add paths to directories as environment variables if other programs references these programs in code.

Search for environment variables and click on the Edit environment variables result. Add the Python directory (C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64) and the Scripts directory (C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\Scripts) as new rows in the Path variable.

Edit environment variables

You will need to browse to the Python folder in the Command Prompt to be able to execute python scripts if you don’t have added paths to environment variables.

Microsoft Windows [Version 10.0.18362.418]
(c) 2019 Microsoft Corporation. Med ensamrätt.

C:\WINDOWS\system32>cd C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64

C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64>python
Python 3.7.4 (tags/v3.7.4:e09359112e, Jul  8 2019, 20:34:20) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>

Install libraries

You will need some libraries to be able to work with machine learning. You can install libraries with Pip from the command prompt or in Visual Studio. Some useful libraries is joblib, numpy, pandas, matplotlib, pytesseract, scipy, statsmodels, scikit-learn, tensorflow and Keras. You need to know that names of libraries is case sensitive. To use pytesseract you will also need to install Tesseract OCR and unpack poppler, you will also need to add the path to poppler and Tesseract OCR as environment variables.

Open the Command Prompt (CMD) as an administrator to install libraries with Pip. You can install specific versions of a library and uninstall libraries with Pip.

Microsoft Windows [Version 10.0.18362.418]
(c) 2019 Microsoft Corporation. Med ensamrätt.

C:\WINDOWS\system32>pip install numpy
Requirement already satisfied: numpy in c:\program files (x86)\microsoft visual studio\shared\python37_64\lib\site-packages (1.17.3)

C:\WINDOWS\system32>pip install scipy==1.3.1
Requirement already satisfied: scipy==1.3.1 in c:\program files (x86)\microsoft visual studio\shared\python37_64\lib\site-packages (1.3.1)
Requirement already satisfied: numpy>=1.13.3 in c:\program files (x86)\microsoft visual studio\shared\python37_64\lib\site-packages (from scipy==1.3.1) (1.17.3)

C:\WINDOWS\system32>pip uninstall numpy

You can also install, uninstall and upgrade Python libraries in Visual Studio. This is done inside Python Environments. Select Packages (PyPI) in the dropdown (Overview).

Python Environment in Visual Studio

Test if libraries is installed

Create a new Python project in Visual Studio and add an Empty Python File to the project. Right click the new file and set it as Startup File. Add the following contents and run the script.

# Import libraries
import sys
import scipy
import numpy
import matplotlib
import pandas
import sklearn  # scikit-learn

# Check the version of installed libraries
print('Python: {0}'.format(sys.version))
print('scipy: {0}'.format(scipy.__version__))
print('numpy: {0}'.format(numpy.__version__))
print('matplotlib: {0}'.format(matplotlib.__version__))
print('pandas: {0}'.format(pandas.__version__))
print('sklearn: {0}'.format(sklearn.__version__))

4 thoughts on “Install Python and libraries with Visual Studio”

    1. Hi!

      Thank you for your comment. Tesseract OCR and poppler is independently installed on the operating system, the path is set on the operating system as well.

  1. ARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by ‘ProtocolError(‘Connection aborted.’, ConnectionResetError(10054, ‘An existing connection was forcibly closed by the remote host’, None, 10054, None))’: /simple/anytree/

    Getting this warning and then an error
    ERROR: Could not find a version that satisfies the requirement == (from versions: none)
    ERROR: No matching distribution found for ==

    Any idea how this could be resolved?

Leave a Reply

Your email address will not be published. Required fields are marked *