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?
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With