How to change version of Python picked up by Cygwin

Question:

I have two versions of python installed on Win7. (Python 2.5 and Python 2.7).

These are located in ‘C:/Python25’ and ‘C:/Python27’ respectively.

I am trying to run a file using Python 2.5 but by default Cygwin picks up 2.7.

How do I change which version Cygwin uses?

Asked By: Robert Whitley

||

Answers:

The fast way is to reorder your $PATH so that 2.5 is picked up first.
The correct way is to use virtualenv to create a jail environment that’s specific to a python version.

Answered By: canadadry

As an addition to Bon’s post, if you’re not sand-boxing your not doing it right. Why would you want to put your global install of Python at risk of anything? With Virtualenv you can select which Python interpreter is used for that particular sand-box. Virtualenv and Virtualenvwrapper(or custom solution) are two of the most essential tools a Python Developer can have. You can view your virtualenvs, create, delete, and activate them all with ease. You can get both pieces of software from pip. If you’re not using those I assume you’re not using requirements files either? $ pip freeze > requirements.txt will generate a requirements.txt with all exact versions and dependencies of your project. That way you can do fast deployment. If your current project requires 10 dependencies from pip if you deploy a lot then requirements files will help you tremendously.

You can have a good beginners look at virtualenv and pip here

Answered By: eusid

Open the Cygwin terminal

$cd /usr/bin
$ls -l | grep "python ->"
lrwxrwxrwx    1 XXXX Domain Users       XXXXX  python -> etc/alternatives/python
$ python
   Python 3.8.10 (default, May 20 2021, 11:41:59)
    [GCC 10.2.0] on cygwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>>

Update this link to the required python version
I have installed python 2.7 and python 3.8 in my Cygwin
I wanted to make Python 2.7 the default. This means when is execute “python” on my terminal it should Load Python version 2.7

$cd /usr/bin
$rm -r python
$ln -s /usr/bin/python2.7 python

$ ls -l | grep "python ->"
lrwxrwxrwx    1 XXXX Domain Users       XXXXX python -> /usr/bin/python2.7

$ python
Python 2.7.18 (default, Jan  2 2021, 09:22:32)
[GCC 10.2.0] on cygwin
Type "help", "copyright", "credits" or "license" for more information.
>>>

If you do not have admin rights this could be done by replacing .dll and .exe for specific version of python.

  1. download embeded version of python from its site.
  2. type whereis python to locate files in cygwin
  3. replace it with downloaded version from site.
Answered By: AnkitP
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.