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
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:
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 usesudo
orsudo -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 ofpip3 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".