I wonder if it's possible to install python packages without leaving the IPython shell.
49
votes
6 Answers
0
votes
The best way to do this in modern ipython or jupyter is to use the %pip magic:
%pip install my_package
97
votes
16
votes
This answer is outdated: See below for an easier way to this in modern jupyter.
The accepted answer by aculich will not work in all circumstances, for example:
- If you installed ipython/jupyter in a venv and run it directly via the venv's
pythonbinary - If you have multiple python versions, like EntryLevelR.
The correct command is:
import sys
!{sys.executable} -m pip install requests
7
votes
3
votes
I like hurfdurf's answer, but on its own iPython may not recognize the new module (especially if it adds to the library path). Here's an augmented example with iPython 3:
import pip
pip.main(['install','pygame'])
# import pygame at this point can report ImportError: No module named 'pygame'
import site
site.main()
# now with refreshed module path...
import pygame
0
votes
In case you are using Conda Package Manager, the following syntax might fit your needs
$ conda install -c conda-forge <targetPackageName>