在Python应用程序中包含一个库 [英] Include a library in python application

查看:183
本文介绍了在Python应用程序中包含一个库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找到一种将库包含在Ubuntu / Python / PyGtk应用程序中的方法,即使它未包含在股票python环境中,我也无法将它作为依赖项添加到我的setup.py文件中。这个库叫做 pygal ,并且有一个PIP包(没有可用的.deb或ppa),但我正在寻找一种方法将其包含在我的应用程序中。我想我可以将源.py文件包含到库中,但我不确定如何将其包含在我的代码中。 Pygal还需要lxml python库。我可以通过pip在我的机器上安装它,它工作正常,但不知道是否有自动化或将其包含在我的.deb包的setup.py文件中。任何帮助或建议将不胜感激。

解决方案

我认为这应该工作,虽然我不知道。
您将名为 pygal 的文件夹放在应用程序目录中的pygal egg中。你可以从你的python安装中获取它 - 它应该有这个路径:

  /usr/local/lib/python2.7/ dist-packages / pygal-0.13.0-py2.7.egg / pygal 

或者如果您使用python 3.1

  /usr/local/lib/python3.1/dist-packages/pygal-0.13.0-py3.1 .egg / pygal 

或从 pipy

您可以像使用任何python库一样使用它:

  from pygal import * 


I am trying to find a way to include a library in a Ubuntu/Python/PyGtk application even though It is not included in the stock python enviornment and I can't add it as a dependency in my setup.py file. The library is called pygal and does have a PIP package (No available .deb or ppa) but I was looking for a way to include it in my application. I would think I could just include the source .py files to the library but I am unsure of how to go about including it in my code. Pygal also requires the lxml python library. I can install it via pip on my machine and it works fine but didn't know if there was anyway to automate or include this in my .deb package's setup.py file. Any help or advice would be greatly appreciated.

解决方案

I think this should work though I'm not sure. You put the folder with the name pygal from the pygal egg in your application directory. You can take it from your python installation - it should have this path:

/usr/local/lib/python2.7/dist-packages/pygal-0.13.0-py2.7.egg/pygal

or if you use python 3.1

/usr/local/lib/python3.1/dist-packages/pygal-0.13.0-py3.1.egg/pygal

or download it from pipy.

You can use it like any python library:

from pygal import *

这篇关于在Python应用程序中包含一个库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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