python3 import idlelib.PyShell fails

Peter Otten __peter__ at web.de
Sun Jun 30 07:20:24 EDT 2013


Helmut Jarausch wrote:

> Hi,
> 
> I have a strange error. When I try import idlelib.PyShell from Python3.3
> it fails with
> 
> Python 3.3.2+ (3.3:68ff68f9a0d5+, Jun 30 2013, 12:59:15)
> [GCC 4.7.3] on linux
> Type "help", "copyright", "credits" or "license" for more information.
>>>> import idlelib.PyShell
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
>   File "/usr/lib64/python3.3/idlelib/PyShell.py", line 29, in <module>
>     from idlelib.EditorWindow import EditorWindow, fixwordbreaks
>   File "/usr/lib64/python3.3/idlelib/EditorWindow.py", line 11, in
>   <module>
>     import webbrowser
>   File "/usr/lib64/python3.3/webbrowser.py", line 7, in <module>
>     import shlex
>   File "./shlex.py", line 56
>     print 'shlex: reading from %s, line %d' \
>                                           ^
> SyntaxError: invalid syntax
> 
> 
> Looking at shlex.py from /usr/lib64/python3.3 there is no print
> statement in line 56.
> 
> But, looking at /usr/lib/python2.7/shlex.py there is this print statement
> in line 56.
> 
> Why does idlelib.PyShell when imported from Python3 import shlex from
> Python2 ?
> 
> What's going on here?
> 
> Many thanks for a hint,
> Helmut.

Look at the traceback again. There's a shlex.py in your working directory. 
That takes precendence over the one belonging to Python 3.3:

$ ls
$ python3.3 -c 'import idlelib.PyShell'
$ cp /usr/lib/python2.7/shlex.py .
$ python3.3 -c 'import idlelib.PyShell'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/local/lib/python3.3/idlelib/PyShell.py", line 28, in <module>
    from idlelib.EditorWindow import EditorWindow, fixwordbreaks
  File "/usr/local/lib/python3.3/idlelib/EditorWindow.py", line 11, in 
<module>
    import webbrowser
  File "/usr/local/lib/python3.3/webbrowser.py", line 7, in <module>
    import shlex
  File "./shlex.py", line 56
    print 'shlex: reading from %s, line %d' \
                                          ^
SyntaxError: invalid syntax
$ 





More information about the Python-list mailing list