Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does pip need an exclamation point to use in iPython?

Tags:

pip

ipython

Just a quick example, typing pip list doesn't work but !pip list does. Is there some syntax regarding the exclamation point and using modules in the ipython shell?

like image 215
thleo Avatar asked Jan 06 '17 16:01

thleo


People also ask

Why is there a exclamation point before pip?

It means run it as a shell command rather than a notebook command. For instance, using a command without ! in the terminal same as using the command with ! in jupyter notebook or google code lab.

Why do we use exclamation mark in Python?

In general, using an exclamation mark before the command will pass the command to the shell (not to the Python interpreter). Note that this differs from executing a python program in IDLE: IDLE restarts the Python interpreter session and thus deletes all existing objects before the execution starts.

Why do we use an exclamation mark in front of pip in jupyter notebook?

In Jupyter notebooks, the exclamation mark ! executes commands from the underlying operating system. For example, to run the list directory command ls in your Jupyter notebook, call ! ls in any cell.

What is exclamation in jupyter notebook?

The exclamation mark ! is used for executing commands from the uderlying operating system; here is an example using WIndows dir : ! dir # result: Volume in drive C has no label.


1 Answers

This is actually not specific to pip, but really any shell command from the iPython notebook. You'll notice other shell commands also work (from the docs):

In[1]: !pwd
/User/home/

Change directory:

In[1]: !cd /var/etc

This is simply shorthand that the good folks at Jupyter have included. See Shell Assignment in the docs for more of an explanation.

like image 136
TayTay Avatar answered Sep 20 '22 08:09

TayTay