Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Environment specific pip.conf under anaconda

Tags:

python

pip

conda

I'm working on a Python library and using the anaconda distribution. I install packages into a conda environment with both conda and pip. I'd like to install Python packages from both PyPi and an in-house repository server (Sonatype Nexus). To do this I need to set the --extra-index-url flag.

I'd like to make this reproducible to enable anyone to recreate the environment from a script so setting --extra-index-url from a command line invocation of pip isn't an option.

I could set this globally in $HOME/.pip/pip.conf, which works, but this isn't transferrable to other users, at least not in an automated way.

Is there a way to set a conda environment specific pip.conf file? Where would it be placed? This would enable anyone to check out the library code and recreate the environment with all dependencies intact and pulling code from an internal repository?

like image 272
Paul Joireman Avatar asked Jan 23 '17 21:01

Paul Joireman


2 Answers

It might be worth mentioning that Conda YAML environment definitions support the full spectrum of the pip install arguments, including --extra-index-url. For example, one could have something like:

environment.yaml

name: foo
channels:
  - defaults
dependencies:
  - python=3.9
  - numpy
  - scipy
  - pip
  - pip:
    - --extra-index-url https://127.0.100.55  # some custom URI
    - custom-pkg1
    - custom-pkg2

See Conda's Advanced Pip Example for a showcase of other capabilities.

like image 83
merv Avatar answered Sep 16 '22 15:09

merv


You can set the environmental variable PIP_CONFIG_FILE and point to the pip.conf you like. Since you want

to recreate the environment from a script

you could set PIP_CONFIG_FILE in this script.

like image 32
Mike Müller Avatar answered Sep 17 '22 15:09

Mike Müller