I don't understand why some Python packages are installed using conda and some by using pip3.
Are these just different installers from different developers but doing the same thing?
Can I use them interchangeably to install Python packages?
For example:
conda create -n mtl python=3.6 anaconda
conda activate mtl
conda install pytorch torchvision cudatoolkit=10.1 -c pytorch
pip3 install opencv-python 1 Answer
It really depends upon your familiarity with pip and conda and how package installation interacts between the two methods. If you are a relative new user of conda and python, I would recommend using only conda to install your packages. YMMV depending upon your experience with both.
See the following two documents that explain the relationship between conda and pip in more detail:
Using pip in a conda environment & Understanding Conda and Pip
From the first article:
Running conda after pip has the potential to overwrite and potentially break packages installed via pip. Similarly, pip may upgrade or remove a package which a conda-installed package requires. In some cases these breakages are cosmetic, where a few files are present that should have been removed, but in other cases the environment may evolve into an unusable state.
There are a few steps which can be used to avoid broken environments when using conda and pip together. One surefire method is to only use conda packages.
conda install <package_name> will be constrained to your use within conda environment. If you delete your conda installation, those packages will be removed as well.
Generally, conda will modify your $PATH so that this isolates the package installation from your system somewhat.
When you use pip3 install <package_name>, you are potentially affecting your system Python installation. Especially if you use sudo or sudo -H to install the Python package.
I am not certain if it is a best practice; but, when I am using pip3, I generally use the command syntax of pip3 install --user <package_name> which will "Install to the Python user install directory for your platform. Typically in the ~/.local/ directory."
Again, I try to take some precaution to isolate my package changes from the system's Python installation.
I consider it a matter of personal preference as to which method conda vs. pip3 is "best".