Menu
Python3 on cygwin. Ask Question 9. How does one install Python3 on cygwin? I tried running the Python install in cygwin with no success. The version I am looking for is >= 3.1, and I was able to install 2.7 successfully under cygwin (which comes with 2.6 as the default).
This is working almost perfectly, except for printing. When I run the Windows Python from Cygwin the output doesn't print until execution finishes. It works fine running in Windows Python from explorer.exe or cmd.exe, and it works in Cygwin using the Cygwin-installed Python (
/bin/python.exe ).
Is there a workaround for this? The important thing is to be able to run the Windows version, but I'd like to do it all from with Bash.
SkilldrickSkilldrick
3 Answers![]()
AmroAmro
The real problem is that when you run a command in any of the Cygwin terminal programs like mintty, they don't act as Windows Consoles. Only Windows Console-based ones like CMD or Console2 do that. So, with Cygwin terminals the Windows python.exe doesn't think it is talking to an interactive console.
That leads to buffering output instead of flushing buffers on every line as is done in interactive sessions. That is why Amro's adding the flush() on every line fixes the symptom, but means changing the code.
One solution without changing the code is to turn off buffering in Python using the '-u' flag on the command line or setting the PYTHONUNBUFFERED environment variable.
or
or run in interactive mode
You will also not be able to run the Windows python.exe interactive mode in the Cygwin terminal. It will not bring up an interactive session, but will just hang. I find the best solution seems to be to use 'cygstart' (better than using the '-i' option):
And that seems to work with ipython as well (if installed):
noisygeckonoisygecko
Not answering the initial question, but for those who want to use Python interactive session from within Cygwin terminal (for example in mintty) - start Python with '-i' option to tell it explicitly that it needs to run in interactive mode:
The neat way is also to create an alias in your .bashrc (knowing that it is only read for interactive terminal sessions anyway):
Otherwise, Python will not know that it runs in the console, because all Cygwin pty-based terminals (mintty, rxvt and xterm) are recognized as pipes by Windows, not as the console. Therefore, Python thinks there is no console and enters non-interactive mode. So, if you still want interactive mode instead, you need to explicitly tell Python to use it. However, it still won't behave as it normally should - one still won't be able to use HOME or LEFT ARROW keys, and so on.
![]()
TimurTimur
Not the answer you're looking for? Browse other questions tagged pythonwindowscygwin or ask your own question. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |