Home > OS >  MacOS python command not finding active Conda environment from VS Code terminal
MacOS python command not finding active Conda environment from VS Code terminal

Time:03-08

I recently got a new M1 MacBook - first time ever using a Mac - and immediately downloaded Miniconda to get it set up for some Python work.

I created some virtual environments (e.g. conda create -n myenv python=3.8) but when active, the python command defaults to Mac's Python 2.7, preventing me from running scripts from the command line in VS Code. For example:

conda activate myenv
(myenv)% which python
 /usr/bin/python

where shows me the default 2.7 installation and the correct virtual environment version, but I can't access it.

(myenv)% where python
/usr/bin/python
/Users/user/miniconda3/envs/myenv/bin/python

Any idea how to get VS Code to find the proper Python version? It seems to work from the built in terminal, just not VS Code.

OS: Monterey 12.2.1

VS Code: 1.65.0

Miniconda: 4.10.1

CodePudding user response:

Could you try to take advantage of python3 instead of python in the MacOS?

Or you can try to rename the python.exe to something others, such as python2.7 under the /usr/bin/python?

CodePudding user response:

So the problem is, that in windows, you can change the path, but in mac there is this thing, that if you don't select the version, for example:

sudo python test.py

It will run Python 2.7, because it is installed, and it runs the lowest installed version. So try using

sudo python3 test.py

or specify the version in the terminal

sudo python3.8 test.py
  • Related