Installing Python package in Visual Studio Code

This short post shows you how to install the Python package in Visual Studio Code, which is widely used in the programming environment.  The prerequisite for our operation is the Python extension in Visual Studio code, which should be installed at the very beginning (Pic. 1).

Python extension in Visual Studio Code

Pic. 1 Python extension in Visual Studio Code.

You can do the installation from this link and get the newest version of the Python language.
Next, you can start programming with Python in Visual Studio Code without a problem. However, it seems, like you are somewhat restricted when you discover, that there are problems with installing the external Python libraries and importing them to Visual Studio Code. I hope, that this quick solution will help you manage these issues.
The biggest problem at the initial stage is the presumed lack of the Pip installation in our Visual Studio Code software. The Pip is the most popular tool for installing Python packages and includes a modern version of Python. It provides the essential core features for finding, downloading, and installing Python packages.
In Visual Studio Code, the Pip seems to be not recognized as an internal or external command (Pic. 2).  Usually, we choose the quickest way of Python module installation, where after visiting the module we want to get, we simply make the copy of the top installation command and next, paste it to our Python dedicated software, i.e. PyCharm.

Pip not recognized in Visual Studio Code

Pic. 2 The “Pip not recognized” error in Visual Studio Code.

In the Visual Studio Code, we need to change our pip command a bit. The proper command in our terminal should be:

C:\Users\m\Desktop\Python> py -m pip

Once we hit enter, the whole list of commands should be populated as you can see below (Pic. 3).

Python Pip commands in Visual Studio Code

Pic. 3 A part of the list of commands for Pip in Visual Studio Code.

Now we are sure, that the Pip has been recognized by our Visual Studio Code. It means, that the Python library can be installed, which is great.
In order to make the installation correctly, we can’t simply make a copy of the main command available just below the library name (Pic. 2).
If we would do so, then our command would look like this:

C:\Users\m\Desktop\Python> py -m pip pip install numpy

and we would have to remove one “pip” preventing at least one space between the strings as you can see here.
I think, it much easier is just to type the py-m in our terminal path:

C:\Users\m\Desktop\Python> py -m

and then append the library command, which we want to install (Pic. 2)…

C:\Users\m\Desktop\Python> py -m pip install numpy 

After hitting the “Enter” button, you can see the installation progress. Next, the tool will inform you the information about the target path where the library has been installed as well as the new pip version if available (Pic. 4).

Python library installation successful in Visual Studio Code

Pic. 4 The Python library installation progress in Visual Studio Code.

In order to make sure, that everything is alright, you can import the library to the file you are working on, by simply typing:

import numpy

If something is wrong, the Python console will underline your code with a wavy red line. Since everything has been installed properly, the library is to be recognized instantly by the Visual Studio Code (Pic. 5).

Visual Studio Code library installed

Pic. 5 Python library imported successfully to Visual Studio Code.

I highly recommend using Visual Studio Code, which appears to be the best coding application in the market. The biggest advantage is a broad opportunity for coding in various programming languages. This application is great and supersedes other programming applications dedicated to a specified language. As a result, a lot of memory is saved keeping our computers faster.

Mariusz Krukar

Links:

  1. https://en.terminalroot.com.br/the-30-best-python-libraries-and-packages-for-beginners/
  2. https://pypi.org/
  3. https://code.visualstudio.com/docs/languages/python
  4. Python extension for Visual Studio Code
  5. https://pip.pypa.io/en/stable/installing/
  6. https://packaging.python.org/tutorials/installing-packages/
  7. https://github.com/pypa/pip
  8. https://pip.pypa.io/en/stable/

Forums:

  1. https://stackoverflow.com/questions/36835341/pip-is-not-recognized/67517658#67517658
  2. https://stackoverflow.com/questions/57310009/how-to-install-a-new-python-module-on-vscode/67517963#67517963
  3. https://stackoverflow.com/questions/23708898/pip-is-not-recognized-as-an-internal-or-external-command?page=1&tab=oldest#tab-top

Youtube:

You may also like...