简体   繁体   English

来自tar.gz的Python导入库?

[英]Python import library from tar.gz?

I am working on a box which I don't have root access. 我正在开发一个我没有root访问权限的盒子。 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. 我想找出一种方法来放置python库,以便每个人都可以访问和使用它们。

I figured out that I can put the egg file in the /share/pythonLib folder and in the python script. 我发现我可以将egg文件放在/ share / pythonLib文件夹和python脚本中。

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. 例如,我正在尝试安装BeautifulSoup4 ,但是,只有tar.gz文件,我不确定是否可以转换为egg和..etc。

OR! 要么! I am wrong right at the BEGINNING, and there are indeed some pythonic magics like below: 我在BEGINNING错了,确实有一些如下的pythonic魔法:

magicadd /share/pythonLib/foo.tar.gz
import foo

tar.gz is the source code of the library. tar.gz是该库的源代码。 You should unpack it, and you will find a setup.py script inside. 你应该解压缩它,你会在里面找到一个setup.py脚本。 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. 在你的脚本中追加到sys.path路径,一切都应该正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM