skip to Main Content

When I try to run any .py file on my vscode ; it always show this error!

zsh: command not found: python

% which python
python not found

% which python3
/Library/Frameworks/Python.framework/Versions/3.10/bin/python3

while my terminal from other environment shows

(tensorflow) anshumansinha@lawn-128-61-45-180 deepOscillations_try-master % which python
/opt/homebrew/Caskroom/miniforge/base/envs/tensorflow/bin/python

(tensorflow) anshumansinha@lawn-128-61-45-180 deepOscillations_try-master % which python3
/opt/homebrew/Caskroom/miniforge/base/envs/tensorflow/bin/python3

Have I installed my python multiple times? And it is not showing up on my vscode? How to correct this? Also does the honeybrew version only work for a given environment? Because when I go for a new terminal window and write the following, again it stops working

anshumansinha@lawn-128-61-44-2 ~ % which python
python not found
anshumansinha@lawn-128-61-44-2 ~ % which python3
/Library/Frameworks/Python.framework/Versions/3.10/bin/python3
anshumansinha@lawn-128-61-44-2 ~ % 

Kindly help me understand what am I doing wrong?

3

Answers


  1. To use python in place of python3 you should add this line to ~/.zshrc

    alias python=python3
    

    This way you will use your system Python /Library/Frameworks/Python.framework/Versions/3.10/bin/python3.

    If you want to use the Python from the tensorflow virtual environment you should activate it also inside VSCode

    $ . tensorflow/bin/activate
    
    Login or Signup to reply.
  2. You have to install two things. Python itself, and the Python extension inside VSCode that allows it to make use of Python.

    The VSCode extension must be installed from within VSCode by searching "Python" in the Extension tab on the left side of the screen and installing it.

    Login or Signup to reply.
  3. In mac, python points to the pre-installed python2 by default. But since Monterey 12.3, python2 is no longer pre-installed.

    So you need to create an alias for your machine using the following command to make python point to python3.

    echo "alias python=/usr/bin/python3" >> ~/.zshrc
    

    If you want to keep using the python 2 version on mac, check out this answer.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search