python-gnureadline icon indicating copy to clipboard operation
python-gnureadline copied to clipboard

python interactive shell crashed with `munmap_chunk(): invalid pointer` after installed `readline`.

Open liudonghua123 opened this issue 1 year ago • 1 comments
trafficstars

I found my python maybe lack of readline functionalities. If I entered the interactive shell, I could not use tab to do auto-completion or use navigation key like up/down to use history commands or input backspace (produce ^H). So I tried to installed readline package, but after installed, the interactive shell always crashed when execute any commands.

[root@localhost dockerfile-from-image]# python
Python 3.11.0 (main, Apr 23 2023, 12:29:15) [GCC 11.3.1 20220421 (Red Hat 11.3.1-2)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import readline
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'readline'
>>> import rlcompleter 
>>> ^H^H^C
KeyboardInterrupt
>>> exit()
[root@localhost dockerfile-from-image]#
[root@localhost dockerfile-from-image]# pip install readline
Collecting readline
  Downloading readline-6.2.4.1.tar.gz (2.3 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 2.3/2.3 MB 1.6 MB/s eta 0:00:00
  Preparing metadata (setup.py) ... done
Building wheels for collected packages: readline
  Building wheel for readline (setup.py) ... done
  Created wheel for readline: filename=readline-6.2.4.1-cp311-cp311-linux_x86_64.whl size=333498 sha256=6f19ff752265f1f078a803c0b703375d8b5bb100477c9572199f4ffde7d7b723
  Stored in directory: /root/.cache/pip/wheels/c8/81/5e/329aa6245c9520e99ef1eb24b0b360a7eaf6dabc812ffb8640
Successfully built readline
Installing collected packages: readline
Successfully installed readline-6.2.4.1
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv

[notice] A new release of pip is available: 23.1.1 -> 23.3.1
[notice] To update, run: pip install --upgrade pip
[root@localhost dockerfile-from-image]# python
Python 3.11.0 (main, Apr 23 2023, 12:29:15) [GCC 11.3.1 20220421 (Red Hat 11.3.1-2)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import docker
munmap_chunk(): invalid pointer
Aborted (core dumped)
[root@localhost dockerfile-from-image]#
[root@localhost dockerfile-from-image]# python
Python 3.11.0 (main, Apr 23 2023, 12:29:15) [GCC 11.3.1 20220421 (Red Hat 11.3.1-2)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> print(123)
munmap_chunk(): invalid pointer
Aborted (core dumped)
[root@localhost dockerfile-from-image]# pip uninstall readline
Found existing installation: readline 6.2.4.1
Uninstalling readline-6.2.4.1:
  Would remove:
    /usr/local/lib/python3.11/site-packages/readline-6.2.4.1.dist-info/*
    /usr/local/lib/python3.11/site-packages/readline.cpython-311-x86_64-linux-gnu.so
Proceed (Y/n)? y
  Successfully uninstalled readline-6.2.4.1
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
[root@localhost dockerfile-from-image]# python
Python 3.11.0 (main, Apr 23 2023, 12:29:15) [GCC 11.3.1 20220421 (Red Hat 11.3.1-2)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> print(123)
123
>>> import gnureadline as readline
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'gnureadline'
>>>

liudonghua123 avatar Dec 07 '23 01:12 liudonghua123

Hi @liudonghua123, sorry for the wait, I missed this... You need to pip install gnureadline. The readline package is an older version that is deprecated. I am working on a better way to override the Python tab completion so that your use case can be achieved. Have a look at the override-readline-via-site-customization branch if you are curious.

ludwigschwardt avatar Apr 19 '24 12:04 ludwigschwardt