Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

What is the best way to install python packages in Ubuntu 11? I am a recent convert to Ubuntu and want to learn best practices.

For context, I am looking to install the tweeststream package, but I did not see it in my Synaptic package manager. Also, I am very new to programming but usually can follow along with code samples.

share|improve this question
up vote 18 down vote accepted

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

share|improve this answer
This is fine for simple packages, but not so good for larger packages e.g. numpy – hayd Oct 25 '13 at 18:03
@hayd: why? Is that related to… – naught101 Mar 11 '15 at 3:57
@naught101 I think I probably meant scipy, not sure if it's related... looks like pip is too late in the python path. I strongly recommend using anaconda/conda, it's vastly superior to pip IMO. – hayd Mar 12 '15 at 2:47
IMHO using sudo pip <anything> should be used very carefuly. Since tweetstream isn't in the Ubuntu Software Center, I recommend using a virtualenv. tweetstream's requires anyjson which is an Ubuntu Package. Not installing tweetstream in a virtualenv may cause other Ubuntu apps dependent on anyjson to fail. Troubleshoot hard. – Mark Mikofski Sep 30 '15 at 16:43
To repeat: don't use sudo pip on Ubuntu. @MarkMikofski: you don't need virtualenv (unless you want it for some specific reason). python -mpip install --user package-name can install the package packafe-name for the current user. If there are complex (large C extensions) dependencies; you could install them using apt-get, to avoid installing build dependencies unless necessary. – J.F. Sebastian Feb 23 at 20:18

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

For global Python packages, use either the Ubuntu Software Center, 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 using pip on my Ubuntu system, but instead I use either Ubuntu Software Center, synaptic or apt-get, 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-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 have to handle some dependencies yourself, 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.

~$ 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 wheel numpy scipy

Since you may end up installing these many times, consider using wheel with pip to create a wheelhouse

~(my_py_proj)$ pip 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 them and you can install them form your wheelhouse using pip install --find-links=<fullpath>/wheelhouse

Read Installing Python Modules in the Python documentation and Get Packages on the Python Package Index main page. Also pip, 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 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 pacakges to be available in Python.

share|improve this answer

In addition to Novarchibald's addition, it is generally a good idea to create a virtual environment for your python project and install dependencies inside. This allows you to have better control over dependencies and their versions. To set up a virtual environment, enter:

virtualenv --no-site-packages --distribute my_python_project

Then, activate it with:

cd my_python_project
source bin/activate

At this point anything that you install with pip will be kept inside this virtual environment. If you want to install something globally, then you should first exit virtualenv with:


You can find out more about virtualenv here.

share|improve this answer
Alternatively: using the pip from the virtualenv bin directory (here my_python_project/bin/pip) you maintain that environment, without a need to "activate" it. Then - using any of scripts installed in the bin is using given virutalenv. "activate" is only handy to make calls to "python", "easy_install" and "pip" using virtualenv specific bin. – Jan Vlcinsky Jun 17 '13 at 11:54
Python's install docs say to use "pyvenv" to create virtual environments specific to a project; but that virtualenv is a fall back for projects using older python version, – pbhj Nov 25 '14 at 1:03
Note that the virtualenv options --no-site-packages and --distribute are deprecated nowadays and have no effect any longer. – Forage Aug 8 '15 at 14:41

In addition to Zetah'a answer, command to install python-pip from terminal is:

sudo apt-get install python-pip
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.