从tar.gz的Python导入库? [英] Python import library from tar.gz?

查看:272
本文介绍了从tar.gz的Python导入库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在一个没有root访问权限的盒子上工作.但是,有一个/share文件夹,每个人都可以访问该文件夹以进行读写.

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.

我想找到一种放置python库的方法,以便每个人都可以访问和使用它们.

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

我发现可以将egg文件放在/share/pythonLib文件夹和python脚本中.

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

,它对每个人都适用,但是,我不确定每个库都有egg版本.例如,我正在尝试安装 BeautifulSoup4 ,但是,只有tar.gz文件,我不确定是否可以转换为egg和..etc.

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.

或!我在开始时就错了,确实有一些类似python的魔术:

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

推荐答案

tar.gz是该库的源代码.您应该打开它的包装,然后在其中找到一个setup.py脚本.运行:

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

这将创建:

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

在您的脚本中,将该路径附加到sys.path,一切都应该正常工作.

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

这篇关于从tar.gz的Python导入库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆