ipython install new modules

后端 未结 4 970
一个人的身影
一个人的身影 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 08:57

    Here's what I did that made it work; open up iypthon through the command line and type

    import sys
    sys.path 
    

    This shows a list of folders where other python modules are located. For me this was:

    ['',
     '/Library/Frameworks/Python.framework/Versions/7.3/bin',
     '/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/pandas-0.10.0-py2.7-macosx-10.5-i386.egg',
     '/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/googlemaps-1.0.2-py2.7.egg',
     '/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/oauth-1.0.1-py2.7.egg',
     '/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/oauth2-1.5.211-py2.7.egg',
     '/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/httplib2-0.7.7-py2.7.egg',
     '/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/selenium-2.28.0-py2.7.egg',
     '/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/jellyfish-0.2.0-py2.7-macosx-10.5-i386.egg',
     '/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/python_yelp-0.1.1-py2.7.egg',
     '/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/pymongo-2.4.2_-py2.7-macosx-10.5-i386.egg',
     '/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/lucene_querybuilder-0.1.6-py2.7.egg',
     '/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/mechanize-0.2.5-py2.7.egg',
     '/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/html2text-3.200.3-py2.7.egg',
     '/Library/Frameworks/Python.framework/Versions/7.3/lib/python27.zip',
     '/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7',
     '/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/plat-darwin',
     '/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/plat-mac',
     '/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/plat-mac/lib-scriptpackages',
     '/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/lib-tk',
     '/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/lib-old',
     '/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/lib-dynload',
     '/Users/vincentwarmerdam/Library/Python/2.7/lib/python/site-packages',
     '/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages',
     '/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/PIL',
     '/Library/Python/2.7/site-packages',
     '/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/IPython/extensions] 
    

    With this information, I now knew where ipython looks for the modules that one can import. So I downloaded the requests library manually, added it to the same root directory such that the following directory exists:

    /Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/requests 
    

    This folder contains the python modules that belong to requests. The only thing I now had to do was to make sure that ipython knows that this folder exists. Which was done by updating the sys.path.

    req_link = '/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/requests'
    sys.path.append(req_link) 
    

    After this I no longer got the error.

    import requests 
    

    Just works.

    Also after restarting ipython, I found that ipython automatically updates the new path into the sys.path list.

提交回复
热议问题