Simple dependency management for a Python project

你离开我真会死。 提交于 2019-12-18 12:29:18

问题


I am coming from Java background and completely new at Python.

Now I have got a small project with a few Python files that contain a few imports. I know I does not have the imported dependencies installed on my computer, so I try to figure out the required dependencies and run pip to install them.

I would like to do it differently. I would prefer to have the dependencies listed in a single file and install them automatically during the build process.

Does it make sense ? If it does I have a few questions:

  • How to list the project dependencies required to install by pip ?
  • How to run pip to install the dependencies from the list ?

回答1:


A common way to manage dependencies for a python project is via a file in root of the project named "requirements.txt". An easy way to make this is:

  1. Setup a python virtualenv for your project
  2. Manually install the required modules via pip
  3. Execute pip freeze > requirements.txt to generate the requirements file

You can then install all the dependencies in other locations using pip install -r requirements.txt.

If you want dependencies to be installed automatically when other people pip install your package, you can use install_requires() in your setup.py.



来源:https://stackoverflow.com/questions/43828879/simple-dependency-management-for-a-python-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!