nichollsg
nichollsg

Reputation: 390

How to use Windows Python install in MSYS2

I am using MSYS2 as my terminal in Visual Studio Code for GCC support and to use a few tools that are easier to build often in a Linux environment. However, I would like to install Python on Windows and use that instead of Python packaged with MSYS2. My current workaround is to define the following alias in my .bashrc:

alias python='$PYTHONPATH/../../python.exe'
alias pip='$PYTHONPATH/../../pip.exe'

I recently tried using venv and that is causing problems as when I type python from the MINGW terminal, it points to my Windows python instead of the venv python. This is not a bug obviously, but I need a way to use Windows python instead of MSYS2 python for packages like numpy, tox, matplotlib, etc. because the MSYS2 packages for those are a headache and currently, tox+pytest in MSYS2 does not work. At this time, my solution above works for everything I've thrown at it in Python.

So, my question is how do I use my Windows Python install instead of the POSIX/Windows MSYS2 Python without the above hack? Is there a way I can define the PATH to include my Windows Python as the first entries in MSYS2 PATH?

Here is what it looks like right now:

$echo $PATH
/mingw64/bin:/usr/local/bin:/usr/bin:/bin:/c/Users/Glen.Nicholls/AppData/Local/Programs/Python/Python37/Scripts:/c/Users/Glen.Nicholls/AppData/Local/Programs/Python/Python37

I would like to know how to make it the following instead, delete python from MSYS2, or find another way to accomplish this.

/c/Users/Glen.Nicholls/AppData/Local/Programs/Python/Python37/Scripts:/c/Users/Glen.Nicholls/AppData/Local/Programs/Python/Python37:/mingw64/bin:/usr/local/bin:/usr/bin:/bin:...

Upvotes: 4

Views: 5105

Answers (1)

nazibalalam
nazibalalam

Reputation: 180

You have to put the path for /c/Users/Glen.Nicholls/AppData/Local/Programs/Python/Python37 and /c/Users/Glen.Nicholls/AppData/Local/Programs/Python/Python37/Scripts before those on the msys2, right? Then I wouldn't try to use the terminal as it's too tricky, so, I will use the control panel to do it more easily. Here are some screenshots how I will do that for you.

(Sorry that I couldn't put the pictures, but the links for them instead, I couldn't put any pictures as I am a new member. Also, sorry I made the instructions too detailed.)

First, open search box with Windows+S key. picture1

Then, choose the environment variables options from the window.picture2

Then, choose the PATH system variable at the bottom section, and choose edit (the upper is the user PATH, and the bottom is the system PATH) picture3

This is how it looked before:-- picture4

Then, choose C:/Users/Glen.Nicholls/AppData/Local/Programs/Python/Python37 and click “Move Up” until done. Likewise, do it same with “C:/Users/Glen.Nicholls/AppData/Local/Programs/Python/Python37/Scripts” until it's on the top.picture5

This is how it looks now:-- picture6

After you are done, restart your terminal and hopefully, it will work. :D

Upvotes: 5

Related Questions