![]() |
VOOZH | about |
We’re so glad you’re here. You can expect all the best TNS content to arrive Monday through Friday to keep you on top of the news and at the top of your game.
Check your inbox for a confirmation email where you can adjust your preferences and even join additional groups.
Follow TNS on your favorite social media networks.
Become a TNS follower on LinkedIn.
Check out the latest featured and trending stories while you wait for your first TNS newsletter.
apt or dnf for Python. Not only does it install the package you want but also the required dependencies for said package. Without pip, you would have a far more challenging time expanding Python beyond what it includes out of the box.
To that end, I want to show you how to install and use Python’s pip. Once you know how to use this package manager, the sky’s the limit for what you can do with Python.
sudo apt-get install python3-pip -yOn Fedora-based distributions, the command is:
sudo dnf install python-pip -yIf you’re using macOS, you can install pip with the following command:
curl https://bootstrap.pypa.io/get-pip.py | pythonIf you have Python installed as Python3, the command would be:
curl https://bootstrap.pypa.io/get-pip.py | python3For Windows, download the standalone ZIP application and use it with any supported version of Python. As soon as you install it, upgrade it with the command:
pip install --upgrade pipIt seems odd that you’d upgrade pip with
pip, but that’s how it goes. You might run into instances where pip will fail to function properly because it requires an upgrade. That’s why the first thing I do is upgrade pip immediately after every pip installation.
Before continuing, there’s something important you’ll want to consider. If you install pip on Linux in the above fashion, you might run into several instances where applications can only be installed with pip using sudo, which can lead to possible security issues. To get around that, you’ll want to follow the following instructions:
wget https://bootstrap.pypa.io/get-pip.py.~/.local/bin) with python3 get-pip.py --user..local/bin to your $PATH by adding the following to the bottom of your ~/.bashrc file: export PATH="$HOME/.local/bin:$PATH". (Where USER is your Linux username)..bashrc file with source ~/.bashrc.sudo.
Once you have it installed, what can you do with pip? Let’s find out.
pip install -U pyinstallerThe
-U option informs pip to also upgrade the package to the newest available version.
The next method is to install packages from the requirements.txt file. When you use this method, you can create a list of packages to be installed and then install them all at once with a single command. This method is far easier, especially when you need to install several packages in multiple environments (or machines), so you don’t have to go through the process of installing the packages one by one.
First, create the requirements.txt file with:
nano requirements.txt
pyinstaller simplejson numpy
pip install -r requirements.txtEvery package in the file will be installed and ready to go. You can also install specific releases of packages this way. For example, say you want to install simplejson version 3.18.4. For that, the entry would be:
simplejson==3.18.4You could use the following specifiers:
== to install a specific release.> to install a release greater than what is specified.>= to install a release greater than or equal to what is specified.<= to install a release less than or equal to what is specified.pip freeze
pip list
python3 -m venv .venvThe above command creates a virtual environment called
.venv. You then must activate the environment with the command:
source .venv/bin/activateYour terminal prompt will now begin with (
.venv) to indicate you’re using it. You can then install any Python application with pip in the same way you did above (even using requirements.txt files).
Once you’re done with that environment, deactivate it with:
deactivateRemember, when you install a package in a virtual environment, it is not installed on your regular Python environment. And that’s how you get started with the Python pip package manager. Learn more about this handy tool by reading the man page with the command:
man pip