How to install python3 version of package via pip on Ubuntu?
On Ubuntu (and many other Linux distributions), you often have multiple versions of Python installed—commonly Python 2.x and Python 3.x. To install packages specifically for Python 3, you can use either:
pip3
(the dedicated command for Python 3), orpython3 -m pip
(calling pip as a module under Python 3).
Below are the most straightforward approaches.
1. Using pip3
Directly
Many Ubuntu systems provide a pip3
command for Python 3 by default or after installing the required packages:
sudo apt-get update sudo apt-get install python3-pip pip3 install <package_name>
For example, if you want to install requests
:
pip3 install requests
After this, you can verify installation by launching Python 3:
python3 >>> import requests >>> requests.__version__
2. Using python3 -m pip
If you prefer explicit clarity or don’t have a direct pip3
command, you can invoke pip as a module under Python 3:
sudo apt-get update sudo apt-get install python3-pip python3 -m pip install <package_name>
This is also handy when you have multiple Python versions (like 3.7 and 3.10) and want to control precisely which interpreter is used.
3. Checking Your Installation
After installing, confirm which pip is being used:
which pip3 which python3
They should correspond to your system’s Python 3 binary (e.g., /usr/bin/python3
). To see where a package was installed:
pip3 show <package_name>
This displays the version, location, and dependencies of the installed package.
4. Tips and Best Practices
-
Use Virtual Environments
For each project, consider using a virtual environment (venv
) to isolate dependencies and Python versions:python3 -m venv venv source venv/bin/activate pip install <package_name>
This avoids potential conflicts with system-level packages and keeps your project environment clean.
-
Keep pip Updated
python3 -m pip install --upgrade pip
An up-to-date pip helps you avoid installation issues and ensures you get the latest package metadata.
-
Uninstalling Packages
If you ever need to remove a package, use:pip3 uninstall <package_name>
5. Level Up Your Python Skills
Installing packages is just the start. If you want to strengthen your Python knowledge, consider these resources from DesignGurus.io:
-
Grokking Python Fundamentals
A clear, structured course covering the essentials of Python 3—from syntax to advanced features. -
Grokking the Coding Interview: Patterns for Coding Questions
Perfect if you’re preparing for technical interviews and want to master common data structures, algorithms, and coding patterns in Python.
If you’re looking to build large-scale systems or aim for senior engineering roles, system design knowledge is crucial:
- Grokking System Design Fundamentals
Ideal for understanding the building blocks of distributed systems and how to design scalable solutions.
Key Takeaway:
To install Python 3 packages on Ubuntu, install python3-pip
and then use pip3 install <package_name>
or python3 -m pip install <package_name>
. For a production-ready workflow, consider virtual environments to isolate your project dependencies. Happy coding!