我习惯于安装包的 R 功能,我正在尝试用ipython
. 有时以下方法有效,但有时又无效,我想最终找出为什么它只在一半时间内有效。
通常要安装一个模块(例如requests
模块),我会在打开一个新终端后键入以下内容:
$ sudo pip install requests
Password: *******
随后会显示一条消息,指示安装成功或已安装。
Requirement already satisfied (use --upgrade to upgrade):
requests in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages
Cleaning up...
这表明可以访问代码。事实上,如果我现在从终端运行 python,它会显示一个很好的响应,没有任何错误。
$ python
ActivePython 2.7.2.5 (ActiveState Software Inc.) based on
Python 2.7.2 (default, Jun 24 2011, 12:20:15)
[GCC 4.2.1 (Apple Inc. build 5664)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests
>>>
我现在PyLab
通过 Alfred 打开,它给了我一个错误。
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-686486c241c8> in <module>()
----> 1 import requests
ImportError: No module named requests
我从 StackOverflow 上的另一个问题(here)中阅读了一些帮助,这表明我从ipython
shell 安装模块。这给出了一个更加莫名其妙的反应:
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-686486c241c8> in <module>()
----> 1 import requests
ImportError: No module named requests
这对我来说似乎很奇怪。系统上是否安装了多个版本的python?我怎么能检查这个?我需要指向ipython
安装代码的位置吗?