Set up Cygwin with Python executables

0

I have a Windows 8 laptop on which I have used Python for some time. I have both 3.3 and 2.7 installed, along with several libraries. I recently installed Cygwin, and am enjoying it immensely. I noticed Python in the list of installable packages, and was wondering if it would be possible to tell Cygwin to use the Python executables, instead of trying to duplicate everything within Cygwin.

Is this possible? Is it a good idea? If so, how would I do it?

Matthew

Posted 2014-08-23T18:11:59.770

Reputation: 217

Answers

1

It's definitely possible. The easiest way to do it would be to call Windows Python explicitly when you want to run a Python script. If you were doing it from a Cygwin shell, you'd probably want a command that looked something like this:

/cygdrive/c/Python27/python.exe script.py

That calls Python with your script as an argument, and should run it in pretty much the same way as if it were run from Windows.

However "possible" is not the same as "sensible". I'd strongly recommend using Cygwin Python from within Cygwin; there are a whole bunch of ways in which Cygwin and Windows Python will interact in bad or unexpected ways. Off the top of my head:

  • Windows Python expects a terminal that acts like the Windows cmd terminal; MinTTY and other Cygwin terminals behave differently, so you're likely to see unexpected behaviour relating to printing things to the terminal. As a specific example, if a Python command is printing a bunch of messages to the terminal at a slow rate, such as ongoing progress messages for some long-running process, they're likely to be cached and written all at once when there's 64 kB of them

  • Cygwin's shell will automatically expand globs, like *.txt, before passing them as arguments to a script. Windows' command line doesn't do that, meaning anything involving characters like * or ? as a script argument may be interpreted in unexpected ways.

  • Cygwin programs generally use Linux-style line endings (LF), while Windows programs generally use Windows-style line endings (CRLF). Cygwin and Windows Python are no different, and you can get errors or unexpected behaviour with string handling and processing if the line endings in a file aren't as the program expects.

None of these are problems that can't be worked around with care, attention and awareness, but if you just opt to use Cygwin Python in Cygwin, you're far less likely to need to work around the problems in the first place.

me_and

Posted 2014-08-23T18:11:59.770

Reputation: 2 118