For developing a script that runs pip install
it would be usefull to have a --dry-run
function.
I came across the --no-install
option. But this one is deprecated and on call references this.
There are hints to unpack a package only, but I can't find a unpack
option in the pip documentation.
Yes - pip should have a dry-run
option, to indicate what would happen in a complex situation. It is dangerous when running pip install
downgrades packages without asking you. We need some way to ask what would happen if we run pip install -r requirements.txt
without laboriously searching thru all the requirements and comparing them to the currently installed ones.
It looks like setup.py used to have a dry-run
. Folks are asking for it elsewhere.
Some progress in that direction can be found here:
- Dry Run for Python Pip | BackSlasher
- nvie/pip-tools: A set of tools to keep your pinned Python dependencies fresh.
It appears you are right, it has been deprecated (ref).
If by trial run you mean testing it out before actually installing a package in a certain place, presumably before a system wide install, then you can simply run it sandboxed using a virtual environment and then simply discard the environment.
virtualenv /tmp/venv; /tmp/venv/bin/pip install flask; rm -rf /tmp/venv
Not as succinct as using a dry-run argument to pip, but it does the job. Also if you want to do a dry run of a series of package installations, omit the deletion at the end.
In a script you can distil it into a procedure:
#!/bin/bash
TMP_DIR='/tmp/venv'
function dry_run (){
if [ ! -d "$TMP_DIR" ]; then
virtualenv /tmp/venv
fi
/tmp/venv/bin/pip install $1
}
dry_run flask
dry_run uwsgi
rm -rf $TMP_DIR
If you want to do a dry run that tests that the new install(s) play well with system wide deployed, then use virtualenv's system-site-packages option.
virtualenv --system-site-packages /tmp/venv; /tmp/venv/bin/pip install flask; rm -rf /tmp/venv
[Ugly hack disclaimer] on Linux you can try to install in the system location as a user who does not have permission to install in the /usr/ directory. The command fails with "Permission denied" but only after logging what is missing and what is not.
(makes you wonder how hard an actual dry-run option would really be to implement)
With pip version 9 there's a new option --format freeze
leading to an elegant one line solution for the pip install -r
use case:
pip list --format freeze | diff - requirements.txt