160

Can I install/upgrade packages from GitHub using conda?

For example, with pip I can do:

pip install git+git://github.com/scrappy/scrappy@master

to install scrappy directly from the master branch in GitHub. Can I do something equivalent with conda?

If this is not possible, would it make any sense to install pip with conda and manage such local installations with pip?

Amelio Vazquez-Reina
  • 83,134
  • 124
  • 340
  • 545

4 Answers4

143

The answers are outdated. You simply have to conda install pip and git. Then you can use pip normally:

  1. Activate your conda environment source activate myenv

  2. conda install git pip

  3. pip install git+git://github.com/scrappy/scrappy@master

Community
  • 1
  • 1
Gabriel Fair
  • 3,599
  • 5
  • 31
  • 52
  • 5
    In addition to this you have to use the pip which is within your envs like in my case the pip I used was "/home/ubuntu/anaconda3/envs/tensorflow_p36/bin/pip". This pip comes after you do the conda install. You can prepend this bin dir to your $PATH. – faizan May 18 '18 at 10:29
  • 1
    is the installed package only on the `master` branch after that? What if I'd like to test my PR from a branch before merging to master? – Mymozaaa May 09 '19 at 16:10
  • 1
    @AntonAndreev [the spec](https://pip.pypa.io/en/stable/reference/pip_install/#git) supports both `git+git` and `git+https`, plus others. However, all the spec examples do show a `.git` whenever specifying the branch. – merv Sep 07 '19 at 18:18
  • 7
    Much of is already in the OP (using `pip install`). The question is asking how to do it using `conda` _directly_, which the top answer provides. – Amelio Vazquez-Reina Jan 18 '20 at 14:49
108

There's better support for this now through conda-env. You can, for example, now do:

name: sample_env
channels:
dependencies:
   - requests
   - bokeh>=0.10.0
   - pip:
     - "--editable=git+https://github.com/pythonforfacebook/facebook-sdk.git@8c0d34291aaafec00e02eaa71cc2a242790a0fcc#egg=facebook_sdk-master"

It's still calling pip under the covers, but you can now unify your conda and pip package specifications in a single environment.yml file.

If you wanted to update your root environment with this file, you would need to save this to a file (for example, environment.yml), then run the command: conda env update -f environment.yml.

It's more likely that you would want to create a new environment:

conda env create -f environment.yml (changed as supposed in the comments)

Dschoni
  • 3,476
  • 5
  • 38
  • 72
Aron Ahmadia
  • 2,057
  • 2
  • 18
  • 22
  • How do you install the requirements from that environment in your root environment? – hobs Feb 29 '16 at 03:03
  • @hobs - I've edited the answer to answer your question. – Aron Ahmadia Mar 01 '16 at 03:14
  • 1
    It's actually `conda env create -f environment.yml`, with `conda create` the `-f` flag stands for `--force`. – Dominik Stańczak Dec 08 '17 at 08:11
  • 1
    Is it documented somewhere? – guilhermecgs Jan 22 '18 at 15:58
  • There is some documentation [here](https://conda.io/docs/user-guide/tasks/manage-environments.html#creating-an-environment-file-manually), but it doesn't explain the `pip` part (just gives an example) but it's pretty self-explanatory. You can also [export an existing conda env to yaml](https://conda.io/docs/user-guide/tasks/manage-environments.html#exporting-the-environment-file) (including pip-installs). – drevicko Feb 02 '18 at 15:28
  • @Perfi, that's incorrect, -f stands for --file which is used to specify the environment.yml file. – Will Nov 18 '18 at 17:38
  • @Will just checked, it confused me as well back then - it's different for `conda create` (where `-f` means `--force` and there is a separate `--file` flag) and `conda env create` (where `-f` means `--file` as you said and there's a separate `--force` flag). Weird API but ok, I guess. This may be a version thing - running `conda 4.5.11` here. – Dominik Stańczak Nov 19 '18 at 21:26
  • 1
    @Perfi, my mistake I thought you were suggesting that the `-f` in `conda env create` referred to force, and not for `conda create`, my mistake for not reading carefully. – Will Nov 21 '18 at 22:35
  • If you are getting "Pip subprocess error" please see [this answer](https://stackoverflow.com/a/51002277/8896457). In short "#egg=" is non optional, and it can be any name you want, typically package name. – Karol Zlot Jun 25 '20 at 02:20
  • In case you need to install from a subdirectory: https://stackoverflow.com/questions/13566200/how-can-i-install-from-a-git-subdirectory-with-pip e.g. - "--editable=git+https://github.com/poleguy/pyshark.git@7fc7fbb400080868291bd7268676f7513f898504#egg=src&subdirectory=src" – poleguy Oct 05 '21 at 07:13
30

conda doesn't support this directly because it installs from binaries, whereas git install would be from source. conda build does support recipes that are built from git. On the other hand, if all you want to do is keep up-to-date with the latest and greatest of a package, using pip inside of Anaconda is just fine, or alternately, use setup.py develop against a git clone.

asmeurer
  • 80,291
  • 25
  • 162
  • 229
17

I found a reference to this in condas issues. The following should now work.

name: sample_env
channels:
dependencies:
   - requests
   - bokeh>=0.10.0
   - pip:
     - git+https://github.com/pythonforfacebook/facebook-sdk.git
mmann1123
  • 4,512
  • 6
  • 36
  • 46
  • 4
    This adds nothing that isn't already in [@AronAhmadia's answer](https://stackoverflow.com/a/32799944/570918), which illustrates more generally that many of the options in a normal requirements.txt are available. – merv Sep 07 '19 at 18:16
  • 6
    I think people forget how many newbies use stack overflow. Providing the simplest example is important. – mmann1123 Jul 16 '21 at 15:44