Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Comments on Console scripts in virtual environment do not output to terminal in git bash
Post
Console scripts in virtual environment do not output to terminal in git bash
I have console scripts in my virtual environment in \env\Scripts
, installed with packages (e.g. black, pytest, coverage). If I try to execute these in Git Bash, the output is not returned to the terminal.
If I use the command line tool for e.g. black with a virtual enviroment activated in Git Bash, I get a blank line returned, but no response:
$ black version.py
If I invoke black through python, I get the expected response:
$ python -m black version.py
All done! ✨ � ✨
1 file left unchanged.
If I invoke the command line tool using black from the system interpreter (i.e. not using the virtual environment), I get the expected response:
$ black version.py
All done! ✨ � ✨
1 file left unchanged.
If I pipe the output to a file, I get the output in the terminal, but nothing in the file:
$ black version.py > test.txt
All done! ✨ � ✨
1 file left unchanged.
If I invoke the command line tool with Microsoft cmd, I get the expected response:
λ black version.py
All done! ✨ � ✨
1 file left unchanged.
If I invoke the command line tool with a blank virtual environment, I get the expected response.
$ python -m venv env
$ . ./env/Scripts/activate
$ pip install black
$ black version.py
All done! ✨ � ✨
1 file left unchanged.
If I try to pip uninstall black, sys.stderr seems to be missing:
$ pip uninstall black
Found existing installation: black 22.1.0
Uninstalling black-22.1.0:
Would remove:
c:\users\XXX\env\lib\site-packages\_black_version.py
c:\users\XXX\env\lib\site-packages\black-22.1.0.dist-info\*
c:\users\XXX\env\lib\site-packages\black\*
c:\users\XXX\env\lib\site-packages\black_primer\*
c:\users\XXX\env\lib\site-packages\blackd\*
c:\users\XXX\env\lib\site-packages\blib2to3\*
c:\users\XXX\env\lib\site-packages\c249b57082ff69932638__mypyc.cp39-win_amd64.pyd
c:\users\XXX\env\scripts\black-primer.exe
c:\users\XXX\env\scripts\black.exe
c:\users\XXX\env\scripts\blackd.exe
ERROR: Exception:
Traceback (most recent call last):
File "C:\Users\XXX\env\lib\site-packages\pip\_internal\cli\base_command.py", line 167, in exc_logging_wrapper
status = run_func(*args)
File "C:\Users\XXX\env\lib\site-packages\pip\_internal\commands\uninstall.py", line 97, in run
uninstall_pathset = req.uninstall(
File "C:\Users\XXX\env\lib\site-packages\pip\_internal\req\req_install.py", line 638, in uninstall
uninstalled_pathset.remove(auto_confirm, verbose)
File "C:\Users\XXX\env\lib\site-packages\pip\_internal\req\req_uninstall.py", line 363, in remove
if auto_confirm or self._allowed_to_proceed(verbose):
File "C:\Users\XXX\env\lib\site-packages\pip\_internal\req\req_uninstall.py", line 403, in _allowed_to_proceed
return ask("Proceed (Y/n)? ", ("y", "n", "")) != "n"
File "C:\Users\XXX\env\lib\site-packages\pip\_internal\utils\misc.py", line 186, in ask
response = input(message)
RuntimeError: input(): lost sys.stderr
The script is where I would expect it:
$ which black
/c/Users/XXX/env/Scripts/black
I get similar results with coverage and pytest. I re-installed Git for Windows. I am using Python 3.9.9. It feels like an environment variable or something related to the PATH that messes up stderr/stdout.
I understand this is a very specific situation, probably related to the repository that I am currently working on (which I installed in editable mode with pip install -e .
).
Could somebody point me in the right direction to fix this?
1 comment thread