How can I synchronize project dependencies between

2019-09-09 08:47发布

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:

  1. Developer A installs a package and writes some code that uses it.
  2. He/she pushes the code to the central repo.
  3. Developer B pulls the code and starts working.
  4. 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条回答
\"骚年 ilove
2楼-- · 2019-09-09 09:32

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.

查看更多
登录 后发表回答