Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to install a python library manually

I built quickfix engine (http://www.quickfixengine.org/) for one of my tasks and also built in python support for it.

Unfortunately this is a multi user env and I dont have access to the python installation path. Thus the make install command tries to copy over the files and fails. I managed to comment out the two lines where it tries to do that and the make install completed. Since I cannot put the files there, where can I put the .so file created?

And how do I let python know that it is there? I looked at python.org documentation but it only describes the process for setup.py installations.

Also I tried putting the path for the .so in sys.path, that didnt work. And is there any documents about the anatomy of a python package? Thanks.

like image 211
Osada Lakmal Avatar asked Feb 08 '11 12:02

Osada Lakmal


3 Answers

I'm going to assume compiling the QuickFix package does not produce a setup.py file, but rather only compiles the Python bindings and relies on make install to put them in the appropriate place.

In this case, a quick and dirty fix is to compile the QuickFix source, locate the Python extension modules (you indicated on your system these end with a .so extension), and add that directory to your PYTHONPATH environmental variable e.g., add

export PYTHONPATH=~/path/to/python/extensions:PYTHONPATH

or similar line in your shell configuration file.

A more robust solution would include making sure to compile with ./configure --prefix=$HOME/.local. Assuming QuickFix knows to put the Python files in the appropriate site-packages, when you do make install, it should install the files to ~/.local/lib/pythonX.Y/site-packages, which, for Python 2.6+, should already be on your Python path as the per-user site-packages directory.

If, on the other hand, it did provide a setup.py file, simply run

python setup.py install --user

for Python 2.6+.

like image 189
gotgenes Avatar answered Oct 20 '22 21:10

gotgenes


You need to install it in a directory in your home folder, and somehow manipulate the PYTHONPATH so that directory is included.

The best and easiest is to use virtualenv. But that requires installation, causing a catch 22. :) But check if virtualenv is installed. If it is installed you can do this:

$ cd /tmp
$ virtualenv foo
$ cd foo
$ ./bin/python

Then you can just run the installation as usual, with /tmp/foo/python setup.py install. (Obviously you need to make the virtual environment in your a folder in your home directory, not in /tmp/foo. ;) )

If there is no virtualenv, you can install your own local Python. But that may not be allowed either. Then you can install the package in a local directory for packages:

$ wget http://pypi.python.org/packages/source/s/six/six-1.0b1.tar.gz#md5=cbfcc64af1f27162a6a6b5510e262c9d
$ tar xvf six-1.0b1.tar.gz 
$ cd six-1.0b1/
$ pythonX.X setup.py   install --install-dir=/tmp/frotz

Now you need to add /tmp/frotz/pythonX.X/site-packages to your PYTHONPATH, and you should be up and running!

like image 3
Lennart Regebro Avatar answered Oct 20 '22 22:10

Lennart Regebro


Here is the official FAQ on installing Python Modules: http://docs.python.org/install/index.html

There are some tips which might help you.

like image 2
Please treat your mods well. Avatar answered Oct 20 '22 20:10

Please treat your mods well.