- How to install Python support in Visual Studio on Windows
- Visual Studio 2019 and Visual Studio 2017
- Troubleshooting
- Visual Studio 2015
- Visual Studio 2013 and earlier
- Install locations
- User-specific installations (1.5 and earlier)
- Installing Python ModulesВ¶
- Key termsВ¶
- Basic usageВ¶
- How do I …?¶
- … install pip in versions of Python prior to Python 3.4?¶
- … install packages just for the current user?¶
- … install scientific Python packages?¶
- … work with multiple versions of Python installed in parallel?¶
- Common installation issuesВ¶
- Installing into the system Python on LinuxВ¶
- Pip not installedВ¶
- Installing binary extensionsВ¶
How to install Python support in Visual Studio on Windows
To install Python support for Visual Studio (also known as Python Tools for Visual Studio or PTVS), follow the instructions in the section that matches your version of Visual Studio:
To quickly test Python support after following the installation steps, open the Python Interactive window by pressing Alt+I and entering 2+2 . If you don’t see the output of 4 , recheck your steps.
The Python workload includes the helpful Cookiecutter extension that provides a graphical user interface to discover templates, input template options, and create projects and files. For details, see Use Cookiecutter.
Python support is not presently available in Visual Studio for Mac, but is available on Mac and Linux through Visual Studio Code. See questions and answers.
Visual Studio 2019 and Visual Studio 2017
Download and run the latest Visual Studio installer. If you have Visual Studio installed already, run the Visual Studio Installer, select the Modify option (see Modify Visual Studio) and go to step 2.
The Community edition is for individual developers, classroom learning, academic research, and open source development. For other uses, install Visual Studio 2019 Professional or Visual Studio 2019 Enterprise.
The installer presents you with a list of workloads, which are groups of related options for specific development areas. For Python, select the Python development workload.
Optional: if you’re working with data science, also consider the Data science and analytical applications workload. This workload includes support for the Python, R, and F# languages. For more information, see Data science and analytical applications workload.
The Python and Data Science workloads are available only with Visual Studio 2017 version 15.2 and later.
Optional: if you’re working with data science, also consider the Data science and analytical applications workload. This workload includes support for the Python and F# languages. For more information, see Data science and analytical applications workload.
On the right side of the installer, chose additional options if desired. Skip this step to accept the default options.
Option | Description |
---|---|
Python distributions | Choose any combination of the available options, such as 32-bit and 64-bit variants of the Python 2, Python 3, Miniconda, Anaconda2, and Anaconda3 distributions that you plan to work with. Each includes the distribution’s interpreter, runtime, and libraries. Anaconda, specifically, is an open data science platform that includes a wide range of pre-installed packages. (You can return to the Visual Studio installer at any time to add or remove distributions.) Note: If you’ve installed a distribution outside of the Visual Studio installer, there’s no need to check the equivalent option here. Visual Studio automatically detects existing Python installations. See The Python Environments window. Also, if a newer version of Python is available than what’s shown in the installer, you can install that version separately and Visual Studio will detect it. |
Cookiecutter template support | Installs the Cookiecutter graphical UI to discover templates, input template options, and create projects and files. See Use the Cookiecutter extension. |
Python web support | Installs tools for web development including HTML, CSS, and JavaScript editing support, along with templates for projects using the Bottle, Flask, and Django frameworks. See Python web project templates. |
Python IoT support | Supports Windows IoT Core development using Python. |
Python native development tools | Installs the C++ compiler and other necessary components to develop native extensions for Python. See Create a C++ extension for Python. Also install the Desktop development with C++ workload for full C++ support. |
Azure Cloud Services core tools | Provides additional support for developer Azure Cloud Services in Python. See Azure cloud service projects. |
Option | Description |
---|---|
Python distributions | Choose any combination of the available options, such as 32-bit and 64-bit variants of the Python 2, Python 3, Miniconda, Anaconda2, and Anaconda3 distributions that you plan to work with. Each includes the distribution’s interpreter, runtime, and libraries. Anaconda, specifically, is an open data science platform that includes a wide range of pre-installed packages. (You can return to the Visual Studio installer at any time to add or remove distributions.) Note: If you’ve installed a distribution outside of the Visual Studio installer, there’s no need to check the equivalent option here. Visual Studio automatically detects existing Python installations. See The Python Environments window. Also, if a newer version of Python is available than what’s shown in the installer, you can install that version separately and Visual Studio will detect it. |
Cookiecutter template support | Installs the Cookiecutter graphical UI to discover templates, input template options, and create projects and files. See Use the Cookiecutter extension. |
Python web support | Installs tools for web development including HTML, CSS, and JavaScript editing support, along with templates for projects using the Bottle, Flask, and Django frameworks. See Python web project templates. |
Python native development tools | Installs the C++ compiler and other necessary components to develop native extensions for Python. See Create a C++ extension for Python. Also install the Desktop development with C++ workload for full C++ support. |
Azure Cloud Services core tools | Provides additional support for developer Azure Cloud Services in Python. See Azure cloud service projects. |
After installation, the installer provides options to modify, launch, repair, or uninstall Visual Studio. The Modify button changes to Update when updates to Visual Studio are available for any installed components. (The Modify option is then available on the drop-down menu.) You can also launch Visual Studio and the installer from the Windows Start menu by searching on «Visual Studio».
Troubleshooting
If you encounter problems installing or running Python in Visual Studio, try the following:
- Determine whether the same error occurs using the Python CLI, that is, running python.exe from a command prompt.
- Use the Repair option in the Visual Studio installer.
- Repair or reinstall Python through Settings >Apps & features in Windows.
Example error: Failed to start interactive process: System.ComponentModel.Win32Exception (0x80004005): Unknown error (0xc0000135) at Microsoft.PythonTools.Repl.PythonInteractiveEvaluator.d__43.MoveNext().
Visual Studio 2015
Run the Visual Studio installer through Control Panel > Programs and Features, selecting Microsoft Visual Studio 2015 and then Change.
In the installer, select Modify.
Select Programming Languages > Python Tools for Visual Studio and then Next:
Once Visual Studio setup is complete, install a Python interpreter of your choice. Visual Studio 2015 supports only Python 3.5 and earlier; later versions generate a message like Unsupported Python version 3.6). If you already have an interpreter installed and Visual Studio doesn’t detect it automatically, see Manually identify an existing environment.
Visual Studio 2013 and earlier
Install the appropriate version of Python Tools for Visual Studio for your version of Visual Studio:
- Visual Studio 2013: PTVS 2.2.2 for Visual Studio 2013. The File >New Project dialog in Visual Studio 2013 gives you a shortcut for this process.
- Visual Studio 2010 and 2012: PTVS 2.1.1 for Visual Studio 2010 and 2012
Install a Python interpreter of your choice. If you already have an interpreter installed and Visual Studio doesn’t detect it automatically, see Manually identify an existing environment.
Install locations
By default, Python support is installed for all users on a computer.
For Visual Studio 2019 and Visual Studio 2017, the Python workload is installed in %ProgramFiles(x86)%\Microsoft Visual Studio\ \ Common7\IDE\Extensions\Microsoft\Python where is 2019 or 2017 and is Community, Professional, or Enterprise.
For Visual Studio 2015 and earlier, installation paths are as follows:
- 32-bit:
- Registry location of path: HKEY_LOCAL_MACHINE\Software\Microsoft\PythonTools\ \InstallDir
- Path: %Program Files(x86)%\Microsoft Visual Studio \Common7\IDE\Extensions\Microsoft\Python Tools for Visual Studio\
- Path: %Program Files%\Microsoft Visual Studio \Common7\IDE\Extensions\Microsoft\Python Tools for Visual Studio\
- Registry location of path: HKEY_LOCAL_MACHINE\Software\Wow6432Node\Microsoft\PythonTools\ \InstallDir
- is:
- 14.0 for Visual Studio 2015
- 12.0 for Visual Studio 2013
- 11.0 for Visual Studio 2012
- 10.0 for Visual Studio 2010
is a version number, such as 2.2.2, 2.1.1, 2.0, 1.5, 1.1, or 1.0.
User-specific installations (1.5 and earlier)
Python Tools for Visual Studio 1.5 and earlier allowed installation for the current user only, in which case the installation path is %LocalAppData%\Microsoft\VisualStudio\ \Extensions\Microsoft\Python Tools for Visual Studio\
Installing Python ModulesВ¶
As a popular open source development project, Python has an active supporting community of contributors and users that also make their software available for other Python developers to use under open source license terms.
This allows Python users to share and collaborate effectively, benefiting from the solutions others have already created to common (and sometimes even rare!) problems, as well as potentially contributing their own solutions to the common pool.
This guide covers the installation part of the process. For a guide to creating and sharing your own Python projects, refer to the distribution guide .
For corporate and other institutional users, be aware that many organisations have their own policies around using and contributing to open source software. Please take such policies into account when making use of the distribution and installation tools provided with Python.
Key termsВ¶
pip is the preferred installer program. Starting with Python 3.4, it is included by default with the Python binary installers.
A virtual environment is a semi-isolated Python environment that allows packages to be installed for use by a particular application, rather than being installed system wide.
venv is the standard tool for creating virtual environments, and has been part of Python since Python 3.3. Starting with Python 3.4, it defaults to installing pip into all created virtual environments.
virtualenv is a third party alternative (and predecessor) to venv . It allows virtual environments to be used on versions of Python prior to 3.4, which either don’t provide venv at all, or aren’t able to automatically install pip into created environments.
The Python Packaging Index is a public repository of open source licensed packages made available for use by other Python users.
the Python Packaging Authority is the group of developers and documentation authors responsible for the maintenance and evolution of the standard packaging tools and the associated metadata and file format standards. They maintain a variety of tools, documentation, and issue trackers on both GitHub and Bitbucket.
distutils is the original build and distribution system first added to the Python standard library in 1998. While direct use of distutils is being phased out, it still laid the foundation for the current packaging and distribution infrastructure, and it not only remains part of the standard library, but its name lives on in other ways (such as the name of the mailing list used to coordinate Python packaging standards development).
Changed in version 3.5: The use of venv is now recommended for creating virtual environments.
Basic usageВ¶
The standard packaging tools are all designed to be used from the command line.
The following command will install the latest version of a module and its dependencies from the Python Packaging Index:
For POSIX users (including Mac OS X and Linux users), the examples in this guide assume the use of a virtual environment .
For Windows users, the examples in this guide assume that the option to adjust the system PATH environment variable was selected when installing Python.
It’s also possible to specify an exact or minimum version directly on the command line. When using comparator operators such as > , or some other special character which get interpreted by shell, the package name and the version should be enclosed within double quotes:
Normally, if a suitable module is already installed, attempting to install it again will have no effect. Upgrading existing modules must be requested explicitly:
More information and resources regarding pip and its capabilities can be found in the Python Packaging User Guide.
Creation of virtual environments is done through the venv module. Installing packages into an active virtual environment uses the commands shown above.
How do I …?¶
These are quick answers or links for some common tasks.
… install pip in versions of Python prior to Python 3.4?¶
Python only started bundling pip with Python 3.4. For earlier versions, pip needs to be “bootstrapped” as described in the Python Packaging User Guide.
… install packages just for the current user?¶
Passing the —user option to python -m pip install will install a package just for the current user, rather than for all users of the system.
… install scientific Python packages?¶
A number of scientific Python packages have complex binary dependencies, and aren’t currently easy to install using pip directly. At this point in time, it will often be easier for users to install these packages by other means rather than attempting to install them with pip .
… work with multiple versions of Python installed in parallel?¶
On Linux, Mac OS X, and other POSIX systems, use the versioned Python commands in combination with the -m switch to run the appropriate copy of pip :
Appropriately versioned pip commands may also be available.
On Windows, use the py Python launcher in combination with the -m switch:
Common installation issuesВ¶
Installing into the system Python on LinuxВ¶
On Linux systems, a Python installation will typically be included as part of the distribution. Installing into this Python installation requires root access to the system, and may interfere with the operation of the system package manager and other components of the system if a component is unexpectedly upgraded using pip .
On such systems, it is often better to use a virtual environment or a per-user installation when installing packages with pip .
Pip not installedВ¶
It is possible that pip does not get installed by default. One potential fix is:
There are also additional resources for installing pip.
Installing binary extensionsВ¶
Python has typically relied heavily on source based distribution, with end users being expected to compile extension modules from source as part of the installation process.
With the introduction of support for the binary wheel format, and the ability to publish wheels for at least Windows and Mac OS X through the Python Packaging Index, this problem is expected to diminish over time, as users are more regularly able to install pre-built extensions rather than needing to build them themselves.
Some of the solutions for installing scientific software that are not yet available as pre-built wheel files may also help with obtaining other binary extensions without needing to build them locally.