What is the most efficient way to list all dependencies required to deploy a working project elsewhere (on a different OS, say)?
Python 2.7, Windows dev environment, not using a virtualenv per project, but a global dev environment, installing libraries as needed, happily hopping from one project to the next.
I've kept track of most (not sure all) libraries I had to install for a given project. I have not kept track of any sub-dependencies that came auto-installed with them. Doing pip freeze
lists both, plus all the other libraries that were ever installed.
Is there a way to list what you need to install, no more, no less, to deploy the project?
EDIT In view of the answers below, some clarification. My project consists of a bunch of modules (that I wrote), each with a bunch of import
s. Should I just copy-paste all the imports from all modules into a single file, sort eliminating duplicates, and throw out all from the standard library (and how do I know they are)? Or is there a better way? That's the question.
Pip Check Command – Check Python Dependencies After Installation. Because pip doesn't currently address dependency issues on installation, the pip check command option can be used to verify that dependencies have been installed properly in your project. For example: $ pip check No broken requirements found.
Dependencies are all of the software components required by your project in order for it to work as intended and avoid runtime errors. You can count on PyPI (the Python Package Index) to provide packages that can help you get started on everything from data manipulation to machine learning to web development, and more.
When a package is installed globally, it's made available to all users that log into the system. Typically, that means Python and all packages will get installed to a directory under /usr/local/bin/ for a Unix-based system, or \Program Files\ for Windows.
You can do it by installing pipdeptree package. Open command prompt in your project folder. If you are using any virtual environment, then switch to that virtual environment. This package will list all the dependencies of your project.
pipreqs
solves the problem. It generates project-level requirement.txt file.
Install pipreqs: pip install pipreqs
pipreqs /path/to/your/project/
If you want to read more advantages of pipreqs
over pip freeze
, read it from here
Scan your import
statements. Chances are you only import things you explicitly wanted to import, and not the dependencies.
Make a list like the one pip freeze
does, then create and activate a virtualenv.
Do pip install -r your_list
, and try to run your code in that virtualenv. Heed any ImportError
exceptions, match them to packages, and add to your list. Repeat until your code runs without problems.
Now you have a list to feed to pip install
on your deployment site.
This is extremely manual, but requires no external tools, and forces you to make sure that your code runs. (Running your test suite as a check is great but not sufficient.)
On your terminal type:
pip install pipdeptree
cd <your project root>
pipdeptree
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With