How to change version of Python picked up by Cygwin

10,677

Solution 1

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.

Solution 2

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.
>>>

Solution 3

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

Share:
10,677
Robert Whitley
Author by

Robert Whitley

Find out all about me by clicking here.

Updated on June 13, 2022

Comments

  • Robert Whitley
    Robert Whitley almost 2 years

    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?