Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Fix broken python and pdb interactive prompts in virtualenv with MacPorts python (using libedit instead of readline)
# Problem: borked readline in virtualenv
#
# Sample python interactive session:
#
# $ python
# Python 3.5.1 (default, Dec 29 2015, 10:15:41)
# [GCC 4.2.1 Compatible Apple LLVM 7.0.2 (clang-700.1.81)] on darwin
# Type "help", "copyright", "credits" or "license" for more information.
# >>> "type an expression and press enter"
# >>> 'type an expression and press enter'
# _
#
# notice the prompt printed before the evaluated expression and the caret is on a blank line
# update: for Python 3.6
# https://trac.macports.org/ticket/48807#comment:121
sudo port install python36 +readline
# for python < 3.6
# assuming virtuanenv created with --python=/opt/local/bin/pythonX.Y
# replace X and Y with your python major/minor versions
sudo port install pyXY-readline
deactivate
# if it's easy to rebuild the virtualenv then just delete and rebuild it
# if you prefer to live dangerously you can try this instead to create a
# new virtualenv and then monkey-patch it with the old virtualenv contents
mv $WORKON_HOME/venv-name $WORKON_HOME/venv-name-borked-readline
mkvirtualenv --python=/opt/local/bin/pythonX.Y venv-name
cd $WORKON_HOME/venv-name
# may want to do this with --dry-run (-n) first
rsync -av --ignore-existing ../venv-name-borked-readline/ .
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.