macOS 10.12.6 Python 3.6.2 pipenv 6.1.6
When I run the CPython REPL from a standard shell tab completion is operative. When I run it via pipenv (pipenv run python3
or pipenv shell
then python3
) tab completion is not operative.
Is this a bug, or a configuration failure on my part?
I'm not sure! Very interesting.
Can you test with a standard virtualenv and see if it's the same? Might be a pew side-effect.
Tab completion is operative under a standard virtualenv.
Now create one with pew.
i believe it's $ pew newvenv
The finger seems to point at pew ... tab completion is not operative.
Let's open an issue over there and link to it here!
Will do.
鉁煃扳湪
so apparently this code activates tab complete:
import rlcompleter, readline
readline.parse_and_bind('tab: complete')
when i run this, it enables autocomplete.
maybe this code is being excluded from site.py
or something, in pew.
Will use the rlcompleter / readline code as a fix for now. Thanks!
Thanks for noticing this!
Rather than the parse_and_bind
call shown above I had to use
readline.parse_and_bind('bind ^I rl_complete')
.
Maybe it's a macOS thing.
Interesting, it worked for me on MacOS.
site.py
from the Python library has the following code in enablerlcompleter()
# Reading the initialization (config) file may not be enough to set a
# completion key, so we set one first and then read the file.
readline_doc = getattr(readline, '__doc__', '')
if readline_doc is not None and 'libedit' in readline_doc:
readline.parse_and_bind('bind ^I rl_complete')
else:
readline.parse_and_bind('tab: complete')
Maybe we have different arrangements for accessing a readline library on our respective machines.
@ColMcp can you add this as a comment on https://github.com/kennethreitz/pipenv/issues/497#issuecomment-328190362 ?
Closing for https://github.com/berdario/pew/issues/150
This issue and https://github.com/pypa/pipenv/issues/207 share the same inconvenience at the end of the day.
As a workaround, I often use this
$ source $(pipenv --venv)/bin/activate
Would it be reasonable to have this documented as a workaround for the series of tab/auto-complete issue presented by pew
/subshell/virtualenv
? Or even have it as the underlying call when we invoke $ pipenv shell
?
@woozyking how does
$ source $(pipenv --venv)/bin/activate
help in any manner ?
$ pipenv shell
Spawning environment shell (/bin/bash). Use 'exit' to leave.
source /Users/woozyking/.local/share/virtualenvs/test-HaxrPBoG/bin/activate
bash-3.2$ source /Users/woozyking/.local/share/virtualenvs/test-HaxrPBoG/bin/activate
(test-HaxrPBoG) bash-3.2$ # tab completion works partially, not working, for example git commands
$ source $(pipenv --venv)/bin/activate
(test-HaxrPBoG) woozyking-air:test woozyking$ # tab completion works
Not to say it's a definitive solution, but a work around (and may very well be superficial) that works.
@woozyking Thanks ! So this helps with the shell completion, and not the one from the python interpreter, right ?
@ngirard yep
I also had problem using tab-completion in pip-env shell
, source $(pipenv --venv)/bin/activate
works for me though. My situation: largely using packages, including python, from Nix pkgs on top of Ubuntu 16.04.
My hack and forget work around is to write a ~/.pyrc
file
import sys, os
if (sys.version_info[0] == 2) or ('PIPENV_ACTIVE' in os.environ):
try:
import readline
except ImportError:
print("Module readline not available.")
else:
import rlcompleter
readline.parse_and_bind("tab: complete")
del readline, rlcompleter
del sys, os
And to export PYTHONSTARTUP=~/.pyrc
in my shell rc script (export PYTHONSTARTUP=~/.pyrc
in ~/bashrc
for the bash case)
Thanks @andyneff, that's very useful! :) I was disappointed to see that PYTHONSTARTUP is not read when using inspect. And neither does the source $(pipenv --venv)/bin/activate
workaround.
@andyneff I still see the same problem with Python 3.7. Why did you test for Python 2 in your .pyrc
?
@wichert At the time, I was not having the same issue on my python 3. If you are, then by all means, remove the test for Python 2
Hi, consider re-opening this please. It was closed after a new bug was filed against pew. However it doesn't seem they're going to fix it. The issue is with virtualenv
.
Indeed when I create a virtual environment with virtualenv
tab completion does not work, however if I create one with venv
it does. Could pipenv
use venv
instead?
(Note: If I sound frustrated, I am. It鈥檚 not really your fault, but because I need to say the same thing so many times.)
We鈥檝e been through this many times in the issue tracker already. venv support is not currently viable because we can鈥檛 drop Python 2 support yet, and do not have resources to maintain two backends (or more, venv is not as compatible across Python releases as you might imagine).
If you want to help, try fix this for virtualenv.
venv also is inferior
Python 2 is EOL now, so perhaps this could be revisited.
Most helpful comment
My hack and forget work around is to write a
~/.pyrc
fileAnd to export
PYTHONSTARTUP=~/.pyrc
in my shell rc script (export PYTHONSTARTUP=~/.pyrc
in~/bashrc
for the bash case)