181

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
  • 91,494
  • 132
  • 359
  • 564

4 Answers4

161

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
  • 4,081
  • 5
  • 33
  • 54
127

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,714
  • 6
  • 45
  • 80
Aron Ahmadia
  • 2,267
  • 2
  • 19
  • 22
  • 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
  • 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
  • Using `--editable` didn't work, said not found, but removing it worked great. Thanks – Sos Aug 31 '22 at 15:02
31

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
  • 86,894
  • 26
  • 169
  • 240
27

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
   - pip:
     - git+https://github.com/pythonforfacebook/facebook-sdk.git
Thomas Grainger
  • 2,271
  • 27
  • 34
mmann1123
  • 5,031
  • 7
  • 41
  • 49
  • 1
    conda will complain if you don't also add pip on a line by itself as a dependency. Furthermore, other useful examples of using conda with pip can be found here: https://github.com/conda/conda/blob/main/tests/conda_env/support/advanced-pip/environment.yml – thomaskeefe Sep 26 '22 at 20:01