0

Lets say a developer is working on a project when he realizes he needs to use some package. He uses pip to install it. Now, after installing it, would a the developer write it down as a dependency in the requirements file / setup.py?

What does that same dev do if he forgot to write down all the dependencies of the project (or if he didn't know better since he hasn't been doing it long)?

What I'm asking is what's the workflow when working with external packages from the PyPi?

2 Answers 2

4

The command:

pip freeze > requirements.txt 

will copy all of the dependencies currently in your python environment into requirements.txt. http://pip.readthedocs.org/en/latest/reference/pip_freeze.html

Sign up to request clarification or add additional context in comments.

1 Comment

Hopefully the developer was using virtualenv and limited the modules installed just to the project, otherwise you will get every single module globally installed on the system. It will still work, but you will get a lot of modules which are probably not used.
1

It depends on the project.

If you're working on a library, you'll want to put your dependencies in setup.py so that if you're putting the library on PyPi, people will be able to install it, and its dependencies automatically.

If you're working on an application in Python (possibly web application), a requirements.txt file will be easier for deploying. You can copy all your code to where you need it, set up a virtual environment with virtualenv or pyvenv, and then do pip install -r requirements.txt. (You should be doing this for development as well so that you don't have a mess of libraries globally).

It's certainly easier to write the packages you're installing to your requirements.txt as soon as you've installed them than trying to figure out which ones you need at the end. What I do so that I never forget is I write the packages to the file first and then install with pip install -r.

pip freeze helps if you've forgotten what you've installed, but you should always read the file it created to make sure that you actually need everything that's in there. If you're using virtualenv it'll give better results than if you're installing all packages globally.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.