- How to enable python interactive mode in cygwin
- How to enable python interactive mode in cygwin?
- Using Windows Python from Cygwin
- How can I use my windows Python environment on Cygwin?
- How to enable vim style command line editing in python interpreter in anaconda windows install in cygwin environment
- Overview
- Cygwin
- Installing Python for Cygwin
- Configuring Cygwin
- Configuring Python
How to enable python interactive mode in cygwin
And that seems to work with ipython as well (if installed): Solution 2: 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 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.
How to enable python interactive mode in cygwin?
Try passing the -i flag to Python.
I’ve experienced this very same thing, as have others. There seems to be an issue with cygwin’s ability to operate interactively with native-Windows applications (including Python.exe). If you can, install the cygwin version of Python via cygwin’s package management, as it doesn’t have this interactivity problem.
$ python Python ****** (********) ********************** Type "help", "copyright", "credits" or "license" for more information. >>> "It works" 'It works' >>>
If you supply a file name, or anything like that, it won’t go into interactive mode by default.
A Windows install of ActiveState python won’t enter interactive mode, AND it will be run instead of cygwin Python even if you have cygwin Python installed, because ActiveState python inserts its bin path at the front of your Windows System PATH environment variables.
I solved it by going (in Windows) to Control Panel->System -> Advanced system settings-> Environment variables, choosing PATH, selecting Edit, and cut-pasting all the ActiveState entries from the front to the back of the PATH list.
Using Windows Python from Cygwin
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.
export PYTHONUNBUFFERED=1 /cydrive/c/Python27/python.exe foo.py
/cydrive/c/Python27/python.exe -u foo.py
or run in interactive mode
/cydrive/c/Python27/python.exe -i foo.py
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):
cygstart /cygdrive/c/Python27/python.exe
And that seems to work with ipython as well (if installed):
cygstart /cygdrive/c/Python27/Scripts/ipython.exe
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.
Perhaps if you flush the output
import sys V = range(100000) for x in V: print x sys.stdout.flush()
Matplotlib interactive plots don’t draw, I have faced this problem before. The solution for this problem is: import matplotlib matplotlib.use(«TkAgg») import matplotlib.pyplot as
How can I use my windows Python environment on Cygwin?
Older Cygwin was written with its stdin, stdout, stderr bound to Windows i.e. it was a Win32 console program. Then it was possible to run Windows version of Python as:
/cygdrive/c/Python27/python.exe
You could even have added /cygdrive/. /Pythonxx to your path variable.
Newer versions are written with implemented their own terminals and when you run an Win32 console app like Python it freezes. Even running it under «cmd» run inside cygwin won’t work.
Half an answer is to run it always in interactive mode, then it works a little. Eg.
/cygdrive/c/Python27/python.exe -i program.py
/cygdrive/c/Python27/python.exe -i
You can try playing around under cygwins options, and change a terminal which it currently emulates, to see whether it will do you any good.
Running Windows version of Python under cygwin, if you have older one, will be like you are still in Windows but using Unix console. I think that is not something you would like to do anyway, but mentioned it just in case. I would like to do just that very much, but well, on newer Cygwins it doesn’t work. Then all modules are still there. And you’re still in Cygwin.
To access modules which are in Windows version of Python from Cygwins version you add the Windows site-packages to the Python path variable. On top of your program do:
import sys sys.path.insert(0, "/cygdrive/c/Python27/lib/site-packages")
Then you can import them normally. But, this isn’t exactly advisable. For example, all modules that depend on windows paths could have great problems. Or those written in C wouldn’t exactly like been called from Cygwin. Especially when Cygwin’s Python version number and Windows’s one aren’t the same. I tried with pyaudio, it collosaly crashed. Some of them (mostly the little ones) will work just fine.
But, IMPORTANT NOTE here is, depending on the place you insert your Windows site-packages path the directory will be searched. If you put it in place 0, Python will look at it firstly. Then, it is perhaps better to use:
sys.path.append("/cygdrive/c/Python27/lib/site-packages")
If some package is packed into an EGG or ZIP archive, you will have to add it separately to the path. The same goes for subdirectories. You try and keep thumbs up.
If you don’t want to do that, you can:
import os wd = os.getcwd() os.chdir("/cygdrive/c/Python27/lib/site-packages") # Your Windows imports here os.chdir(wd)
Sometimes you will have to do both.
You can add even a check, so that your program works in both environments nicely:
It will work without a check, but it is stupid to bother Python with twice added same directory into the path.
Copying the packages will save you from these extra lines of code, but the problems I mentioned above will remain the same. Never the less, if the modules are small, copy them, if not, do as I said, but be aware that it’s not exactly something that is supposed to be done.
How to use Thread extension for Tcl using Cygwin, If it does not exist on the cygwin installer, how can I install it and I think Python is too heavy, anyway, I would like to hear any
How to enable vim style command line editing in python interpreter in anaconda windows install in cygwin environment
winpty-0.4.3-cygwin-2.8.0-x64.tar.gz
https://github.com/rprichard/winpty/releases
and extracted it to /usr/local of cygwin installation.
readline config needs to be in $HOME of cygwin as opposed to c:\users\
$ cp /usr/local/anaconda3/Lib/site-packages/pyreadline/configuration/startup.py $HOME $ cp /usr/local/anaconda3/Lib/site-packages/pyreadline/configuration/pyreadlineconfig.ini $HOME
With above setup, when I run anaconda python as
$ PATH=/usr/local/anaconda3/Library/bin:$PATH winpty /usr/local/anaconda3/python
vi style command line editing works fine.
How to enable Command Line Editing in Python interactive mode?, I noticed that on my two Python 3 installations (v3.7 and v3.9), running from Cygwin bash, the command line editing feature (like history
Overview
Python is a powerful scripting language that can be used to manipulate many data types. It can also be used with Fortran code to do complex mathematical tasks with the fast speed typical of Fortran programs but with the benefit of Python structures for dealing with complicated data formats and files.
Integrated Development Environments (IDEs) exist for Python. However, this page describes how to install and configure Python for Cygwin, and focuses on interacting with Python using its Command Line Interface (CLI) via the Cygwin Terminal.
Cygwin
Cygwin is a Linux emulator for Windows that contains packages, including coding tools such as compilers and run-time components, which may be difficult to install on Windows as standalone programs themselves. Cygwin provides its own operating environment that interacts with Windows. Programs and commands are run in Cygwin using the Cygwin terminal.
Installing Python for Cygwin
Packages are installed for Cygwin using its setup utility, setup-x86_64.exe for 64-bit (source: http://cygwin.com/install.html).
By default, the Cygwin setup utility asks for elevated Administrative permissions. These are not necessary to install and update the base Cygwin environment. When elevated Administrative permissions are not available from the User account, run the program with the » —no-admin » option.
This can be done via a Windows «Shortcut»: After browsing to the location of the Cygwin setup utility, add » —no-admin » to the end of the path:
Alternatively, this can be done by starting the program from Command Prompt (cmd.exe) by specifying the path to the program and adding » —no-admin » to the end of the path before running the program:
Configuring Cygwin
If the Python packages as described are not listed, check if the packages are labelled with a variant of the Python version. For example, Cygwin previous included packages under the «python2» and «python3» name, such as «python2-pip» and «python3-pip». Sometimes the packages, and corresponding Python version are updated, and the packages may be renamed. In this case, check for variants that include a minor version, such as «python27-pip» and «python36-pip».
When selecting packages to install, toggle the action at the top-right of the Cygwin setup utility to «Keep» to preserve versions of packages that are already installed.
- Run the Cygwin setup utility
- Continue through setup until prompted to select packages to install:
- Search for and mark the following packages for installation:
To mark a package for installation, change the option under the «Current» column from blank to a version number:
- Base packages:
- \All\Devel\make
- \All\Devel\gcc-core
- \All\Devel\gcc-fortran
- \All\Devel\gcc-g++
- \All\Python\python27
- \All\Python\python27-devel
- \All\Python\python27-numpy
- \All\Python\python27-pip
- \All\Python\python36
- \All\Python\python36-devel
- \All\Python\python36-numpy
- \All\Python\python36-pip
- \All\Libs\libfreetype-devel
- \All\Libs\libpng-devel
Cygwin may automatically select other packages to install, which are dependencies that are required for the user-selected packages to install. This is normal.
- Continue through setup until the packages have been installed
Configuring Python
«python» may not exist as a program, especially if more than one version of Python is installed:
In this case, include the version in the call to Python:
Or create an alias to attach this program to the common name «python», either temporarily at the prompt or by adding the command to the end of the «.bashrc» file inside the /home/username/ folder to use this alias permanently:
If a specific version of python was installed, such as «python27», the «python» program will include the version number in its name (e.g., «python2.7.exe»):
To distinguish between Python 2 or Python 3, consider creating aliases to the specific version but preserving «2» and «3» in the name. Furthermore, include this version when calling Python explicitly: