Opened 7 years ago

Closed 5 years ago

#45301 closed defect (worksforme)

spacebar not recognized in python macport version

Reported by: manzotti.alessandro@… Owned by: macports-tickets@…
Priority: Normal Milestone:
Component: ports Version: 2.3.1
Keywords: Cc:
Port: python27

Description

My problem is that when I run a python version, obtained through macport, from the bash the spacebar is not recognized in the python shell. When I press the spacebar I just hear the beep sound.

Using different shell does not seem to solve the problem.

This does NOT happen when I compile Python from source or when I used the python already installed in the system. I am running OSX 10.9.5. I compiled different python version and they work fine so it does not seem to be related to the version of python I am using.

And it happen only with python/ipython I have never seen this problem with other application or in my bash.

It seems to be something related to how Macport python is compiled (maybe some libreadline issue?).

For example this version I compiled does not have the problem

otool -L /Users/alessandromanzotti/Python2.7.8/bin/python2.7 
/Users/alessandromanzotti/Python2.7.8/bin/python2.7:
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1197.1.1)
	/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 855.17.0)
	/usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 2577.0.0)

And also the system python works fine

otool -L /usr/bin/python
/usr/bin/python:
	/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 855.14.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1197.1.1)

But all the macport version show the same problem

otool -L /opt/local/bin/python
/opt/local/bin/python:
	/opt/local/Library/Frameworks/Python.framework/Versions/2.7/Python (compatibility version 2.7.0, current version 2.7.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1197.1.1)

Change History (15)

comment:1 Changed 7 years ago by larryv (Lawrence Velázquez)

This is almost certainly a problem with your setup. I don’t experience this problem, and this is the first time I’ve ever heard of this happening.

What does this tell you?

(
cd /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload
otool -L {_curses,_curses_panel,readline}.so
)
Last edited 7 years ago by larryv (Lawrence Velázquez) (previous) (diff)

comment:2 in reply to:  1 ; Changed 7 years ago by manzotti.alessandro@…

Replying to larryv@…:

This is almost certainly a problem with your setup. I don’t experience this problem, and this the first time I’ve ever heard of this happening.

What does this tell you?

(
cd /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload
otool -L {_curses,_curses_panel,readline}.so
)

Thanks I agree. But it still does not happen with python compile in a different way.

_curses.so:
	/opt/local/lib/libncurses.5.dylib (compatibility version 5.0.0, current version 5.0.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1197.1.1)
_curses_panel.so:
	/opt/local/lib/libpanel.5.dylib (compatibility version 5.0.0, current version 5.0.0)
	/opt/local/lib/libncurses.5.dylib (compatibility version 5.0.0, current version 5.0.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1197.1.1)
readline.so:
	/opt/local/lib/libedit.0.dylib (compatibility version 1.0.0, current version 1.42.0)
	/opt/local/lib/libncurses.5.dylib (compatibility version 5.0.0, current version 5.0.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1197.1.1)

comment:3 in reply to:  2 Changed 7 years ago by manzotti.alessandro@…

I noticed that I do not have the readline library in the python version that does not show the problem.

/Python2.7.5/lib/python2.7/lib-dynload$ otool -L {_curses,_curses_panel,readline}.so
_curses.so:
	/usr/lib/libncurses.5.4.dylib (compatibility version 5.4.0, current version 5.4.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1197.1.1)
	/usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 2577.0.0)
_curses_panel.so:
	/usr/lib/libpanel.5.4.dylib (compatibility version 5.4.0, current version 5.4.0)
	/usr/lib/libncurses.5.4.dylib (compatibility version 5.4.0, current version 5.4.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1197.1.1)
	/usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 2577.0.0)
error: otool: can't open file: readline.so (No such file or directory)

Maybe this tells something?

comment:4 Changed 7 years ago by larryv (Lawrence Velázquez)

Can’t say I know where to go from here. I suggest emailing macports-users to tap a wider audience.

comment:5 Changed 7 years ago by ned-deily (Ned Deily)

This doesn't ring a bell with me, either. Just to confirm, by Python shell, you mean something like:

$ /opt/local/bin/python2.7
Python 2.7.8 (default, Oct  4 2014, 09:21:32)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.51)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 

And typing space here gives the beep? If so, the most likely explanation is an incompatible command in either a PYTHONSTARTUP file (https://docs.python.org/2/using/cmdline.html#envvar-PYTHONSTARTUP) or in the libedit .editrc file (https://developer.apple.com/library/mac/documentation/Darwin/Reference/Manpages/man5/editrc.5.html). Python can be linked with either BSD editline (libedit) (the default on OS X), GNU readline, or with neither. Keep in mind that the syntax of configuration command for libedit are different than those for GNU readline (https://docs.python.org/2/library/readline.html). If you want to use GNU readline with the MacPorts Python, you can port install py27-readline.

comment:6 in reply to:  5 Changed 7 years ago by manzotti.alessandro@…

Hi all thanks for the help.

The problem is exactly with the py27-readline package. When I install it I have the problem which disappears once I uninstall it.

That is installed because I need Ipython that depends on it. Is there a way to try to force ipython to use libedit instead of gnureadline?

Or does anyone know what the problem with the py27-gnureadline package could be?

Thanks

comment:7 Changed 7 years ago by ned-deily (Ned Deily)

Have you checked whether you define a PYTHONSTARTUP environment variable that has editline specific commands in it? Try python -E to ignore env variables and see if that works. Also check what terminal def is in use: echo $TERM.

For what it's worth, it is possible to write a python startup file (pointed to by PYTHONSTARTUP) that will work with Python 2.7.x or 3.x and with Pythons using either libedit or GNU readline. For example:

from pprint import pprint as pp
try:
    import readline
    import rlcompleter
    if 'libedit' in readline.__doc__:
        readline.parse_and_bind("bind ^I rl_complete")
    else:
        readline.parse_and_bind("tab: complete")
except ImportError:
    pass

comment:8 in reply to:  7 Changed 7 years ago by manzotti.alessandro@…

No I do not think it has nothing to do with my PYTHONSTARTUP file. The error is independent of that and it is there even with python -E.

My $TERM is xterm-256color

Thanks

comment:9 Changed 7 years ago by ned-deily (Ned Deily)

Ah, one last thought: make sure Python is really importing the right readline.so and check the library dependencies on it with otool -L. I forgot that py27-readline installs its own version of readline.so (in site-packages/readline) and then does some fancy sys.path manipulation at Python startup to ensure that its readline.so is found before the standard library readline.so (linked with libedit).

>>> import readline
>>> readline.__file__
'/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/readline/readline.so'

$  otool -L '/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/readline/readline.so'
/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/readline/readline.so:
	/opt/local/lib/libncurses.5.dylib (compatibility version 5.0.0, current version 5.0.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1213.0.0

Note that the py27-readline readline.so is statically linked with GNU readline.

Last edited 7 years ago by ned-deily (Ned Deily) (previous) (diff)

comment:10 Changed 7 years ago by ned-deily (Ned Deily)

Added: you may just need to rebuild/reinstall py27-readline or perhaps, if you are using a binary package, the binary package is too old. It needs to be rebuilt when python27 is updated. I build all my MacPorts packages from source so I wouldn't see that kind of problem.

comment:11 in reply to:  10 Changed 7 years ago by manzotti.alessandro@…

I have the same, with a slight older version of libSystem.B.dylib

otool -L /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/readline/readline.so
/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/readline/readline.so:
	/opt/local/lib/libncurses.5.dylib (compatibility version 5.0.0, current version 5.0.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1197.1.1)

I have uninstalled and installed py27-readline several times. plus in my mac port config I forced it to build everything from source. If there is something I can do manually I can try.

comment:12 Changed 7 years ago by ned-deily (Ned Deily)

Sorry, I don't know what else to suggest other than verifying exactly what version and variants of the ports you have intstalled. You aren't by any chance using a +ucs4 variant of python27 are you? In any caee, the py27-readline port is seriously out-of-date (the upstream version moved and was renamed); it's somewhat surprising it works at all. See ticket:44206 for details. Here's what I have currently installed (note I have universal enabled):

$ port info python27 py27-readline
python27 @2.7.8_3 (lang)
Variants:             ucs4, (+)universal
[...]
--
py27-readline @6.2.4.1 (python)
Variants:             (+)universal
[...]

comment:13 in reply to:  12 ; Changed 7 years ago by mf2k (Frank Schima)

Replying to nad@…:

Please instead show us the output of the following, because port info doesn't tell us anything about your installed state of the ports.

port installed python27 py27-readline

comment:14 in reply to:  13 Changed 7 years ago by manzotti.alessandro@…

Replying to mf2k@…:

Replying to nad@…:

Please instead show us the output of the following, because port info doesn't tell us anything about your installed state of the ports.

port installed python27 py27-readline
port installed python27 py27-readline
The following ports are currently installed:
  py27-readline @6.2.4.1_0 (active)
  python27 @2.7.8_3 (active)

Here it is:

port info python27 py27-readline
python27 @2.7.8_3 (lang)
Variants:             ucs4, universal

Description:          Python is an interpreted, interactive, object-oriented programming language.
Homepage:             http://www.python.org/

Extract Dependencies: xz
Library Dependencies: gettext, zlib, openssl, sqlite3, db48, ncurses, bzip2, libedit
Runtime Dependencies: python_select
Platforms:            darwin
License:              PSF
Maintainers:          jwa@macports.org, openmaintainer@macports.org
--
py27-readline @6.2.4.1 (python)
Variants:             universal

Description:          GNU readline extension for Python
Homepage:             http://github.com/ludwigschwardt/python-readline

Build Dependencies:   py27-setuptools
Library Dependencies: python27
Platforms:            darwin
License:              GPL-3+ PSF
Maintainers:          nomaintainer@macports.org

comment:15 Changed 5 years ago by mf2k (Frank Schima)

Port: python27 added
Resolution: worksforme
Status: newclosed

I don't see what can be done here.

Note: See TracTickets for help on using tickets.