linux下安装执行linux ipython下载 --pylab是出现Import Error错误

《利用python进行数据分析》中,”ipython --pylab“ 在pycharm中怎么使用? - 知乎34被浏览4356分享邀请回答129 条评论分享收藏感谢收起51 条评论分享收藏感谢收起解决python - ipython install new modules - python-install-module - ITkeyowrd
解决python - ipython install new modules
推荐:为了使用python种类繁多的library,必须先安装setuptools和pip这一类的安装工具 直接下载setuptools的可执行文件,在Windows下即使设置了python的路径默认setupt
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 sometimes it doesn't and I would like to finally find out why it only works half the time.
Normally to install a module (like the requests module for example) I would type the following after opening a fresh terminal:
$ sudo pip install requests
Password: *******
This would then be followed by a message indicating that the install was succesfull or that it has already been installed.
Requirement already satisfied (use --upgrade to upgrade):
requests in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages
Cleaning up...
Which suggests that the code can be accessed. And indeed if I run python now from the terminal it shows a good response without any errors whatsoever.
ActivePython 2.7.2.5 (ActiveState Software Inc.) based on
Python 2.7.2 (default, Jun 24 :15)
[GCC 4.2.1 (Apple Inc. build 5664)] on darwin
Type &help&, &copyright&, &credits& or &license& for more information.
&&& import requests
I now open PyLab through Alfred and it gives me an error.
Welcome to pylab, a matplotlib-based Python environment [backend: WXAgg].
For more information, type 'help(pylab)'.
In [1]: import requests
---------------------------------------------------------------------------
ImportError
Traceback (most recent call last)
/Users/vincentwarmerdam/&ipython-input-1-c8& in &module&()
----& 1 import requests
ImportError: No module named requests
I've read some help from another question on stackoverflow (here ) which suggests that I install the module from ipython shell. This gives an even more baffeling response:
In [2]: !pip install requests
Requirement already satisfied (use --upgrade to upgrade): requests in
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages
Cleaning up...
In [3]: import requests
---------------------------------------------------------------------------
ImportError
Traceback (most recent call last)
/Users/vincentwarmerdam/&ipython-input-3-c8& in &module&()
----& 1 import requests
ImportError: No module named requests
This seems very strange to me. Are there multiple versions of python installed on the system? How could I check this? Do I need to point ipython to the location of the installed code?
asked Apr 12 '13 at 14:33
5,023 5 34 65 && & I don't know what Alfred is, but what happens if you just try to import requests in an ipython session without pylab/alfred? –&
Apr 12 '13 at 15:23 && & Alfred is a shortcut app. I tried running ipython instead of pylab. I get the following:
In [1]: import request
ImportError: No module named request Seems like the same error. –&
Apr 12 '13 at 15:31 && & try to
print sys.path in iPython to see if the install directory is included. –&
Apr 12 '13 at 18:16 && & one thing to check is the value of
sys.executable when you are in plain Python and IPython, or alternately the value of
head -n 1 $(which ipython) and
head -n 1 $(which pip) to make sure they are using the same Python. –&
Apr 12 '13 at 23:30 && &
$ head -n 1 $(which ipython)
#!/Library/Frameworks/Python.framework/Versions/7.3/Resource?s/Python.app/Content?s/MacOS/Python
$ head -n 1 $(which pip) gives
#!/Library/Frameworks/Python.framework/Versions/2.7/bin/pyth?on2.7
so i need to include the 'pip-folder' to the 'ipython-folder' if i understand correctly? i still don't understand why
pip install requests in ipython tells me that the library is installed while the folders are not correct. –&
Apr 13 '13 at 14:45
3 Answers 3
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.
Another alternative would be to use the %%bash magic.
pip install requests
If you want the standard output, one could even use the exclamation bang.
! pip install requests
answered Aug 5 '13 at 10:20
5,023 5 34 65 && & Does this trick work with easy_install? –&
Jul 16 '14 at 22:07 && & not to my knowledge. but you can install pip easily from easy_install and maybe you should:
Jul 17 '14 at 8:19 && & Such a wonderful solution! –&
May 2 '16 at 10:47
Here's what I d open up iypthon through the command line and type 推荐:首先介绍一下easy_install和pip. easy_install:就是用来安装第三方扩展包的。 用法: 安装一个包:easy_install package_name 升级一个包:easy_install -U “p
import sys
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.
answered May 2 '13 at 15:40
5,023 5 34 65
If the new packages installed are imported on Terminal but not imported to ipython notebook then it is very likely that you have two versions of python installed on your library. Due to this there are separate site-packages directory from where packages are being imported on terminal and ipython notebook. To check if this is the case. On terminal use: import sys sys.path This will show where the python modules are located for python you using on terminal. Now, in ipython notebook use: import sys sys.path This will show where the python modules are located for python you using on terminal.
Now, if the two path are different you know you are using two different installations of python. To solve this problem, copy installed packages from site-packages directory of terminal python to site-packages directory of ipython.
answered Aug 15 '16 at 21:39
推荐:上一篇中说道pip install py2app失败的情况。 其实很常见,经常理论上pip install 的东西肯定是可以的但是每次就是找不到,我不知道是这段时间pip生病了,还是这
相关阅读排行
相关内容推荐
请激活账号
为了能正常使用评论、编辑功能及以后陆续为用户提供的其他产品,请激活账号。
您的注册邮箱:
如果您没有收到激活邮件,请注意检查垃圾箱。64位Win7搭建Python开发平台Python3 + Ipython Notebook +... - 简书
64位Win7搭建Python开发平台Python3 + Ipython Notebook + Numpy + Scipy + Matplotlib + PyQt4
Life is short, you need Python!------ Bruce Eckel(ANSI C++ Comitee member)Python[1]是一门很难让人拒绝学习的语言,我喜欢它是因为它能很快给人带来成就感,海量的扩展库几乎可以帮助你立刻完成许多看起来很困难的事情。Python的触角已经深入到学习、工作的各个领域,甚至是在科学计算领域也有不俗的表现,许多古老的fortran程序库(如lapack[2])都被封装成了Python的扩展库,继续散发着活力。Python是的、免费的。开源,往往让我想到跨平台的问题。Linux上的软件要移植到Windows上面,要借助于Cygwin[3],但其性能不令人满意,后来有了Mingw[4],可以编译32位的lapack库,配合msys[5]就成了一个mini的linux。但是仅仅32位还是不能让人满意,于是又有了Mingw-w64[6],就连msys也不甘寂寞,弄出了个msys2[7],总算完美了,估计治好了不少人的强迫症,但是它的包管理工具pacman着实让我头疼了一番。64位已然成为主流,Python的自然也最好是64位的。单纯win64上的Python不是问题,关键在于与之配套的扩展库,如numpy[8]、scipy[9],官方只提供了win32的安装包,想在64位的Python上使用,只能自己编译咯。这还不是最坏的情况,在Python出来的相当长的一段时间内,这些库实际上只有python2版本的,如果现在你还在用python2,那可以安装一个python(x,y)[10],最新版基于Python2.7.6,700+MB的安装包包含了用都用不完的扩展库,几乎可以媲美、mathematica等商业软件。回到编译64位扩展库的问题上,numpy需要64位lapack的库,这个不难办,我用Mingw-w64可以编译出来,其实这个工作早有人做了[11],也可以直接装个intel mkl[12],用intel的就可以了,有人在linux上实现了[13]。这三个思路我都尝试了一下,最终发现numpy的说明文件写的太粗糙了,想要顺利编译是不可能的。正当我要放弃时,发现了牛人Christoph Gohlke的工作[14],这家伙编译了许多windows下python的科学计算程序库,而且更新得很及时,几乎都是最新版的。不得不相信一个事实,这个世界上有70亿人,除非你做的工作是领域内最前沿的,否则你遇到的问题,大多都被别人解决过了。所以,拿过来,学习它,继续前进,向最前沿前进。总而言之,我所需要的东西都有了,下面就是单调的安装、配置过程了。Python 3.4.1 x86_64:这个无需多言。numpy、scipy、matplotlib[15]、ipython[16]、pyqt4[17]:直接从[14]下载64位安装包,以及有依赖关系的包,运行安装,程序会自动安装到python的目录下。这里的IPython实际上属于IDE了,关于IDE,我尝试了ERIC5、Wing IDE、Eclipse+PyDev等,但最喜欢的还是IPython和IDLE。学习基础的Python时,用IDLE;学习科学计算库numpy、scipy、matplotlib时,IPython,尤其IPython Notebook是不二选择。IDLE和IPython在安装完之后就可以直接使用,下面介绍IPython Notebook的配置:1. 确保IPython可以正常运行:在命令行中输入ipython,显示如下提示:
如果提示缺少依赖库的话,到[14]处下载安装即可。2. 安装MathJax:Mathjax能够方便地显示数学符号、公式。默认情况IPython Notebook可以使用在线的Mathjax,本地安装是为了方便离线状态下使用。 在IPython中运行以下命令1from IPython.external.mathjax import install_mathjax2install_mathjax()3. 生成并修改配置文件:在命令行下运行ipythonfile create,会在C:/Users/yourname/.ipython/下生成file_default目录,其中的ipython_notebook_config.py就是要修改的配置文件。增加以下内容1c.NotebookApp.enable_mathjax =True2c.NotebookApp.book_dir ='X://XXX'//notebook启动目录3c.IPKernelApp.pylab ='inline'//生成的图形嵌入到notebook中,也可通过%pylab inline命令在notebook中实现4. 配置Matplotlib:这里按照其官方文档中的CONFIGURATION GUIDE章节来配置就可以了。我主要关注的是其渲染LaTex的功能,这需要安装texlive[18]或是miktex[19],以及ghostscript[20],并将其bin目录添加到系统path环境变量中。这样就可以生成eps图片了,当然,这需要在程序中添加以下说明1import matplotlibasmpl2mpl.rcParams['text.usetex']=True//启用tex3mpl.rcParams['text.latex.unicode']=True//启用Unicode当然,这也可以通过修改.../Python34/Lib/site-packages/matplotlib/mpl-data/matplotlibrc配置文件来实现。在实际运行过程中,有可能会遇到无法导出较大的eps图像文件的情况,伴随着某个临时文件处于保护状态的错误提示,我是直接把用户临时文件目录修改到非系统盘目录中来解决的。设置用户1TEMP=X:/XX2TMP=X:/XX//X为非系统盘5. 到此为止,我们可以运行notebook了ibook运行Matplotlib官方主页上的一个例子[21],给它加入一句输出eps文件的命令,完美运行,如下所示:
我的笔记本屏幕小,只能截这一部分图了。可以看出,ibook的界面与mathematica非常类似,至于功能上,二者会差别多大?这个我不知道,因为我投入python的怀抱了!本文链接:/bourbaki/p/4008883.html[1] http://en.wikipedia.org/wiki/Python_(gramming_language)[2] http://www.netlib.org/lapack/[3] /[4] http://www.mingw.org/[5] http://www.mingw.org/wiki/MSYS/[6] http://mingw-w64.sourceforge.net/[7] http://sourceforge.net/projects/msys2/[8] http://www.numpy.org/[9] http://www.scipy.org/[10] /p/xy/[11] http://icl.cs.utk.edu/lapack-for-windows/lapack/[12] /en-us/forums/intel-math-kernel-library/[13] http://blog.csdn.net/tengh/article/details/] http://www.lfd.uci.edu/~gohlke/pythonlibs/[15] http://matplotlib.org/[16] http://ipython.org/[17] http://pyqt.sourceforge.net/Docs/PyQt4/[18] https://www.tug.org/texlive/[19] http://miktex.org/[20] /[21] http://matplotlib.org/users/usetex.html#usetex-with-unicodeipython里面%pylab
时间: 12:19:45
我在本机已经pip&install&matplotlib成功,然后在ipython里面&&&&%pylab&inline&&&&打印提示一堆错误。这是还是因为缺少什么库吗?&谢谢。&&&&&&&&In&[34]:&%pylab&inline&&&&x---------------------------------------------------------------------------&&&&UnknownBackend&&&&&&&&&&&&&&&&&&&&&&&&&&&&Traceback&(most&recent&call&last)&&&&&ipython-input-34-550caa57204a&&in&&module&()&&&&----&&1&get_ipython().magic(u'pylab&inline')&&&&&&&&/usr/local/lib/python2.7/site-packages/IPython/core/interactiveshell.pyc&in&magic(self,&arg_s)&&&&&&&2156&&&&&&&&&magic_name,&_,&magic_arg_s&=&arg_s.partition('&')&&&&&&&2157&&&&&&&&&magic_name&=&magic_name.lstrip(prefilter.ESC_MAGIC)&&&&-&&2158&&&&&&&&&return&self.run_line_magic(magic_name,&magic_arg_s)&&&&&&&2159&&&&&&&2160&&&&&#-------------------------------------------------------------------------&&&&&&&&/usr/local/lib/python2.7/site-packages/IPython/core/interactiveshell.pyc&in&run_line_magic(self,&magic_name,&line)&&&&&&&2077&&&&&&&&&&&&&&&&&kwargs['local_ns']&=&sys._getframe(stack_depth).f_locals&&&&&&&2078&&&&&&&&&&&&&with&self.builtin_trap:&&&&-&&2079&&&&&&&&&&&&&&&&&result&=&fn(*args,**kwargs)&&&&&&&2080&&&&&&&&&&&&&return&result&&&&&&&2081&&&&&&&&&decorator-gen-105&&in&pylab(self,&line)&&&&&&&&/usr/local/lib/python2.7/site-packages/IPython/core/magic.pyc&in&&lambda&(f,&*a,&**k)&&&&&&&&186&&&&&#&but&it's&overkill&for&just&that&one&bit&of&state.&&&&&&&&187&&&&&def&magic_deco(arg):&&&&--&&188&&&&&&&&&call&=&lambda&f,&*a,&**k:&f(*a,&**k)&&&&&&&&189&&&&&&&&190&&&&&&&&&if&callable(arg):&&&&&&&&/usr/local/lib/python2.7/site-packages/IPython/core/magics/pylab.pyc&in&pylab(self,&line)&&&&&&&&154&&&&&&&&&&&&&import_all&=&not&args.no_import_all&&&&&&&&155&&&&--&&156&&&&&&&&&gui,&backend,&clobbered&=&self.shell.enable_pylab(args.gui,&import_all=import_all)&&&&&&&&157&&&&&&&&&self._show_matplotlib_backend(args.gui,&backend)&&&&&&&&158&&&&&&&&&print&("Populating&the&interactive&namespace&from&numpy&and&matplotlib")&&&&&&&&/usr/local/lib/python2.7/site-packages/IPython/core/interactiveshell.pyc&in&enable_pylab(self,&gui,&import_all,&welcome_message)&&&&&&&2984&&&&&&&&&from&IPython.core.pylabtools&import&import_pylab&&&&&&&2985&&&&-&&2986&&&&&&&&&gui,&backend&=&self.enable_matplotlib(gui)&&&&&&&2987&&&&&&&2988&&&&&&&&&#&We&want&to&prevent&the&loading&of&pylab&to&pollute&the&user's&&&&&&&&/usr/local/lib/python2.7/site-packages/IPython/core/interactiveshell.pyc&in&enable_matplotlib(self,&gui)&&&&&&&2945&&&&&&&&&&&&&&&&&gui,&backend&=&pt.find_gui_and_backend(self.pylab_gui_select)&&&&&&&2946&&&&-&&2947&&&&&&&&&pt.activate_matplotlib(backend)&&&&&&&2948&&&&&&&&&pt.configure_inline_support(self,&backend)&&&&&&&2949&&&&&&&&/usr/local/lib/python2.7/site-packages/IPython/core/pylabtools.pyc&in&activate_matplotlib(backend)&&&&&&&&292&&&&&matplotlib.rcParams['backend']&=&backend&&&&&&&&293&&&&--&&294&&&&&import&matplotlib.pyplot&&&&&&&&295&&&&&matplotlib.pyplot.switch_backend(backend)&&&&&&&&296&&&&&&&&/usr/local/lib/python2.7/site-packages/matplotlib/pyplot.py&in&&module&()&&&&&&&2510&#&are&no-ops&and&the&registered&function&respect&`mpl.is_interactive()`&&&&&&&2511&#&to&determine&if&they&should&trigger&a&draw.&&&&-&&2512&install_repl_displayhook()&&&&&&&2513&&&&&&&2514&#################&REMAINING&CONTENT&GENERATED&BY&boilerplate.py&##############&&&&&&&&/usr/local/lib/python2.7/site-packages/matplotlib/pyplot.py&in&install_repl_displayhook()&&&&&&&&163&&&&&&&&&&&&&ipython_gui_name&=&backend2gui.get(get_backend())&&&&&&&&164&&&&&&&&&&&&&if&ipython_gui_name:&&&&--&&165&&&&&&&&&&&&&&&&&ip.enable_gui(ipython_gui_name)&&&&&&&&166&&&&&&&&&else:&&&&&&&&167&&&&&&&&&&&&&_INSTALL_FIG_OBSERVER&=&True&&&&&&&&/usr/local/lib/python2.7/site-packages/IPython/terminal/interactiveshell.pyc&in&enable_gui(self,&gui)&&&&&&&&450&&&&&def&enable_gui(self,&gui=None):&&&&&&&&451&&&&&&&&&if&gui:&&&&--&&452&&&&&&&&&&&&&self._inputhook&=&get_inputhook_func(gui)&&&&&&&&453&&&&&&&&&else:&&&&&&&&454&&&&&&&&&&&&&self._inputhook&=&None&&&&&&&&/usr/local/lib/python2.7/site-packages/IPython/terminal/pt_inputhooks/__init__.pyc&in&get_inputhook_func(gui)&&&&&&&&&36&&&&&&&&&37&&&&&if&gui&not&in&backends:&&&&---&&38&&&&&&&&&raise&UnknownBackend(gui)&&&&&&&&&39&&&&&&&&&40&&&&&if&gui&in&aliases:&&&&&&&&UnknownBackend:&No&event&loop&integration&for&'inline'.&Supported&event&loops&are:&qt,&qt4,&qt5,&gtk,&gtk2,&gtk3,&tk,&wx,&pyglet,&glut,&osx&&&&Error&in&callback&&function&post_execute&at&0x10f398c08&&(for&post_execute):&&&&---------------------------------------------------------------------------&&&&AttributeError&&&&&&&&&&&&&&&&&&&&&&&&&&&&Traceback&(most&recent&call&last)&&&&/usr/local/lib/python2.7/site-packages/matplotlib/pyplot.py&in&post_execute()&&&&&&&&145&&&&&&&&146&&&&&&&&&&&&&def&post_execute():&&&&--&&147&&&&&&&&&&&&&&&&&if&matplotlib.is_interactive():&&&&&&&&148&&&&&&&&&&&&&&&&&&&&&draw_all()&&&&&&&&149&&&&&&&&AttributeError:&'NoneType'&object&has&no&attribute&'is_interactive'&&&&
&&&&&&&&&&&&
&&&&&&&&&&&&
&&&&&&&&&&&&}

我要回帖

更多关于 linux ipython下载 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信