Installing 3rd Party Python Modules On An Ubuntu Linux Machine?
Solution 1:
You aren't supposed to manually install anything.
There are three ways to install Python libraries:
- Use
apt-get
,aptitude
or similar utilities. - Use
easy_install
orpip
(installpip
first, its not available by default) - If you download some
.tar.gz
file, unzip it and then typesudo 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.
- Run
sudo apt-get install python-virtualenv
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.)source myenv/bin/activate
(this activates your environment; making sure your shell is pointing to the right place for Python)pip install _____
(replace __ with whatever you want to install)- Once you are done type
deactivate
to reset your shell and environment to the default system Python.
Solution 2:
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 42011, 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
Solution 3:
You can use
sudo apt-get install python3-library_name
Replace library_name
by any other library (e.g. scipy, pandas, numpy, matplotlib, etc.)
Solution 4:
use setuptools http://pypi.python.org/pypi/setuptools/ then type
pip install <somePackageName>
or
easy_install <somePackageName>
they will look in the pypi directories (on the interwebs) for the package and will install the correct version for you automagically...
Solution 5:
To install nay python package in ubuntu, first run sudo apt-get update
Then type "sudo apt-get install python-" and press tab twice repeatedly. press y or yes and it will display all the packages available for python. Then again type sudo apt-get install python-package It will install the package from the internet.
Post a Comment for "Installing 3rd Party Python Modules On An Ubuntu Linux Machine?"