Introduction
So you have Python installed (and working). Now, what’s next?
After installing Python we can already create our first scripts.
And the next step is to use external libraries. As we mentioned before, a powerful advantage of Python is that it can use external libraries - you simply import a package (a library) and you can so use all of its resources.
That’s where enters PIP.
Although third-party libraries and frameworks that we can install keep us from reinventing the wheel with every new project, the task of getting it done (downloading, installing, and managing these packages) by hand can be frustrating and time-consuming.
So we can use PIP to make this task much easier and faster.
What is PIP?
In short PIP is a very useful package manager for Python projects.
PIP stands for “PIP Installs Packages” or “Preferred Installer Program”.
Python supports third-party libraries and frameworks that you can install to avoid reinventing the wheel with every new project. If you want to use them you can find these Python libraries on a central repository called the Python Package Index (PyPI).
By default PIP is already installed with Python, and it is a command-line utility that allow us to install, remove and update Python packages in our projects with a simple and straightforward command: pip.
It is similar to the well-known npm (Node.js) and composer (php), for example.
If PIP is installed correctly, just type pip install <package_name> at the command prompt, and it will download and install <package_name>.
However, it may happen that even with Python installed on your computer, PIP is not installed. In that case, let’s see how to install.
Installing PIP on Windows
If PIP is already installed on your computer, you should find the PIP executable file in that Scripts folder inside the Python installation folder. (If you’re using Python 2.7.9 (or greater) or Python 3.4 (or greater) , then PIP comes installed with Python by default)
In our case it is, and we can find the file at C:\Users\telec\AppData\Local\Programs\Python\Python38\Scripts\.
As we can see, in our case the PIP was already installed when we installed Python, and therefore the file is in the folder where it should be.
In addition, the installer we used has already configured the system variables (for both Python and PIP), so when typing Python or PIP at the command prompt they are executed correctly.
Note: if the file is there, but give an error just by running the name Python or PIP at the command prompt, you should probably manually set the system variables, telling the system the path of such executables. But we’ll see that later.
But let’s consider that we don’t have the PIP installed. In this case, let’s see how to install it using Python itself (running a Python script).
The steps to install PIP on your Windows are described below.
-
Download the get-pip.py script to your computer.
This is a special script, made exclusively for this purpose: to install PIP.
To download, visit PIP website:
Then, click Installation link:
Next, right click get-pip.py hyperlink and choose “Save link as…” to save this file in a folder in your computer.
-
Open the command prompt and navigate to the folder where you saved get-pip.py
-
Run the following command.
python get-pip.py
Done: after this command the PIP has already been installed and added to your PATH environment variable and it should already be working.
To test just try to install a Package.
Installing Python Packages.
To find and download Python packages you can visit:
The Python Package Index (PyPI) is a repository of software for the Python programming language, and helps you find and install software developed and shared by the Python community
Upgrading PIP on Windows
Of course PIP itself doesn’t update very often. Anyway, it’s recommended to stay updated (new versions) in case of important fixes to bugs, compatibility, and security holes.
To upgrade PIP on Windows simply run the following command:
python -m pip install -U pip
Troubleshooting
Some error may occur when the location where the executable you want to run is (python.exe, pip.exe, …) is not in the PATH environment variable. Check that the two paths (where the Python is and where the PIP is) are set in the PATH environment variable. If so, close the command prompt (terminal) and open it again.
Conclusion
This was a brief tutorial about PIP (Python package manager).
If you have any questions, post them in the comments.
Index
Back to main index: Data Science by telecomHall Community