Msys2: Python 2.7 and Python 3.8 side by side, how to load correct site.py

29 views Asked by At

I have portable msys2 under Windows. It works great.

I have both python 2.7 and python 3.8 installed. If I load python 3.8 it works fine.

$ python
Python 3.8.2 (default, Apr 16 2020, 15:31:48)
[GCC 9.3.0] on msys
Type "help", "copyright", "credits" or "license" for more information.
Reading /home/user/.pythonrc
readline is in /usr/lib/python3.8/lib-dynload/readline.cpython-38-i386-msys.dll
>>>

But I can't load python2

$ python2
  File "/c/Users/user1/Documents/appls_mydocs/PortableApps/MSYS2Portable/App/msys32/mingw64/lib/python3.8/site.py", line 178
    file=sys.stderr)
        ^
SyntaxError: invalid syntax

How can I setup msys2 correctly for both versions? Where is the dir that contains site.py specified?

1

There are 1 answers

0
sancho.s ReinstateMonicaCellio On

Helped by this, I realized I need to use

export PYTHONPATH=/c/Users/user1/Documents/appls_mydocs/PortableApps/MSYS2Portable/App/msys32/mingw64/lib/python2.7:/c/Users/user1/Documents/appls_mydocs/PortableApps/MSYS2Portable/App/msys32/mingw64/lib/python2.7/site-packages

The default was with 3.8. I setup respective aliases (I have a suitable export for MINGW_HOME)

alias python2="export PYTHONPATH=${MINGW_HOME}/lib/python2.7:${MINGW_HOME}/lib/python2.7/site-packages; /usr/bin/python2"
alias python3="export PYTHONPATH=${MINGW_HOME}/lib/python3.8:${MINGW_HOME}/lib/python3.8/site-packages; /usr/bin/python3"