Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

up/down arrow history doesn't work on pipenv shell on windows #165

Open
dangillet opened this issue Oct 19, 2017 · 17 comments
Open

up/down arrow history doesn't work on pipenv shell on windows #165

dangillet opened this issue Oct 19, 2017 · 17 comments

Comments

@dangillet
Copy link

In the cmd shell, usually you can hit 'up arrow' to get your previous command. Once you run 'pipenv shell', this no longer works. if you run some commands inside the pipenv shell and then hit 'up' it does nothing.

This bug was filed in pipenv issue tracker. According to @erinxocon this is a pew bug.

@erinxocon
Copy link
Collaborator

Indeed! Don't know the cause, I do believe the bug is pew!

@berdario
Copy link
Collaborator

It's a virtualenv issue, already reported

#90

Sorry :/

@crioux
Copy link

crioux commented Oct 27, 2017

This is not the same issue as the virtualenv issue. That's for the python3 interpreter and it has to do with locating the history file for the python interactive shell.

This is for the windows console specifically. Note that things work when using 'conemu' instead of just 'cmd'. See details in #166

@crioux
Copy link

crioux commented Oct 27, 2017

The issue is that the windows console does not interpret the 'arrow keys' as ansi codes, like unix terminals, but rather as virtual keystrokes. The virtual keystrokes are captured by the parent process, and not translated into ansi codes or passed through to the child process windows event loop. The only way to do this is with a windows event hook dll, which translates the virtual keystrokes from the parent console and passes them to the child process event loop. This is what conemu is doing, and every similar subshell under Win32 would have to do. I'm not suggesting this is worth anyone's time, since the workaround (using conemu) is possibly acceptable.

That said, I'm not sure you'd even want this fix if i were to write it. It would involve compiling a binary that gets injected into every window on the system, which is what conemu is doing. One might be able to do it in a less invasive fashion, but it would be some pretty deep win32. I'm willing to give it a shot at some point, unless someone here really wants a go at it.

@crioux
Copy link

crioux commented Oct 27, 2017

Okay, some color on this: There may be a simpler way to fix this.

There's a problem with the generated 'pew.exe' that gets created by setuptools or whatever. Something that executable is doing to launch python is doing so in a manner that is probably piping the stdin/stdout handles or something. Directly executing the process from pew in python without using the 'pew.exe' does what you'd expect:

python -c "from pew import pew; pew.pew()" in <yourvirtualenv> cmd

If you do the above, arrow keys work in cmd.

@berdario berdario reopened this Oct 27, 2017
@berdario
Copy link
Collaborator

Apologies, I was too eager to close the ticket and didn't realize it was actually a different issue

The fact that setuptools would cause the issue could explain why I haven't seen it before while developing.
Is this affecting only cmd.exe or powershell as well?

I don't use Windows day to day, so I haven't tested this first hand,yet... And I don't have plans to fix it with an invasive dll as in your first suggestion

@dangillet
Copy link
Author

I've tested @crioux work around and it indeed works! 😃 🎉

@berdario I've tested in powershell and the problem does not occur there. It's only a problem in cmd.exe it appears.

@crioux
Copy link

crioux commented Oct 27, 2017

Yea, I'm looking into setuptools and working this bug through, I'll let you know what I find.

@garytyler
Copy link

garytyler commented Dec 5, 2017

Any news or other workarounds on this issue? I just want to ask before I spend an evening on some wobbly solution of my own, to allow me to work in the vscode integrated terminal. I'm happy to attempt contributing, but I am far from the best person for a job like this. Thanks!

@crioux 's solution python -c "from pew import pew; pew.pew()" in <yourvirtualenv> cmd does [DEPRECATED] work in a regular cmd shell but not in the vscode integrated terminal.

@crioux
Copy link

crioux commented Dec 7, 2017

I haven't had much time to look into it. I got around it by using ConEmu and my desire to fix it some other was has waned :|

@eli-b
Copy link

eli-b commented Feb 21, 2018

@crioux's workaround doesn't work for me. I just get a list of available commands.
I'm using cmd.exe on Windows 10, with pew 1.1.2 installed in my pipenv virtualenv.

@astewart-xmos
Copy link

I have the same setup as @eli-b, can confirm I get the same results

@askpatrickw
Copy link

It's interesting to note that using the virtualenv-wrapper for windows that workon <env> works as expected from CMD. I suspect its working differently... maybe that method could be adopted by pew or uplevel dependencies aka pipenv could replace pew with that method since they're waiting on a fix from pew. cc: @kennethreitz and @nateprewitt

@fredfalcon
Copy link

what is required to fix this?

@dangillet
Copy link
Author

dangillet commented Apr 7, 2018

I'm not sure. I can just add that using the command python -m pew in <yourvirtualenv> cmd works as well.

So it seems that the problem has something to do with using the pew.exe file.

@RZarifov
Copy link

Found this issue since it is related to the problem I'm facin, so decided to post here, despite the fact it is 2 years old.
The issue is that when I use python interactive console on windows 10 in pipenv, I have no history, so no up and down arrows work.
There is mentioned that pipenv won't use pew anymore, but still, if somebody knows how to handle this issue, I would be much obliged if you help me.

And again: the issue is as described in this thread: pipenv, windows 10, interactive python console, it doesn't save history, so up and down arrows doesn't work. Asking anybody who could help to resolve this issue.

@pfmoore
Copy link
Collaborator

pfmoore commented Aug 17, 2020

There's a problem with the generated 'pew.exe' that gets created by setuptools or whatever. Something that executable is doing to launch python is doing so in a manner that is probably piping the stdin/stdout handles or something.

The code used by the wrappers generated by pip comes from distlib (and via that, from simple_launcher - the relevant bit is here). There's some code in there that ensures the child behaves correctly - maybe something more is needed for history?

If I'm correct, then the issue should probably be raised against that project, but it stands a better chance of being fixed if someone can produce a smaller test case (i.e., something that doesn't need all of pew to reproduce).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests