问题
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
回答1:
You basically have two options (just like you might recognize from Java).
One is to packaged the external dependencies in your app, meaning you copy all the dependencies into your apps directory structure. This is usually not recommended unless you must be able to ship a single installation or binary. In this case, you must be able to handle all supported platforms.
The better way to handle dependencies is to document what your apps dependencies are. One way to do this is to define a requirements.txt file in the pip format which can then be run by pip install -r requirements.txt
, which will proceed to install all dependencies. Buildout is another option you can go with.
来源:https://stackoverflow.com/questions/5862566/whats-the-best-practice-for-incorporating-third-party-libraries-in-a-python-pro