The answers by @Powers and by @Boby actually helped steer me in the right direction, albeit in a roundabout way.
In my case, I tried everything, including: upgrading/installing pyenv with brew using brew upgrade pyenv
, adding config for pyenv to my ~/.zshrc
file, then removing it from there and adding it to ~/.zprofile
, and basically everything in between.
The problem was that when I activated a particular Python version that I had installed, such as:
pyenv global 3.6.15
It didn't actually work. When I typed python
in a terminal, it still showed my system Python version, which was different (3.11)
Long story short, I eventually happened upon the fix rather unintentionally, when I was in the midst of updating my ~/.zprofile
based on another answer, and then opening up a new terminal window to test out whether that fixed or resolved the issue.
I noticed a peculiar strangeness, in that under my user home ~
directory, the Python version was 3.6 correctly (as set in pyenv) but when I cd
-ed into the folder I was having trouble with, it gave me a different python version when I ran python
.
So, thus confused and rendered rather speechless, I ran the following command on my terminal from within this folder:
$ ls -la
And lo and behold, what I did I get other than:
drwxr-xr-x 37 usr staff 1184 Mar 23 17:14 .
drwxr-x---+ 94 usr staff 3008 Mar 30 16:01 ..
-rw-r--r--@ 1 usr staff 16388 Mar 13 11:17 .DS_Store
-rw-r--r-- 1 usr staff 7 Feb 10 18:10 .python-version
-rw-r--r--@ 1 usr staff 170 Feb 9 ? Other stuff
Aha! The culprit (in my case) was the .python-version
file.
I cat
ed it, and found the contents of the file was just plainly:
system
Cleaning up by deleting the file, by running:
rm .python-version
Resolved the issue in my case.
FYI, it looks like this is a trickle-down effect, so that if I had a .python-version
file under:
~/git-repos
Then the same settings (overriding Python version for pyenv
) applies to any children sub-folders, such as:
~/git-repos/my-repo
Solution, was to entirely remove any .python-version
files, all the way up to (and potentially including) the user home or ~
directory on my Mac OS.
Hope this helps someone else, who ends up in the same boat or situation as me.