3

Good afternoon.

I am writing a small to medium-sized python program for my job. The task requires me to use the Excel libraries xlwt and xlrd, as well as a library for querying Oracle databases, called cx_Oracle. I am developing the project through a version control system, namely CVS.

I was wondering what is the standard way to organize third-party libraries around a python project. Should the libraries xlwt, xlrd, and cx_Oracle be stored in a directory such as /usr/local/lib/python, which presumably has its place in the PYTHONPATH? Or should the third-party libraries instead be included in the same directory as the source code of the project, effectively "shipped out" with the project, that way the python script is more platform-independent.

I am just looking for best practices since I am coming from Java and am new to Python.

Thanks in advance,
ktm

4

1 回答 1

6

您基本上有两个选择(就像您可能从 Java 中认识到的那样)。

一种是将外部依赖项打包到你的应用程序中,这意味着你将所有依赖项复制到你的应用程序目录结构中。通常不建议这样做,除非您必须能够发布单个安装或二进制文件。在这种情况下,您必须能够处理所有支持的平台。

处理依赖项的更好方法是记录您的应用程序依赖项是什么。一种方法是定义一个 pip 格式的 requirements.txt 文件,然后可以运行该文件pip install -r requirements.txt,它将继续安装所有依赖项。Buildout是您可以使用的另一种选择。

于 2011-05-02T21:18:30.173 回答