24

How can I install a package under development to an Anaconda environment?

With pip:

pip install -e /path/to/mypackage

or with regular setuptools:

python /path/to/mypackage/setup.py develop
Jasper van den Bosch
  • 3,169
  • 4
  • 32
  • 55
  • 1
    did you try: `conda install conda-build` followed by `conda develop .`? – Charlie Parker Mar 26 '20 at 22:04
  • 3
    is it just me or the actual setup is not run properly (i.e. the supporting packages required by my `setup.py` are not being installed). How does one have conda do this automatically? – Charlie Parker Jul 03 '20 at 17:25

5 Answers5

14

There is also conda develop available now.

http://conda.pydata.org/docs/commands/build/conda-develop.html

Update in 2019: conda develop hasn't been maintained and is not recommended. See https://github.com/conda/conda-build/issues/1992

Recommendation is to use python setup.py develop or pip install -e .

jkitchen
  • 900
  • 11
  • 16
  • 8
    this is why you shouldn't answer a question with a link and nothing else. when the link dies, your answer becomes useless. – endolith Apr 17 '19 at 16:47
8

Using either of those will work with Anaconda. Make sure that you have pip or setuptools installed into the conda environment you want to install into, and that you have it activated.

asmeurer
  • 86,894
  • 26
  • 169
  • 240
  • 1
    I'm not sure that this works with current anaconda versions. I got the error "package directory 'distutils' does not exist". conda develop worked just fine. – John Haberstroh Oct 27 '16 at 18:59
7

This is the equivalent to pip install -e .

conda install conda-build
conda develop .
Joseph Sheedy
  • 6,296
  • 4
  • 30
  • 31
2

As explained in this gh issue thread, because of build isolation and dependency installation, Anaconda developers recommend using:

pip install --no-build-isolation --no-deps -e .
droumis
  • 61
  • 7
-1

Build / Host Environment

To create build and host environments and a build script go to your recipe directory and use

conda debug /path/to/your/recipe-directory

as documented here. This will print an instructive message like

################################################################################
Build and/or host environments created for debugging.  To enter a debugging environment:

cd /home/UserName/miniconda3/conda-bld/debug_1542385789430/work && source /home/UserName/miniconda3/conda-bld/debug_1542385789430/work/build_env_setup.sh

To run your build, you might want to start with running the conda_build.sh file.
################################################################################

(The message might tell you incorrectly, that it created a test environment.) Your source code has been copied to the .../work directory and there is also a conda_build.sh script. Note, that sourcing the build_env_setup.sh will load both build and host environments.

You can work on your code and your recipe and build with the conda_build.sh, but you won't get a proper conda package, as far as I know. When you are finished, you can remove the debug environment:

conda deactivate   # maybe twice
conda build purge

Test Environment

To get the test environment, you have to build the package first and then debug that. This might be useful to fix your test files.

conda build /path/to/your/recipe-directory # creates mypackage*.tar.bz2
# find file location of mypackage*.tar.bz2 with:
conda search --info --use-local mypackage  # look at the url row for the path
cd /path/to/miniconda3/conda-bld/linux-64/ # go to that path, can be different
conda debug mypackage*.tar.bz2

This will print e. g.:

################################################################################
Test environment created for debugging.  To enter a debugging environment:

cd /home/UserName/miniconda3/conda-bld/debug_1542385789430/test_tmp && source /home/UserName/miniconda3/conda-bld/debug_1542385789430/work/conda_test_env_vars.sh

To run your tests, you might want to start with running the conda_test_runner.sh file.
################################################################################

Again, remove with

conda deactivate
conda build purge

Run Environment

This is actually no debugging, but the general process of building and installing a local package. With the run environment you can check, whether all dependencies are specified in the requirements/run section. Also pinning can be an issue.

(base) $ conda build /path/to/your/recipe-directory
(base) $ conda create --name package-env --use-local mypackage
(base) $ conda activate package-env
(package-env) $ python
>>> import mypackage

You can also list the dependencies of your package with (man page)

conda search --info --use-local mypackage

A last hint: If you want to know the versions of the dependencies and see, whether pinning works, try (man page)

conda render /path/to/your/recipe-directory
John
  • 1,472
  • 1
  • 19
  • 22