Reputation: 400
what is the difference between '!pip' and '%pip'? We can use both of them in jupyter notebook and google colab. But we can not use the simple 'pip' there, can we?
Upvotes: 25
Views: 15039
Reputation: 590
%pip
will install the package in the virtual environment where the current notebook kernel is running. While !pip
will install the package in the base environment. If you are using Python virtual environment (as you should!), you should use %pip
.
Upvotes: 23
Reputation: 1779
%pip
is a magic function and works mostly the same like pip
. You can use other magic functions in jupyter which you can list with %lsmagic
(https://ipython.readthedocs.io/en/stable/interactive/magics.html#magic-lsmagic)
Using !
allows to run commands like ls
or pip
or what you have available on your OS.
Colab is just like jupyter so you can run native pip
like pip install tensorflow
.
See related answers:
Upvotes: 11