8

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
B.Mr.W.
  • 18,910
  • 35
  • 114
  • 178
  • How about install the package to the shared directory? If you are using pip, try `pip install -t /share/pythonLib BeautifulSoup4`. – falsetru Aug 11 '13 at 15:32
  • OSError:[Errno13] Permission denied: '/usr/lib/python..../__init__.pyc' Seems like it still trying to touch some file that it should not touch – B.Mr.W. Aug 11 '13 at 15:58
  • It seems like beautifulsoup is already installed globally in your system. pip tries to delete old installation. – falsetru Aug 11 '13 at 16:03
  • foo.egg is a directory created after the install, right? So how is adding the foo.egg directory to sys.path any different than adding a regular directory created by an install? – 7stud Aug 11 '13 at 17:43
  • @falsetru You are right open sudo with python, can you can import beautifulsoup, however, log in as normal user, it says Import Error: No module named BeautifulSoup4. – B.Mr.W. Aug 11 '13 at 17:44

1 Answers1

6

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.

Viktor Kerkez
  • 45,070
  • 12
  • 104
  • 85