Reputation: 33
When I type the line python3 --version
into my mac terminal, it comes up as 3.7.6
. If I type the same line in VSCode's terminal, I get 3.7.7
. I wouldn't have thought it much an, except I can't import tensorflow on the 3.7.6
version which seems to also be causing issues with Jupyter since Anaconda runs it off Mac's terminal.
brew install python
registers 3.7.7
as installed on the terminal, but even after re-installing and forcing the terminal closed and re-opened it still registers 3.7.6
. Any insight into the problem would be helpful!
Upvotes: 2
Views: 2082
Reputation: 15861
As it was already written the problem is that you have two versions of python installed. And the version that is listed first in the PATH
environment variable is used. In your default shell (probably bash
) one path to python is used, in the terminal run from VSCode another PATH
is used. You can check this by running echo $PATH
command in both places and checking for difference.
The solution is to be careful with versions of python installed on your system and sometimes this is not easy.
I would suggest to use pyenv for python version management. After the installation you will be able to easily switch between versions. Also it allows to easily install new versions and the most important that it does not conflict with system python installed on MacOS or with python installed with brew.
In your specific case with pyenv you can choose which version should be used globally for all applications (including bash sessions run in Terminal).
Upvotes: 2
Reputation: 11
You have to know that Python in Mac environment has many bugs and often you will run into libraries issues or even problems with Python itself. This said I suggest you to download the newest version of Python you can find on the official site https://www.python.org/downloads/mac-osx/, uninstall everything you can find about old Python versions on your Mac, then install only the last one you get to find.
Anyway personally I always run into issues with VSCode and Python because of imports! I suggest using PyCharm community version (if it is not a problem for you, but consider that it is 100% free and cross-platrform!). Personally I use tensorflow online on google colab platform, at least give it a try!
Upvotes: -1
Reputation: 23
It's because you have 2 versions installed. One from IDE(VSCode-3.7.7) and one from your own install(from the terminal-3.7.6).
Just uninstall the 3.7.6 version, download and install a version that is compatible with tensorflow.
Or you can create a new virtual environments for python with conda.
Upvotes: 0