Installing python modules on Ubuntu

2019-01-22 08:34发布

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.

6条回答
劫难
2楼-- · 2019-01-22 09:17
 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

查看更多
狗以群分
3楼-- · 2019-01-22 09:20

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)

查看更多
倾城 Initia
4楼-- · 2019-01-22 09:26

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.

查看更多
再贱就再见
5楼-- · 2019-01-22 09:33

Try to install pip.

apt-get install python-pip
pip install pygame
查看更多
地球回转人心会变
6楼-- · 2019-01-22 09:34

Just have a look a askubuntu.

E.g. this post exactly covers your problem.

For ubuntu there are a lot of excellent sites on the net :-)

查看更多
唯我独甜
7楼-- · 2019-01-22 09:38

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.

查看更多
登录 后发表回答