我一直在学习python,但我的系统之一上的Python交互式外壳有问题。它在每个python-interactive-mode的开始上运行一个脚本(不带参数)。我不知道在哪里可以找到执行此操作的过程,我已经在该系统上编写了许多小脚本,并且可以看到正在混乱的脚本,
当我这样做时:
user@Host ~/Python Scripts> python
我得到:
Python 3.4.2 (default, Feb 21 2015, 22:19:02)
[GCC 4.9.2 20150212 (Red Hat 4.9.2-6)] on linux
Type "help", "copyright", "credits" or "license" for more information.
# ! / u s r / b i n / e n v p y t h o n
finished
Failed calling sys.__interactivehook__
Traceback (most recent call last):
File "/usr/local/opt/python-3.4.2/lib/python3.4/site.py", line 396, in register_readline
import rlcompleter
File "/usr/local/opt/python-3.4.2/lib/python3.4/rlcompleter.py", line 161, in <module>
readline.set_completer(Completer().complete)
AttributeError: 'module' object has no attribute 'set_completer'
>>> quit()
这是我运行的文件,在每个python开头都运行:
#!/usr/bin/env python
try:
number = int(input("Enter a number: "))
print(number)
aFile = open('modules.py')
for i in aFile:
print(aFile.readline(), end=' ')
except ValueError:
print('Not a number, please re-enter:')
number = int(input('Enter a number: '))
print(number)
except IOError:
print('Cannot open file')
print('finished')
是什么原因引起的,该如何解决?
编辑#1
系统为Fedora 21,文件modules.py和在交互式外壳程序启动时运行的脚本是从未在Windows系统上进行过编辑的脚本。
系统已经11天没有重新引导过。
这是:
~/Python Scripts> file tryexcept.py
tryexcept.py: Python script, ASCII text executable
编辑#2
我当前的工作目录中有一个readline.py:
~/Python Scripts> ls | grep readline
readline.py
最后一部分rlcompleter.py
尝试导入readline,然后运行您出错的行。
try:
import readline
except ImportError:
pass
else:
readline.set_completer(Completer().complete)
# Release references early at shutdown (the readline module's
# contents are quasi-immortal, and the completer function holds a
# reference to globals).
atexit.register(lambda: readline.set_completer(None))
readline.py
您要导入的路径中一定有一个文件,而不是实际的python模块。如果您没有readline.py,但曾经有一次,则查找readline.pyc
文件。
把import readline;print(readline.__file__)
你的解释,看看你导入什么
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句