1

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 3

2

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
Sign up to request clarification or add additional context in comments.

7 Comments

What's ~/.zshrc ? and how to add this line to that? additionaly the 2nd line does not work! no such file or directory: tensorflow/bin/activate
~/.zshrc it's a file. It's located on directory ` ~` and it's an hidden file, since its name starts with a dot. You can add the line by open the file and just type that line at the end. I personally use Vim $ vim ~/.zshrc but you can use your favorite text editor (I think you can also open it with $ open ~/.zshrc).
I added the lines in my ~/.zshrc file but it is still showing anshumansinha@lawn-128-61-44-2 ~ % which python python not found
I recommend you to uninstall all packages you have already installed with pip on your system Python (stackoverflow.com/questions/11248073/…) and install any new packages in the future within a virtual environment dedicated to a specific project
VSCode it's just an IDE, it has no Python nor packages installed. It all dependes on which Python you areusing and which packages are installed on that Python. You should follow this tutorial (stackoverflow.com/questions/11248073/…) and remove everything you have installed in your basic (system) Python. Then you should learn how to work on virtual environments (realpython.com/python-virtual-environments-a-primer) and install there what you need to use, for example tensorflow
|
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.

1 Comment

I have done both, but still the above happens!
2

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.

1 Comment

I wish to use my python and tensorflow which I installed from homebrew! ` environment location: /opt/homebrew/Caskroom/miniforge/base` and it shows up on one of my terminals as : (tensorflow) anshumansinha@lawn-128-61-45-180 deepOscillations_try-master % which python3 /opt/homebrew/Caskroom/miniforge/base/envs/tensorflow/bin/python3 ; but other terminal don't show like this! The keyword (tensorflow) is missing in the initial statement! before anshumansinha@lawn. I am getting confused in all this!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.