Reputation: 6298
When writing a setup.py
I can specify extras_require
and give a list of dependencies that are needed for additional functionality of my tool like this:
setup(
name = "mypackage",
install_requires = ["numpy"],
extras_require = {
"plotting": ["matplotlib"],
}
)
I uploaded my package to PyPI and a conda channel and tried to install it, including all extras. From PyPI I can install the extras using:
$ pip install mypackage[plotting]
However, when installing my package from conda, I fail to install the extras. Is there a similar option for conda?
Upvotes: 14
Views: 4150
Reputation: 931
Note that this syntax may help:
Since pip can do
python -m pip install 'some-package[extra] @ git+https://git.repo/SomePackage@main'
We can have in the environment.yaml:
- pip
- some-package[extra] @ git+https://git.repo/SomePackage@main
Using this may help you build the recipe you need for your conda package to use the package with the extras you want. pip documentation
Upvotes: 0
Reputation: 8816
You can do this by creating a metapackage for the optional dependency. A good example for this is the matploptlib-feedstock. Here you have the main package matplotlib-base
that contains all code and the metapackage matplotlib
that depends on matplotlib-base
and its optional Qt dependencies.
With the matplotlib
example in mind, you could have the following outputs in your recipe:
package:
name: some_pkg
…usual recipe contents…
outputs:
- name: some_pkg
- name: some_pkg_with_optional_dep
requirements:
host:
- python
run:
- python
- optional_dependency
- {{ pin_subpackage('some_pkg', exact=True) }}
test:
imports:
- some_pkg
Note that when you require a specific version of an optional dependency, you can specify it in the optional package but then the version constraint will only be applied when you have some_pkg_with_optional_dep
installed.
To have the version constraint on the optional dependency respected independently of the presence of some_pkg_with_optional_dep
, you should specify it in the run_constrained
section:
requirements:
…
run_constraint:
- optional_dependency >=1.2
Upvotes: 6
Reputation: 19645
As of 18-APR-2017, this is not currently possible. See https://github.com/conda/conda/issues/3299 and https://github.com/conda/conda/issues/2984
The solution that I generally use is just to make everything that might be optional as a mandatory dependency. This tends to work out, since conda packages are available for most platforms, particularly for common dependencies, and if a dependency isn't available, writing a conda recipe and uploading it to Anaconda.org is relatively easy.
Upvotes: 5