How to install a Python package from within IPython?

后端 未结 5 1210
遥遥无期
遥遥无期 2020-11-27 14:01

I wonder if it\'s possible to install python packages without leaving the IPython shell.

5条回答
  •  失恋的感觉
    2020-11-27 14:37

    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
    

提交回复
热议问题