3

我在 Centos 6 Linux 上

当我尝试这个

Python 2.7.3 (default, Nov 23 2012, 18:02:22)
[GCC 4.4.6 20120305 (Red Hat 4.4.6-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> import readline
Traceback (most recent call last):
  File "<console>", line 1, in <module>
ImportError: No module named readline
>>>

我尝试用 pip 安装 python readline,我得到了这个

 virtualenv/bin/pip-2.7 install readline
Requirement already satisfied (use --upgrade to upgrade): readline in ./virtualenv/lib/python2.7/site-packages/readline-6.2.4.1-py2.7-linux-x86_64.egg
Cleaning up...

我应该怎么办

编辑:

我也试过这个

[myhost]$ virtualenv/bin/python2.7
Python 2.7.3 (default, Nov 23 2012, 18:02:22)
[GCC 4.4.6 20120305 (Red Hat 4.4.6-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import readline
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named readline
>>>

我尝试了所有这些

(virtualenv)[aaaaaa]$ source virtualenv/bin/activate
(virtualenv)[aaaaaa]$ virt
virtualenv/                virtualenv-clone           virtualenvwrapper.sh
virtualenv-2.7             virtualenvwrapper_lazy.sh  virt-what
(virtualenv)[aaaaaa]$ virtualenv/bin/pip
pip      pip-2.7
(virtualenv)[aaaaa]$ virtualenv/bin/pip install readline
Requirement already satisfied (use --upgrade to upgrade): readline in ./virtualenv/lib/python2.7/site-packages/readline-6.2.4.1-py2.7-linux-x86_64.egg
Cleaning up...
(virtualenv)[aaaaa]$ python
Python 2.7.3 (default, Nov 23 2012, 18:02:22)
[GCC 4.4.6 20120305 (Red Hat 4.4.6-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import readline
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named readline
>>>

我尝试了所有虚拟环境并激活了。但我再次得到同样的错误

4

2 回答 2

2

您需要实际激活要使用的环境,而不仅仅是从环境bin文件夹中运行 python 二进制文件:

$ source /path/to/envirn/bin/activate
$ pip install readline
$ python 
> import readline
于 2013-06-27T11:35:09.233 回答
0

对我有用的解决方法是重新安装 readline:

$ source /path/to/env/bin/activate
$ pip uninstall -y readline
Uninstalling readline-6.2.4.1:
  Successfully uninstalled readline-6.2.4.1
$ pip install readline
Collecting readline
Installing collected packages: readline
Successfully installed readline-6.2.4.1
于 2016-02-15T07:17:55.157 回答