Python web 应用常常构建与其他众多程序员的代码之上，不仅仅是开发框架，还包括爬虫、分词、分析、可视化等众多工作。
Python函数库有一个中央存储仓库叫Python Package Index (PyPi)。PyPi可按照相关权重和相关性提供搜索功能。
- Python.org’s useful modules
- GitHub Explore Trending repositories
- 20 Python libraries you can’t live without
- page dedicated to Python libraries
为了预防系统版本冲突，有时候要隔离依赖性，最常用方法是 virtualenv。每一个virtualenv 有自己的一份Python解释器和依赖库，存放在自己的目录下。要使用virtualenv必须先创建并激活。
先创建并激活virtualenv，然后推荐用 pip 安装依赖包。
django==1.6 bpython==0.12 django-braces==0.2.1 django-model-utils==1.1.0 logutils==0.3.3 South==0.7.6 requests==1.2.0 stripe==1.9.1 dj-database-url==0.2.1 django-oauth2-provider==0.2.4 djangorestframework==2.3.1
There is another type of dependency specification for Python libraries known as setup.py. Setup.py is a standard for distributing and installing Python libraries. If you’re building a Python library, such as requests or underwear you must include setup.py so a dependency manager can correctly install both the library as well as additional dependencies for the library. There’s still quite a bit of confusion in the Python community over the difference between requirements.txt and setup.py, so read this well written post for further clarification.
- Python Packaging Is Good Now 介绍了Python包曾经的历史和现在的改进
- virtualenv and pip basics.
- A non-magical introduction to virtualenv and pip
- Tools of the modern Python hacker
- Occasionally arguments about using Python’s dependency manager versus one of Linux’s dependency managers comes up. This provides one perspective on that debate.
- Open source trust scaling is a good piece for the Python community (and other communities) that is based on the left-pad NPM situation that broke many dependent packages in the Node.JS community.
- This Stack Overflow question details how to set up a virtual environment for Python development.
- Another Stack Overflow page answers how to set environment variables when using virtualenv.
- Tips for using pip + virtualenv + virtualenvwrapper shows how to use shell aliases and postactivate virtualenvwrapper hooks to make life easier when using these tools.
- Major speed improvements were made in pip 7 over previous versions. Read this article about the differences and be sure to upgrade.
- How to submit a package to PyPI is a short and sweet introduction that’ll help you quickly get your first package on PyPI.
Open source app dependency projects
- Autoenv is a tool for activating environment variables stored in a
.envfile in your projects’ home directories. Environment variables aren’t managed by virtualenv and although virtualenvwrapper has some hooks for handling them, it’s often easiest to use a shell script or
.envfile to set them in a development environment.
- Pipreqs searches through a project for dependencies based on imports. It then generates a
requirements.txtfile based on the libraries necessary to run those dependencies. Note though that while this could come in handy with a legacy project, the version numbers for those libraries will not be generated with the output.
Application dependencies learning checklist
- Ensure the libraries your web application depends on are all captured in a requirement.txt file with pegged versions.
- An easy way to capture currently installed dependencies is with the
- Create a fresh virtualenv and install the dependencies from your
requirements.txtfile by using the
pip install -r requirements.txtcommand.
- Check that your application runs properly with the fresh virtualenv and only the installed dependencies from the