【问题标题】:Not able to import readline in django shell python无法在 django shell python 中导入 readline
【发布时间】:2013-06-24 19:55:07
【问题描述】:

我在 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
>>>

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

【问题讨论】:

  • 你到哪儿了吗?我需要创建一个 virtualenv,我无法让它在系统范围内工作。

标签: python django shell readline


【解决方案1】:

您需要actually activate the environment you want to use,而不仅仅是从环境bin 文件夹中运行python 二进制文件:

$ source /path/to/envirn/bin/activate
$ pip install readline
$ python 
> import readline

【讨论】:

    【解决方案2】:

    对我有用的解决方法是重新安装 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
    

    【讨论】:

      猜你喜欢
      • 2021-02-04
      • 1970-01-01
      • 1970-01-01
      • 2012-09-27
      • 2023-04-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-14
      相关资源
      最近更新 更多