When I create an python3 virtual-env, tab-completion (default with python3) does not work any more. Why is that?
virtualenv -p /usr/bin/python3 --system-site-packages ~/venv3.site
. ~/venv3.site/bin/activate
Without --system-site-packages
it has the same problem: no tab-completion. If I run python3
without any virtual-env activated, tab-completion works.
This is how I got my tab-completion back:
Added the following to ~/.pythonrc.py
:
try:
import readline
except ImportError:
print("Module readline not available.")
else:
import rlcompleter
readline.parse_and_bind("tab: complete")
Added the following to ~/.bash_profile
:
export PYTHONSTARTUP=$HOME/.pythonrc.py
Quoting Carl Meyer on this GitHub comment,
Yes, one of the uglier aspects of virtualenv's implementation is that it has to have its own copy of the site module, which is used for all virtualenvs regardless of which version of Python they are created with.
The problem is in the $VIRTUAL_ENV/lib/python3.4/site.py
file, which does not setup tab completion. It does not provide the enablerlcompleter
function. Compare it with the site.py file distributed with Python 3.
If you're using Python 3.3 or newer, I advise pyvenv instead of virtualenv
.
python3 -mvenv ~/venv3.site
Another thing you could do is roll your own Python startup script and refer to it in the PYTHONSTARTUP
environment variable. Put tab completion and other startup tweaks in there. See Mike Covington's answer for an example of such script.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With