Home > Back-end >  Not able to run a python code in my visual studio code
Not able to run a python code in my visual studio code

Time:08-29

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?

CodePudding user response:

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

CodePudding user response:

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.

  • Related