Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python import library from tar.gz?

Tags:

python

path

tar

egg

I am working on a box which I don't have root access. However, there is a folder /share which would be accessed for everyone to read and write.

I want to figure out a way to put python libraries so that everyone could access and use them.

I figured out that I can put the egg file in the /share/pythonLib folder and in the python script.

import sys
sys.path.append("/share/pythonLib/foo.egg")
import foo

and it would work for everyone, however, I am not sure every library has egg version. For example, I am trying to install BeautifulSoup4 , however, there is only tar.gz file and I am not sure if it would be possible to convert to egg and ..etc.

OR! I am wrong right at the BEGINNING, and there are indeed some pythonic magics like below:

magicadd /share/pythonLib/foo.tar.gz
import foo
like image 345
B.Mr.W. Avatar asked Aug 11 '13 15:08

B.Mr.W.


People also ask

How do I import a tar GZ file?

Import TAR.Find and select the compressed TAR. GZ files on your computer and click Open to bring them into Express Zip to extract them. You can also drag and drop your TAR. GZ files directly into the program to extract them as well.

How do I read a tar file in Python?

You can use the tarfile module to read and write tar files. To extract a tar file, you need to first open the file and then use the extract method of the tarfile module.


1 Answers

tar.gz is the source code of the library. You should unpack it, and you will find a setup.py script inside. Run:

python setup.py install --prefix=/share/pythonLib

This will create:

/share/pythonLib/lib/python2.7/site-packages/

In your scripts append that path to sys.path and everything should work fine.

like image 167
Viktor Kerkez Avatar answered Sep 23 '22 02:09

Viktor Kerkez