updated: 2019-05-11: This post mostly mentions virtualenv, but according to the Python doc about module installation, since Python 3.5 "the use of venv is now recommended for creating virtual environments", while virtualenv is an alternative for versions of Python prior to 3.4.

updated: 2018-08-17: since conda-4.4.0 use conda to activate anaconda on all platforms

updated: 2017-03-27: PEP 513 - manylinux binaries for PyPI

updated: 2016-08-19: Continuum Anaconda Option

This is somewhat a duplicate of easy_install/pip or apt-get.

For global Python packages, use either the Ubuntu Software Center, apt, apt-get or synaptic

Ubuntu uses Python for many important functions, therefore interfering with Python can corrupt your OS. This is the main reason I never use pip on my Ubuntu system, but instead I use either Ubuntu Software Center, synaptic, apt-get, or the newer just apt, which all by default install packages from the Ubuntu repository. These packages are tested, usually pre-compiled so they install faster and ultimately designed for Ubuntu. In addition all required dependencies are also installed and a log of installs is maintained so they can be rolled back. I think most packages have corresponding Launchpad repos so you can file issues.

Another reason to use either Ubuntu packages is that sometimes these Python packages have different names depending on where you downloaded them from. Python-chardet is an example of a package which at one time was named one thing on PyPI and another thing in the Ubuntu repository. Therefore doing something like pip install requests will not realize that chardet is already installed in your system because the Ubuntu version has a different name, and consequently install a new version which will corrupt your system in a minor insignificant way but still why would you do that.

In general you only want to install trusted code into your OS. So you should be nervous about typing $ sudo pip <anything-could-be-very-bad>.

Lastly some things are just easier to install using either Ubuntu packages. For example if you try pip install numpy to install numpy & scipy unless you have already installed gfortran, atlas-dev, blas-dev and lapack-dev, you will see an endless stream of compile errors. However, installing numpy & scipy through the Ubuntu repository is as easy as...

$ sudo apt-get install python-numpy python-scipy

You are in luck, because you are using Ubuntu, one of the most widely supported and oft updated distributions existing. Most likely every Python package you will need is in the Ubuntu repository, and probably already installed on your machine. And every 6 months, a new cycle of packages will be released with the latest distribution of Ubuntu.

If you are 100% confident that the package will not interfere with your Ubuntu system in any way, then you can install it using pip and Ubuntu is nice enough to keep these packages separate from the distro packages by placing the distro packages in a folder called dist-packages/. Ubuntu repository has both pip, virtualenv and setuptools. However, I second Wojciech's suggestion to use virtualenv.

For personal Python projects use pip and wheel in a virtualenv

If you need the latest version, or the module is not in the Ubuntu repository then start a virtualenv and use pip to install the package. Although pip and setuptools have merged, IMO pip is preferred over easy-install or distutils, because it will always wait until the package is completely downloaded and built before it copies it into your file system, and it makes upgrading or uninstalling a breeze. In a lot of ways it is similar to apt-get, in that it generally handles dependencies well. However you will may have to handle some dependencies yourself, but since PEP 513 was adopted there are now manylinux binaries at the Python Package Index (PyPI) for popular Linux distros like Ubuntu and Fedora. for example as mentioned above for NumPy and SciPy make sure you have installed gfortran, atlas-dev, blas-dev and lapack-dev from the Ubuntu repository For example, both NumPy and SciPy are now distributed for Ubuntu as manylinux wheels by default using OpenBLAS instead of ATLAS. You can still build them from source by using the pip options --no-use-wheel or --no-binary <format control>.

~$ sudo apt-get install gfortran libblas-dev liblapack-dev libatlas-dev python-virtualenv
~$ mkdir ~/.venvs
~$ virtualenv ~/.venvs/my_py_proj
~$ source ~/.venvs/my_py_proj/bin/activate
~(my_py_proj)$ pip install --no-use-wheel numpy scipy

See the next section, "You're not in sudoers", below for installing updated versions of pip, setuptools, virtualenv or wheels to your personal profile using the --user installation scheme with pip. You can use this to update pip for your personal use as J.F. Sebastian indicated in his comment to another answer. NOTE: the -m is really only necessary on MS Windows when updating pip.

python -m pip install --user pip setuptools wheel virtualenv

Newer versions of pip automatically cache wheels, so the following is only useful for older versions of pip. Since you may end up installing these many times, consider using wheel with pip to create a wheelhouse. Wheel is already included in virtualenv since v13.0.0 therefore if your version of virtualenv is too old, you may need to install wheel first.

~(my_py_proj)$ pip install wheel  # only for virtualenv < v13.0.0
~(my_py_proj)$ pip wheel --no-use-wheel numpy scipy

This will create binary wheel files in <cwd>/wheelhouse, use -d to specify a different directory. Now if you start another virtualenv and you need the same packages you've already built, you can install them form your wheelhouse using pip install --find-links=<fullpath>/wheelhouse

Read Installing Python Modules in the Python documentation and Installing packages on the Python Package Index main page. Also pip, venv, virtualenv and wheel.

If you're not in sudoers and virtualenv isn't installed.

Another option to using a virtual environment, or if you are using a Linux share without root privileges, then using either the --user or --home=<wherever-you-want> Python installation schemes with Python's distutils will install packages to the value of site.USERBASE or to wherever you want. Newer versions of pip also have a --user option. Do not use sudo!

pip install --user virtualenv

If your Linux version of pip is too old, then you can pass setup options using --install-option which is useful for passing custom options to some setup.py scripts for some packages that build extensions, such as setting the PREFIX. You may need to just extract the distribution and use distutils to install the package the old-school way by typing python setup install [options]. Reading some of the install documentation and the distutils documentation may help.

Python is nice enough to add site.USERBASE to your PYTHONPATH ahead of anything else, so the changes will only effect you. A popular location for --home is ~/.local. See the Python module installation guide for the exact file structure and specifically where your site-packages are. Note: if you use the --home installation scheme then you may need to add it to the PYTHONPATH environment variable using export in your .bashrc, .bash_profile or in your shell for your localized packages to be available in Python.

Use Continuum Anaconda Python for Math, Science, Data, or Personal Projects

If you are using Python for either math, science, or data, then IMO a really good option is the Anaconda-Python Distribution or the more basic miniconda distro released by Anaconda, Inc. (previously known as Continuum Analytics). Although anyone could benefit from using Anaconda for personal projects, the default installation includes over 500 math and science packages like NumPy, SciPy, Pandas, and Matplotlib, while miniconda only installs Anaconda-Python and the conda environment manager. Anaconda only installs into your personal profile, ie: /home/<user>/ and alters your ~/.bashrc or ~/.bash_profile to prepend Anaconda's path to your personal $PATH recommends sourcing conda.sh in your ~/.bashrc which lets you use conda activate <env|default is base> to start anaconda - this only affects you - your system path is unchanged. Therefore you do not need root access or sudo to use Anaconda! If you have already added Anaconda-Python, miniconda, or conda to your personal path, then you should remove the PATH export from your ~/.bashrc, and update to the new recommendation, so your system Python will be first again.

This is somewhat similar to the --user option I explained in the last section except it applies to Python as a whole and not just packages. Therefore Anaconda is completely separate from your system Python, it won't interfere with your system Python, and only you can use or change it. Since it installs a new version of Python and all of its libraries you will need at least 200MB of room, but it is very clever about caching and managing libraries which is important for some of the cool things you can do with Anaconda.

Anaconda curates a collection of Python binaries and libraries required by dependencies in an online repository (formerly called binstar), and they also host user packages as different "channels". The package manager used by Anaconda, conda, by default installs packages from Anaconda, but you can signal a different "channel" using the -c option.

Install packages with conda just like pip:

$ conda install -c pvlib pvlib  # install pvlib pkg from pvlib channel

But conda can do so much more! It can also create and manage virtual environments just like virtualenv. Therefore since Anaconda creates virtual environments, the pip package manager can be used to install packages from PyPI into an Anaconda environment without root or sudo. Do not use sudo with Anaconda! Warning! Do be careful though when mixing pip and conda in an Anaconda environment, b/c you will have to manage package dependencies more carefully. Another option to pip in a conda environment is to use the conda-forge channel, but also best to do that in a fresh conda environment with conda-forge as the default channel. As a last resort, if you can't find a package anywhere but on PyPI, consider using --no-deps then install the remaining dependencies manually using conda.

Anaconda is also similar in some ways to Ruby RVM if you're familiar with that tool. Anaconda conda also lets you create virtual environments with different versions of Python. e.g.: conda create -n py35sci python==3.5.2 numpy scipy matplotlib pandas statsmodels seaborn will create a scientific/data-science stack using Python-3.5 in a new environment called py35sci. You can switch environments using conda. Since conda-4.4.0, this is now different to virtualenv which uses source venv/bin/activate, but previous to conda-4.4.0 the conda commands were the same as virtualenv and also used source:

# AFTER conda-4.4 
~/Projects/myproj $ conda activate py35sci

# BEFORE conda-4.4 
~/Projects/myproj $ source activate py35sci

But wait there's more! Anaconda can also install different languages such as R for statistical programming from the Anaconda r channel. You can even set up your own channel to upload package distributions built for conda. As mentioned conda-forge maintains automated builds of many of the packages on PyPI at the conda-forge Anaconda channel.

Epilogue

There are many options for maintaining your Python projects on Linux depending on your personal needs and access. However, if there's any one thing I hope you take away from this answer is that you should never use sudo pip to install Python packages. The use of sudo should be a warning to you to be extra cautious because you will make system wide changes that could have bad consequences. You have been warned.

Good luck and happy coding!

Answer from Mark Mikofski on askubuntu.com
Top answer
1 of 5
55

updated: 2019-05-11: This post mostly mentions virtualenv, but according to the Python doc about module installation, since Python 3.5 "the use of venv is now recommended for creating virtual environments", while virtualenv is an alternative for versions of Python prior to 3.4.

updated: 2018-08-17: since conda-4.4.0 use conda to activate anaconda on all platforms

updated: 2017-03-27: PEP 513 - manylinux binaries for PyPI

updated: 2016-08-19: Continuum Anaconda Option

This is somewhat a duplicate of easy_install/pip or apt-get.

For global Python packages, use either the Ubuntu Software Center, apt, apt-get or synaptic

Ubuntu uses Python for many important functions, therefore interfering with Python can corrupt your OS. This is the main reason I never use pip on my Ubuntu system, but instead I use either Ubuntu Software Center, synaptic, apt-get, or the newer just apt, which all by default install packages from the Ubuntu repository. These packages are tested, usually pre-compiled so they install faster and ultimately designed for Ubuntu. In addition all required dependencies are also installed and a log of installs is maintained so they can be rolled back. I think most packages have corresponding Launchpad repos so you can file issues.

Another reason to use either Ubuntu packages is that sometimes these Python packages have different names depending on where you downloaded them from. Python-chardet is an example of a package which at one time was named one thing on PyPI and another thing in the Ubuntu repository. Therefore doing something like pip install requests will not realize that chardet is already installed in your system because the Ubuntu version has a different name, and consequently install a new version which will corrupt your system in a minor insignificant way but still why would you do that.

In general you only want to install trusted code into your OS. So you should be nervous about typing $ sudo pip <anything-could-be-very-bad>.

Lastly some things are just easier to install using either Ubuntu packages. For example if you try pip install numpy to install numpy & scipy unless you have already installed gfortran, atlas-dev, blas-dev and lapack-dev, you will see an endless stream of compile errors. However, installing numpy & scipy through the Ubuntu repository is as easy as...

$ sudo apt-get install python-numpy python-scipy

You are in luck, because you are using Ubuntu, one of the most widely supported and oft updated distributions existing. Most likely every Python package you will need is in the Ubuntu repository, and probably already installed on your machine. And every 6 months, a new cycle of packages will be released with the latest distribution of Ubuntu.

If you are 100% confident that the package will not interfere with your Ubuntu system in any way, then you can install it using pip and Ubuntu is nice enough to keep these packages separate from the distro packages by placing the distro packages in a folder called dist-packages/. Ubuntu repository has both pip, virtualenv and setuptools. However, I second Wojciech's suggestion to use virtualenv.

For personal Python projects use pip and wheel in a virtualenv

If you need the latest version, or the module is not in the Ubuntu repository then start a virtualenv and use pip to install the package. Although pip and setuptools have merged, IMO pip is preferred over easy-install or distutils, because it will always wait until the package is completely downloaded and built before it copies it into your file system, and it makes upgrading or uninstalling a breeze. In a lot of ways it is similar to apt-get, in that it generally handles dependencies well. However you will may have to handle some dependencies yourself, but since PEP 513 was adopted there are now manylinux binaries at the Python Package Index (PyPI) for popular Linux distros like Ubuntu and Fedora. for example as mentioned above for NumPy and SciPy make sure you have installed gfortran, atlas-dev, blas-dev and lapack-dev from the Ubuntu repository For example, both NumPy and SciPy are now distributed for Ubuntu as manylinux wheels by default using OpenBLAS instead of ATLAS. You can still build them from source by using the pip options --no-use-wheel or --no-binary <format control>.

~$ sudo apt-get install gfortran libblas-dev liblapack-dev libatlas-dev python-virtualenv
~$ mkdir ~/.venvs
~$ virtualenv ~/.venvs/my_py_proj
~$ source ~/.venvs/my_py_proj/bin/activate
~(my_py_proj)$ pip install --no-use-wheel numpy scipy

See the next section, "You're not in sudoers", below for installing updated versions of pip, setuptools, virtualenv or wheels to your personal profile using the --user installation scheme with pip. You can use this to update pip for your personal use as J.F. Sebastian indicated in his comment to another answer. NOTE: the -m is really only necessary on MS Windows when updating pip.

python -m pip install --user pip setuptools wheel virtualenv

Newer versions of pip automatically cache wheels, so the following is only useful for older versions of pip. Since you may end up installing these many times, consider using wheel with pip to create a wheelhouse. Wheel is already included in virtualenv since v13.0.0 therefore if your version of virtualenv is too old, you may need to install wheel first.

~(my_py_proj)$ pip install wheel  # only for virtualenv < v13.0.0
~(my_py_proj)$ pip wheel --no-use-wheel numpy scipy

This will create binary wheel files in <cwd>/wheelhouse, use -d to specify a different directory. Now if you start another virtualenv and you need the same packages you've already built, you can install them form your wheelhouse using pip install --find-links=<fullpath>/wheelhouse

Read Installing Python Modules in the Python documentation and Installing packages on the Python Package Index main page. Also pip, venv, virtualenv and wheel.

If you're not in sudoers and virtualenv isn't installed.

Another option to using a virtual environment, or if you are using a Linux share without root privileges, then using either the --user or --home=<wherever-you-want> Python installation schemes with Python's distutils will install packages to the value of site.USERBASE or to wherever you want. Newer versions of pip also have a --user option. Do not use sudo!

pip install --user virtualenv

If your Linux version of pip is too old, then you can pass setup options using --install-option which is useful for passing custom options to some setup.py scripts for some packages that build extensions, such as setting the PREFIX. You may need to just extract the distribution and use distutils to install the package the old-school way by typing python setup install [options]. Reading some of the install documentation and the distutils documentation may help.

Python is nice enough to add site.USERBASE to your PYTHONPATH ahead of anything else, so the changes will only effect you. A popular location for --home is ~/.local. See the Python module installation guide for the exact file structure and specifically where your site-packages are. Note: if you use the --home installation scheme then you may need to add it to the PYTHONPATH environment variable using export in your .bashrc, .bash_profile or in your shell for your localized packages to be available in Python.

Use Continuum Anaconda Python for Math, Science, Data, or Personal Projects

If you are using Python for either math, science, or data, then IMO a really good option is the Anaconda-Python Distribution or the more basic miniconda distro released by Anaconda, Inc. (previously known as Continuum Analytics). Although anyone could benefit from using Anaconda for personal projects, the default installation includes over 500 math and science packages like NumPy, SciPy, Pandas, and Matplotlib, while miniconda only installs Anaconda-Python and the conda environment manager. Anaconda only installs into your personal profile, ie: /home/<user>/ and alters your ~/.bashrc or ~/.bash_profile to prepend Anaconda's path to your personal $PATH recommends sourcing conda.sh in your ~/.bashrc which lets you use conda activate <env|default is base> to start anaconda - this only affects you - your system path is unchanged. Therefore you do not need root access or sudo to use Anaconda! If you have already added Anaconda-Python, miniconda, or conda to your personal path, then you should remove the PATH export from your ~/.bashrc, and update to the new recommendation, so your system Python will be first again.

This is somewhat similar to the --user option I explained in the last section except it applies to Python as a whole and not just packages. Therefore Anaconda is completely separate from your system Python, it won't interfere with your system Python, and only you can use or change it. Since it installs a new version of Python and all of its libraries you will need at least 200MB of room, but it is very clever about caching and managing libraries which is important for some of the cool things you can do with Anaconda.

Anaconda curates a collection of Python binaries and libraries required by dependencies in an online repository (formerly called binstar), and they also host user packages as different "channels". The package manager used by Anaconda, conda, by default installs packages from Anaconda, but you can signal a different "channel" using the -c option.

Install packages with conda just like pip:

$ conda install -c pvlib pvlib  # install pvlib pkg from pvlib channel

But conda can do so much more! It can also create and manage virtual environments just like virtualenv. Therefore since Anaconda creates virtual environments, the pip package manager can be used to install packages from PyPI into an Anaconda environment without root or sudo. Do not use sudo with Anaconda! Warning! Do be careful though when mixing pip and conda in an Anaconda environment, b/c you will have to manage package dependencies more carefully. Another option to pip in a conda environment is to use the conda-forge channel, but also best to do that in a fresh conda environment with conda-forge as the default channel. As a last resort, if you can't find a package anywhere but on PyPI, consider using --no-deps then install the remaining dependencies manually using conda.

Anaconda is also similar in some ways to Ruby RVM if you're familiar with that tool. Anaconda conda also lets you create virtual environments with different versions of Python. e.g.: conda create -n py35sci python==3.5.2 numpy scipy matplotlib pandas statsmodels seaborn will create a scientific/data-science stack using Python-3.5 in a new environment called py35sci. You can switch environments using conda. Since conda-4.4.0, this is now different to virtualenv which uses source venv/bin/activate, but previous to conda-4.4.0 the conda commands were the same as virtualenv and also used source:

# AFTER conda-4.4 
~/Projects/myproj $ conda activate py35sci

# BEFORE conda-4.4 
~/Projects/myproj $ source activate py35sci

But wait there's more! Anaconda can also install different languages such as R for statistical programming from the Anaconda r channel. You can even set up your own channel to upload package distributions built for conda. As mentioned conda-forge maintains automated builds of many of the packages on PyPI at the conda-forge Anaconda channel.

Epilogue

There are many options for maintaining your Python projects on Linux depending on your personal needs and access. However, if there's any one thing I hope you take away from this answer is that you should never use sudo pip to install Python packages. The use of sudo should be a warning to you to be extra cautious because you will make system wide changes that could have bad consequences. You have been warned.

Good luck and happy coding!

2 of 5
32

I think best way for you would be to install Python packaging system like "python-pip". You can install it with Synaptic or Ubuntu Software Center.

Pip will allow you to easy install and uninstall Python packages, simply as pip install package. In your case it would be something like this from terminal:

sudo pip install tweeststream
🌐
Reddit
reddit.com › r/ubuntu › help with installing python packages on ubuntu 24.04.
r/Ubuntu on Reddit: Help with installing Python packages on Ubuntu 24.04.
August 9, 2024 -

I'm trying to install a few python packages on my Ubuntu 24.04 machine running KDE Plasma, the Python interpreter can be invoked with python3 in a terminal window, however, using pip or pip3 to install a package, it returns this error:

$ pip3 install pytube
error: externally-managed-environment

× This environment is externally managed
╰─> To install Python packages system-wide, try apt install
    python3-xyz, where xyz is the package you are trying to
    install.
    
    If you wish to install a non-Debian-packaged Python package,
    create a virtual environment using python3 -m venv path/to/venv.
    Then use path/to/venv/bin/python and path/to/venv/bin/pip. Make
    sure you have python3-full installed.
    
    If you wish to install a non-Debian packaged Python application,
    it may be easiest to use pipx install xyz, which will manage a
    virtual environment for you. Make sure you have pipx installed.
    
    See /usr/share/doc/python3.12/README.venv for more information.

note: If you believe this is a mistake, please contact your Python installation or OS distribution provider. You can override this, at the risk of breaking your Python installation or OS, by passing --break-system-packages.
hint: See PEP 668 for the detailed specification.

i've read here (https://docs.python-guide.org/dev/virtualenvs/#virtualenvironments-ref) that i can use pipenv to install packages only for my projects, rather than installing them system-wide, but it requires pip, which i can't access due to the error.

when creating a virtual environment in VS Code i can choose between 2 interpreters:

i chose the "Global" one and it doesn't let me create it. Returns an error:

VenvError: CREATE_VENV.VENV_FAILED_CREATION
2024-08-09 19:47:57.063 [error] Error while running venv creation script:  CREATE_VENV.VENV_FAILED_CREATION
2024-08-09 19:47:57.064 [error] CREATE_VENV.VENV_FAILED_CREATION
Discussions

linux - Installing python modules on Ubuntu - Stack Overflow
I need to install some modules for python on Ubuntu Linux 12.04. I want pygame and livewires but I'm not sure how to install them. I have the py file for livewires, which has been specially edited (from a book I'm reading) and I want to install it but I'm not sure how to, I also want to install pygame. ... to use the Debian/Ubuntu package ... More on stackoverflow.com
🌐 stackoverflow.com
Installing 3rd party Python modules on an Ubuntu Linux machine? - Stack Overflow
Installing pip...............done. ... installed mechanize Cleaning up... daniel@redhotcar:~/tmp/myenv$ bin/python Python 2.7.2+ (default, Oct 4 2011, 20:06:09) [GCC 4.6.1] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import mechanize >>> mechanize >>> On Ubuntu, install ... More on stackoverflow.com
🌐 stackoverflow.com
How do I install python?
Chances are it's already installed. In terminal you can type python3 --version and it will tell you if it is installed already. More on reddit.com
🌐 r/Ubuntu
11
4
February 25, 2021
[Ubuntu/Linux, default python 3.10.4] best way to install Python 3.8 and create venv with it?
i have used conda to generate python2+ envs under python3+ so it should be able to handle 3.8 from 3.10 https://i.imgur.com/AQ3kBh4.png https://docs.conda.io/projects/conda/en/4.6.0/_downloads/52a95608c49671267e40c689e0bc00ca/conda-cheatsheet.pdf More on reddit.com
🌐 r/learnpython
7
1
June 13, 2022
🌐
Python Packaging
packaging.python.org › tutorials › installing-packages
Installing Packages — Python Packaging User Guide
While pip alone is sufficient to install from pre-built binary archives, up to date copies of the setuptools and wheel projects are useful to ensure you can also install from source archives: ... See section below for details, but here’s the basic venv 3 command to use on a typical Linux system: ... This will create a new virtual environment in the tutorial_env subdirectory, and configure the current shell to use it as the default python environment. Python “Virtual Environments” allow Python packages to be installed in an isolated location for a particular application, rather than being installed globally.
Top answer
1 of 5
11

You aren't supposed to manually install anything.

There are three ways to install Python libraries:

  1. Use apt-get, aptitude or similar utilities.
  2. Use easy_install or pip (install pip first, its not available by default)
  3. If you download some .tar.gz file, unzip it and then type sudo python setup.py install

Manually messing with paths and moving files around is the first step to headaches later. Do not do it.

For completeness I should mention the portable, isolated way; that is to create your own virtual environment for Python.

  1. Run sudo apt-get install python-virtualenv
  2. virtualenv myenv (this creates a new virtual environment. You can freely install packages in here without polluting your system-wide Python libraries. It will add (myenv) to your prompt.)
  3. source myenv/bin/activate (this activates your environment; making sure your shell is pointing to the right place for Python)
  4. pip install _____ (replace __ with whatever you want to install)
  5. Once you are done type deactivate to reset your shell and environment to the default system Python.
2 of 5
10

virtualenv is the de facto Python standard for installing third party library cleanly. Read more about it here: http://www.virtualenv.org/

Usage example:

daniel@redhotcar:~/tmp$ virtualenv myenv
New python executable in myenv/bin/python
Installing distribute....................................................................................................................................................................................done.
Installing pip...............done.
daniel@redhotcar:~/tmp$ cd myenv/
daniel@redhotcar:~/tmp/myenv$ bin/pip install mechanize
Downloading/unpacking mechanize
  Downloading mechanize-0.2.5.zip (445Kb): 445Kb downloaded
  Running setup.py egg_info for package mechanize

Installing collected packages: mechanize
  Running setup.py install for mechanize

Successfully installed mechanize
Cleaning up...
daniel@redhotcar:~/tmp/myenv$ bin/python
Python 2.7.2+ (default, Oct  4 2011, 20:06:09) 
[GCC 4.6.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import mechanize
>>> mechanize
<module 'mechanize' from '/home/daniel/tmp/myenv/local/lib/python2.7/site-packages/mechanize/__init__.pyc'>
>>> 

On Ubuntu, install virtualenv via apt-get install python-virtualenv

🌐
BitLaunch
bitlaunch.io › blog › how-to-install-python-on-ubuntu
7 Ways to Install and Manage Python and Python3 on Ubuntu
December 17, 2025 - You can install pipx on Ubuntu ... cd projectname python3 -m venv myenv source myenv/bin/activate · You can then use pip to install packages, for example:...
🌐
PhoenixNAP
phoenixnap.com › home › kb › sysadmin › how to install python 3 on ubuntu
How to Install Python 3 on Ubuntu | phoenixNAP KB
June 12, 2025 - The Deadsnakes PPA has many Python versions in its database and allows you to install older versions as well. Specify the version in the package name to install that version. For example, run this command to install Python 3.12: ... The output states the program version you chose to install. ... This article explained how to install Python 3 on your Ubuntu system.
Find elsewhere
🌐
MakeUseOf
makeuseof.com › home › linux › how to install python in ubuntu [3.12]
How to Install Python in Ubuntu [3.12]
June 30, 2023 - Here are some of the recommended ways: APT, or Advanced Package Tool is the default package manager on Ubuntu and other Debian-based distros. You can download the Python package from the official Ubuntu repository.
🌐
Ubuntu
documentation.ubuntu.com › ubuntu-for-developers › howto › python-setup
How to set up a development environment for Python on Ubuntu - Ubuntu for Developers
2 weeks ago - To get a more useful runtime environment, use the special dependency package, python3-full, which automatically installs the interpreter with the complete class library, support for Python virtual environments (venv), and the basic Python IDE (IDLE).
🌐
LinuxShout
linux.how2shout.com › home › how to install python library in ubuntu linux
How to install Python library in Ubuntu Linux - LinuxShout
May 12, 2023 - Follow the given commands in this tutorial to install the Python libraries on Ubuntu 22.04 or 20.04 using PIP package manager and terminal.
🌐
GeeksforGeeks
geeksforgeeks.org › how-to-install-python-in-ubuntu
How to install Python in Ubuntu (3 Methods to install ) - GeeksforGeeks
June 21, 2025 - Replace [version number] with the Python version you want to be installed in your Ubuntu system. On the Linux Terminal, the following command will be used. It will start accessing the Repository of the Python Module. ... Now, the following command execution will download the Python Package on the device.
🌐
Hostinger
hostinger.com › home › tutorials › how to install python pip on ubuntu
How to install Python pip on Ubuntu
July 9, 2025 - Learn how to install pip Python package manager on Ubuntu: 1. Connect to your server 2. Update system repository 3. Install pip + more
🌐
Ubuntu
documentation.ubuntu.com › ubuntu-for-developers › tutorials › python-use
Develop with Python on Ubuntu - Ubuntu for Developers
2 weeks ago - If you wish to install a non-Debian-packaged Python package, create a virtual environment using python3 -m venv path/to/venv. Then use path/to/venv/bin/python and path/to/venv/bin/pip. Make sure you have python3-full installed. If you wish to install a non-Debian packaged Python application, ...
🌐
Linuxize
linuxize.com › home › python › how to install python pip on ubuntu 20.04
How to Install Python Pip on Ubuntu 20.04 | Linuxize
April 27, 2020 - Use pip to install a module globally only if there is no deb package for that module. Prefer using pip within a virtual environment only. Python Virtual Environments allows you to install Python modules in an isolated location for a specific project, rather than being installed globally. This way, you do not have to worry about affecting other Python projects. To install pip for Python 3 on Ubuntu 20.04 run the following commands as root or sudo user in your terminal:
🌐
Christopher5106
christopher5106.github.io › python › 2017 › 10 › 12 › python-packages-and-their-managers-apt-yum-easy_install-pip-virtualenv-conda.html
Python packages and their managers: Ubuntu APT, yum, easy_install, pip, virtualenv, conda
October 12, 2017 - For pip3, the package is direcly installed locally: /home/christopher/.local/lib/python3.5/site-packages/numpy ... In recent Ubuntu versions, by default, pip installs the package locally.
🌐
BlueVPS
bluevps.com › blog › how to install python on ubuntu 22.04? (a complete step-by-step guide)
How to Install Python on Ubuntu 22.04
There are multiple ways to install Python on Ubuntu: ... This method uses the APT package manager and the default Ubuntu repositories to install Python. It's the simplest method, but it might not always provide the most recent version of Python.
🌐
Cherry Servers
cherryservers.com › home › blog › cloud computing › how to install pip on ubuntu 22.04 | step-by-step
How to Install PIP on Ubuntu 22.04 | Step-by-Step | Cherry Servers
February 20, 2026 - In this step-by-step guide, we will walk you through how to install pip on Ubuntu 22.04. In addition, you will also learn how to install and uninstall Python packages using pip, as well as how to upgrade it to the latest version.
🌐
Cherry Servers
cherryservers.com › home › blog › linux › how to install pip on ubuntu 24.04: step-by-step guide
How to Install PIP on Ubuntu 24.04: Step-by-Step Guide | Cherry Servers
November 7, 2025 - Also read: How to Install Anaconda on Ubuntu 22.04 · With the virtual environment activated, use the following syntax to install packages: ... Additionally, you can install multiple packages saved in a text file. To do so, create a requirements.txt file. ... Specify the packages and their versions. ... Save the changes and exit the file. Finally, run the pip command as shown to install all the specified packages. ... Once done with your Python project, you can exit the virtual environment by deactivating it as follows
🌐
MangoHost
mangohost.net › mangohost blog › guide to install python on ubuntu
Guide to Install Python on Ubuntu
February 12, 2024 - To install Python on Ubuntu, you can use the package manager called apt.
🌐
The Hitchhiker's Guide to Python
docs.python-guide.org › starting › install3 › linux
Installing Python 3 on Linux — The Hitchhiker's Guide to Python
If you’re using another version ... Python 3.8: $ sudo apt-get install software-properties-common $ sudo add-apt-repository ppa:deadsnakes/ppa $ sudo apt-get update $ sudo apt-get install python3.8 · If you are using other ...