ipython install new modules

后端 未结 4 756
一个人的身影
一个人的身影 2021-02-01 08:25

I am used to the R functionality of installing packages and I am trying to do the same thing with ipython. Sometimes the following method works but then again somet

4条回答
  •  醉梦人生
    2021-02-01 09:07

    actually there is a much much much more elegant solution. when pip is installed then within python you can do things like this as well:

    import pip
    
    def install(package):
       pip.main(['install', package])
    
    install('requests') 
    

    which is easier. once logged into a virtualenv you can just make sure that you have what you need in the session you are in. easy.

    edit

    Another alternative would be to use the %%bash magic.

    %%bash
    pip install requests
    

    edit2

    If you want the standard output, one could even use the exclamation bang.

    ! pip install requests
    

提交回复
热议问题