somethingSomething somethingSomething - 3 months ago 66
Python Question

Errors when I start the Python shell, errors from a script I ran a week ago

I've been learning python and I there is a problem with my Python interactive shell on one of my systems. It runs a script on every python-interactive-mode start(without arguments). I don't know where to look for a process that does this, I've programmed a lot of small scripts on this system, and I can see what script is messing around,

When I do this:

user@Host ~/Python Scripts> python


I get:

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()


Here is the file I ran, and is run on every python start:

#!/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')


What is causing this and how do I fix it?

EDIT #1

The system is Fedora 21, the file modules.py and the script that runs on start of the interactive shell are scripts that have never been edited on a Windows system.

The system has not been rebooted for 11 day's.

Here is:

~/Python Scripts> file tryexcept.py
tryexcept.py: Python script, ASCII text executable


EDIT #2

I have a readline.py in my current working directory:

~/Python Scripts> ls | grep readline
readline.py

Answer

The last part of rlcompleter.py trys to import readline and then runs the line you error on.

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))

There must be a readline.py file somewhere in your path that you are importing instead of the actual python module. If you don't have a readline.py but once had then look for a readline.pyc file.

Put a import readline;print(readline.__file__) in your interpreter and see what exactly you are importing