9

If I have a directory with setup.py, in pip, I can pip install . in the directory to install the package.

What if I am using conda?

conda install . makes conda to find a package named dot.

youkaichao
  • 1,938
  • 1
  • 14
  • 26
  • Are you looking to simply install the package, or do you wish for your package to be available _as_ a `conda` package? That is, are you creating something, installling something from somewhere else, or ...? – Chris Larson Feb 10 '19 at 17:19
  • @ChrisLarson I want to just install a package, and I happen to hear that it is better not to mix ``conda`` and ``pip``. The package is not available in ``conda`` but only available by source code. – youkaichao Feb 10 '19 at 21:53
  • `conda` itself recommends you use pip for non-`conda` packages. See both of the answers below for correct usage of `pip` in `conda`. Note that in my answer, I point out that this is the official, recommended and best practice way to handle non-`conda` packages. – Chris Larson Feb 11 '19 at 00:40
  • Although `conda install .` fails, I happen to find that `conda install conda-4.6.3-py37_0.tar.bz2` works. – youkaichao Feb 13 '19 at 09:03

3 Answers3

9

conda packages are a different structure than standard python packaging. As a result, the official, recommended and best-practice approach is to use conda to install pip within an activated conda environment, and use that to install standard packages:

conda install pip

NOTE: You want to use conda packages whenever they're available, as they have more features within a conda environment than non-conda packages.

conda install pip will install pip within the currently activated conda environment, and will ensure that it is integrated with conda so that, for example, conda list, will include any packages installed with pip.

NOTE: Commands like conda update will ignore pip installed packages, as it only checks conda channels for available updates, so they still need to be updated using pip. See this Question/Answer discussion:

Does conda update packages from pypi installed using pip install?

NOTE: See @kalefranz comment below regarding conda 4.6 experimental handling of packages.

If you're interested in creating your own conda package(s), take a look at this question/1st answer for a great run-down:

How to install my own python module (package) via conda and watch its changes

If you simply wish to install non-conda packages, using pip is the correct, and expected, way to go.

Chris Larson
  • 1,684
  • 1
  • 11
  • 19
  • 1
    Conda 4.6 has an experimental feature to enable interoperability with pip-installed packages. Use `conda config --set pip_interop_enabled true`. Packages that can be "managed" by conda (i.e. removed) may be updated to satisfy the current solve. Manageable packages were typically installed from wheels. Packages that can't be managed will anchor the environment in place until they're removed by other means. An example of unmanageable packages are "editable" installs that used `pip install -e`. – kalefranz Feb 11 '19 at 03:32
  • "You want to use conda packages whenever they're available", how do we achieve this? can `conda` read from `setup.py` and try to install dependencies that are available and we can use `pip install .` to do the rest? Or should we just create conda metafiles for this purpose? – Ryan Apr 17 '19 at 20:05
2

You can use pip install from within conda environment.

Just activate your environment using:

$ conda activate myenvironment

and use pip install . to install your package in environment's directory.

EDIT: As pointed by Chris Larson in another answert, you should install pip inside the environment using

$ conda install pip

in order to register packages correctly.

Szymon Maszke
  • 22,747
  • 4
  • 43
  • 83
0

If I have a whl file, I can use pip install xxx.whl to install it.

From the documentation, conda install from a local file is also available, but the file should be a tarball file, i.e. .tar.bz2 files.

conda install /package-path/package-filename.tar.bz2 works. And if I have multiple tarballs, I can tar them to get a .tar file, then conda install /packages-path/packages-filename.tar installs the packages in it.

youkaichao
  • 1,938
  • 1
  • 14
  • 26