问题
My team is starting a new Python project. We will be using Git with a central repository. Each developer will work on a local virtualenv, and push/pull from the central repo to the local one.
Using this setting, here is a possible scenario:
- Developer A installs a package and writes some code that uses it.
- He/she pushes the code to the central repo.
- Developer B pulls the code and starts working.
- Developer B runs the project locally and gets an ImportError, because he/she hadn't installed the new dependency introduced by Developer A.
My question is: how can I synchronize the project dependencies between all developers?
An approach I considered:
Before any git push, the developer performs git freeze > requirements.txt. The file is pushed along with the code.
After any git pull, the developer performs git install -r requirements.txt.
Is this approach vaiable? Is it recommended? Are there better approaches?
回答1:
I would use virtualenv and create a requirements file
pip freeze > requirements.txt
that you add to your git repo, every time a new package is needed, it should be added to the requirements file. When a developer pulls they can run
pip install -r requirements.txt
I think this is the most logical approach and is one my team has used multiple times.
来源:https://stackoverflow.com/questions/34344874/how-can-i-synchronize-project-dependencies-between-developers