19

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.

1
  • import looks in the program's directory so put livewire there. Commented Nov 13 at 18:17

7 Answers 7

28

There are two nice ways to install Python packages on Ubuntu (and similar Linux systems):

sudo apt-get install python-pygame 

to use the Debian/Ubuntu package manager APT. This only works for packages that are shipped by Ubuntu, unless you change the APT configuration, and in particular there seems to be no PyGame package for Python 3.

The other option is to use PIP, the Python package manager:

sudo apt-get install python3-pip 

to install it, then

sudo pip3 install pygame 

to fetch the PyGame package from PyPI and install it for Python 3. PIP has some limitations compared to APT, but it does always fetch the latest version of a package instead of the one that the Ubuntu packagers have chosen to ship.

EDIT: to repeat what I said in the comment, pip3 isn't in Ubuntu 12.04 yet. It can still be installed with

sudo apt-get install python3-setuptools sudo easy_install3 pip sudo apt-get purge python-pip 

After this, pip is the Python 3 version of PIP, instead of pip3. The last command is just for safety; there might be a Python 2 PIP installed as /usr/bin/pip.

Sign up to request clarification or add additional context in comments.

5 Comments

Does it automatically import it into my python file, so i can straight away start using pygame?
@Infamouslyuseless: both options install packages into a location where you can import from, if you haven't done crazy things to your Python setup.
It doesn't work, it says "E: unable to locate package python3-pip"
"E: Invalid operation python3-setuptools" is what i got after i did "sudo apt-get python3-setuptools"...
7
+150

Try to install pip.

apt-get install python-pip pip install pygame 

Comments

3

It depends on the Ubuntu version and the IDE you are using. Ubuntu 15 and older come with Python 2.7 and Ubuntu 16.04 comes with both Python 2.7 and 3.5. Now based on the IDE you are using there are several ways to do this. Let`s say you only installed Spyder from Ubuntu app store or installed Jupyter. In other words you do not have a distribution like Anaconda or Enthought which install their own Python versions. This is important to pay attention to because once you are trying to install a package/library, you need to know which Python it is being installed to.

Now assuming you just have an IDE that is connected to Ubuntu`s default Python versions, you can use the terminal to install your packages:

For python 2.7 use

pip install libraryname 

For python 3.5 use

pip3 install libraryname 

Sometimes, for reasons that I don`t know, during the package installation process, Linux blocks access to the Python so try these as well:

sudo apt install python-libraryname 

and for Python 3.5

sudo apt install python3-libraryname 

These have helped me to install all the libraries that I need.

Now, if you are using a distribution like Aanaconda or Enthought, there is a good chance that the libraries that you are installing are not going to be added to the libraries that those distributions use. In order to install the libraries for these distributions, once you run the distribution, go to the ipython console and write

!pip install libraryname 

In case of Enthought, it has it`s own Package Manager where it has most of the libraries you need and you can install them there without using pip or anything else.

Comments

2

You can use several approaches:

1 - Download the package by yourself. This is what I use the most. If the package follows the specifications, you should be able to install it by moving to its uncompressed folder and typing in the console:

python setup.py build python setup.py install 

2 - Use pip. Pip is pretty straightforward. In the console, you have to type:

pip install package_name 

You can obtain pip here https://pypi.python.org/pypi/pip and install it with method 1

One thing to note: if you aren't using a virtualenv, you'll have to add sudo before those commands (not recommended)

Comments

0
 curl -O http://python-distribute.org/distribute_setup.py sudo python distribute_setup.py sudo easy_install pygame 

Differences between distribute, distutils, setuptools and distutils2

1 Comment

This should now be clearly marked as obsolete. The distribute installation wrapper now simply installs setuptools instead.
0

It's most recommended to use a Virtual Environment :

$ python3 -m venv .venv $ source .venv/bin/activate $ pip3 install pygame some_other_package other_package 

Then add this to the top of your python file: import pygame, some_other_package, other_package

Finally run $ python3 python_file.py.

Comments

-1

You release is so old and unsupported since 2019, that the official docs don't even mention the available Python packages for Version 12: Available Python versions - Ubuntu for Developers

Python 3 was added to Ubuntu only at version 14.10 - Python/3 - Ubuntu Wiki

Is there a good reason to remain on that version, considering hundreds of exploitable security vulnerabilites - Canonical Ubuntu Linux 12.04 security vulnerabilities, CVEs?

4 Comments

You're answering a 12 year old question...
LOL. I guess I should get more sleep the next time :D
why is it bountied tho
I didn't even notice that. Weird thing to bounty

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.