60

Since conda install and pip install in many cases do essentially the same thing, what would be the best option? Is there a case when someone should stick to pip install only? Symmetrical, is there a case when one should stick to conda install only? Is there a way to shoot in one's foot by using both conda and pip install in a single environment?

If both approaches are essentially the same and don't contradict each other there should be no reason to stick solely to one of them but not to the other.

y.selivonchyk
  • 8,987
  • 8
  • 54
  • 77
  • 4
    No, it is not, as long as you don't try to double install packages; some packages are not available on either conda or pip, so it is sometimes unavoidable. – Reblochon Masque May 14 '19 at 16:12
  • 2
    yes. conda doesnt know what pip has installed and vice versa. You need to stick to conda in my suggestion. – MEdwin May 14 '19 at 16:12
  • 2
    @MEdwin is there a reason for such suggestion? – y.selivonchyk May 14 '19 at 16:14
  • 1
    I guess the question is why, if you are using conda, would you ever use pip. – Chris May 14 '19 at 16:15
  • conda tries to do more than pip in my opinion, and pip compiles everything from source, so more chance of failure. They can be run side by side, but when pip uninstalls some package conda doesnt know it. The same when conda uninstalls. – MEdwin May 14 '19 at 16:16
  • 3
    @Chris to install a package who's wheel has not been duplicated in conda. For instance, when newer version of package is available, or not all wheels of a package have been duplicated in conda and there is a compatibility issue. – y.selivonchyk May 14 '19 at 16:51
  • 1
    @Chris I was trying to use torchmeta and it cannot be installed with `conda intall torchmeta` for some reason but it succeeded with pip. So that's a reason to use pip and conda together. what is not clear to me is what are the drawbacks of combining them. – Charlie Parker Jul 03 '20 at 19:02

2 Answers2

54

Don't mix conda install and pip install within conda environment. Probably, decide to use conda or virtualenv+piponce and for all. And here is how you decide which one suits you best:

  • Conda installs various (not only python) conda-adopted packages within conda environment. It gets your environments right if you are into environments.
  • Pip installs python packages within Python environment (virtualenv is one of them). It gets your python packages installed right.

Safe way to use conda: don't rush for the latest stuff and stick to the available packages and you'll be fine.

Safe way to use pip+virtualenv: if you see a dependency issue or wish to remove and clean up after package - don't. Just burn the house, abandon your old environment and create a new one. One command line and 2-5 minutes later things gonna be nice and tidy again.

Pip is the best tool for installing Python packages among the two of them. Since pip packages normally come out first and only later are adopted for conda (by conda staff or contributors). Chances are, after updating or installing the latest version of Python some of the packages would only be available through pip. And the latest freshest versions of packages would only be available in pip. And mixing pip and conda packages together can be a nightmare (at least if you want to utilize conda's advantages).

Conda is the best when it comes to managing dependencies and replicating environments. When uninstalling a package conda can properly clean up after itself and has better control over conflicting dependency versions. Also, conda can export environment config and, if the planets are right at the moment and the new machine is not too different, replicate that environment somewhere else. Also, conda can have larger control over the environment and can, for example, have a different version of Python installed inside of it (virtualenv - only the Python available in the system). You can always create a conda package when you have no freedom of choosing what to use.

Some relevant facts:

  • Conda takes more space and time to setup
  • Conda might be better if you don't have admin rights on the system
  • Conda will help when you have no system Python
  • virtualenv+pip will free you up of knowing lots of details like that

Some outdated notions:

  • Conda used to be better for novice developers back in the day (2012ish). There is no usability gap anymore
  • Conda was linked to Continuum Analytics too much. Now Conda itself is open source, the packages - not so much.
y.selivonchyk
  • 8,987
  • 8
  • 54
  • 77
  • "*Conda takes more space*" Do you have a reference for that? I'd be interested to see a solid comparison of how a collection of virtualenvs stack up against an equivalent collection of Conda envs, after correcting for hardlinks. – merv May 15 '19 at 15:10
  • @merv, http://deeplearning.lipingyang.org/2018/12/23/anaconda-vs-miniconda-vs-virtualenv/ - that statement comes from here. No comparison, so – y.selivonchyk May 15 '19 at 15:30
  • The only statement about space in that blog post pertains only to Anaconda, which your question/answer isn't about. – merv May 15 '19 at 15:47
  • 7
    you start by saying not to mix them but then actually not provide an explanation to **why** not to mix them. Can you clarify that please? Thanks! – Charlie Parker Jul 03 '20 at 19:00
  • 1
    @CharlieParker this link from the post describes why https://www.anaconda.com/blog/using-pip-in-a-conda-environment – y.selivonchyk Jul 08 '20 at 00:14
  • tensorflow-addon is never on conda..... and perhaps forever – ArtificiallyIntelligence Mar 17 '22 at 18:29
12

Depends on the complexity of your environment really.

Using pip for a few simple packages should not generate any issues. Using more pip installs raises the question "Why not use a pip venv then?".

If you're not doing anything major, you might be able to have a mix of pip and conda installs.

There is an extensive explanation why mixing them can be a bad idea here: Using Pip in a Conda Environment.

Alin Iuga
  • 250
  • 4
  • 11