Pip install from a specific commit prompts “requirements already satisfied”
问题内容:
I’m using pip
and a requirements.txt
file to handle my python packages in
my virtualenv. I have a particular package I install from Github so that
inside my file I have:
git+ssh://git@github.com/myuser/mypackage.git#egg=mypackage
Since I’m working on the package quite often I need to re-install it but: pip install -r requirements.txt
gives me back
Requirement already satisfied (use --upgrade to upgrade)...
for all the packages in requirements.txt that have new versions.
If I run pip install -r requirements.txt --upgrade
it tries to upgrade
all my packages (that I do NOT want) but I want to upgrade only
mypackage
. In requirements.txt I’ve tried to add a specific commit, like so:
git+ssh://git@github.com/myuser/mypackage.git@733c5b616da27cba14478c24b#egg=mypackage
But when I run pip again it throws:
Requirement already satisfied (use --upgrade to upgrade)..bla bla bla
QUESTION:
- Is there a way to upgrade only the specific package
mypackage
possibily using the requirements.txt file? - Do I need to specify the
#egg=mypackage
?
问题答案:
The reason you’re getting Requirement already satisfied
is because if you do
not pass --upgrade
or -U
(the shorthand), the package is not modified if
it is already installed.
(This part of the command has had a lot of discussion. Check out the first 4
issues here)
Is there a way to upgrade only the specific packagemypackage
possibily
using the requirements.txt file?
You need to specify just mypackage
to pip when telling it to upgrade. If you
wanted to update only requests, the pip command is:
pip install --upgrade requests
Similarly, to update from your git repository, you want to do:
pip install --upgrade git+ssh://git@github.com/myuser/mypackage.git#egg=mypackage
Since it’s a URL is a long thing, what I suggest you do what @daphtdazz
suggests, use multiple requirements files, as follows:
requirements.txt
requests~=2.12.3
simplejson~=3.10.0
-r git_requirements.txt
git_requirements.txt
git+ssh://git@github.com/myuser/mypackage.git#egg=mypackage
Additionally, I suggest you use shell-aliases for your shell to ease the
typing load.
alias pip_git_upgrade="pip install --upgrade -r git_requirements.txt"
Do I need to specify the#egg=mypackage
?
To quote from pip’s official
documentation:
Any URL may use the #egg=name syntax to explicitly state the project name.
Basically, using #egg=mypackage
is a good idea since you are making the the
project name explicit.