10

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?
Leonardo
  • 4,046
  • 5
  • 44
  • 85
  • I have found the option [non-recursive upgrade](https://pip.pypa.io/en/latest/user_guide.html#non-recursive-upgrades) but how to use it with a `requirements.txt` file? – Leonardo May 19 '14 at 11:09
  • Unless you are adding requirements, you already have them all installed, so you don't need to specify it. when you do add a new requirement, you can just install it manually, as it will not happen frequently. – Davidmh May 19 '14 at 11:12
  • I don't add new requirements, I need to upgrade only `mypackage` all the time because it changes quite often. Specifying a specific commit doesn't help – Leonardo May 19 '14 at 11:14
  • `pip install -U --no-deps git-ssh@...` – Davidmh May 19 '14 at 11:18
  • 1
    @Davidmh yes..how to specify this in the `requirements.txt` so that I can upgrade only for `mypackage` for that specific commit? I need to track in the file the version I am using – Leonardo May 19 '14 at 11:57

2 Answers2

10

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 package mypackage 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.

pradyunsg
  • 18,287
  • 11
  • 43
  • 96
2

If you have dependencies that need to be at a particular version, then you should fix them in your requirements file to stay at that version. So for example (although not realistic):

mock~=2.0.0
pexpect==2.4.1
git+ssh://git@github.com/myuser/mypackage.git@733c5b616da27cba14478c24b#egg=mypackage
  • mock will be updated to any version that looks like 2.0.* (normally changes in the most minor number are bugfixes, so you generally want this)
  • pexpect will be fixed at 2.4.1
  • mypackage will always be updated whenever possible.

If you only want to upgrade a single package though, then just upgrade that one:

pip install -U git+ssh://git@github.com/myuser/mypackage.git

Another alternative if you want to upgrade all of them regularly but some more regularly than others would be to split up the requirements file. See the pip docs. I suspect this needs an up to date version of pip and setuptools (but you're updating those regularly anyway, right??).

For example, you could then have:

update_regularly_reqs.txt

git+ssh://git@github.com/myuser/mypackage.git@733c5b616da27cba14478c24b#egg=mypackage

all_requirements.txt

-r update_regularly_reqs.txt
mock~=2.0.0
pexpect==2.4.1

Edit to add info on #egg=

The #egg=mypackage bit is required if you want to check it out using pip and also edit the code in that package, but then you need to use:

-e git+ssh://...#egg=mypackage

pip will then make a directory in the src directory in your virtualenv's home directory (use cdvirtualenv to find it) with that name, or at least it did on my system, and will check out the code using git clone (or appropriate for Mercurial or SVN if using those) so you can go and edit it in place.

But if you don't specify -e (as you did) then I think it checks it out as a normal package, which makes it harder for you to manage if you want to edit it in place, and then you don't need the #egg= bit.

No doubt there are lots of config options too... a good place to start is that doc I linked.

daphtdazz
  • 7,754
  • 34
  • 54
  • No, not in my case. Especially the github portion, changing the commit hash in the `requirements.txt` and running again `pip install -r requirements.txt` will not upgrade my package from github, no matter what I put after the @ a commit, a branch a tag. It will stick with the current version – Leonardo Dec 06 '16 at 15:47
  • You always need to pass `-U` or `--upgrade` if you want to change what is already installed. I think you should be using the `-e` option though. You should always be able just to upgrade the single package using `pip install -U git+ssh://git@github.com/myuser/mypackage.git`; I'll add that to my answer. – daphtdazz Dec 06 '16 at 16:03
  • You've linked to (outdated) pip 1.1 docs... pip 9.0.1 recently released. – pradyunsg Dec 07 '16 at 07:30