-1

I'm using an Intel MacBook Pro and have problems with python and pyenv.

Can anybody explain how this can happen and how I can correct it?

[~] pyenv versions
  system
* 3.10.1 (set by /Users/....../.pyenv/version)
[~] python -V
Python 2.7.16
[~] pyenv --version
pyenv 2.2.3
[~]

In my .zshrc file I have

# set correct python version using pyenv

if command -v pyenv 1>/dev/null 2>&1; then
  eval "$(pyenv init -)"
fi

In my opinion python -V should return 3.10.1 and not 2.7.16 which seems to be the system version.

I installed pyenv using brew and run MacOS BigSur 11.6.2.

Gino Mempin
  • 25,369
  • 29
  • 96
  • 135
ThommyB
  • 1,456
  • 16
  • 34
  • 1
    Python 2 is installed on all macs. Try using the command `python3` – It_is_Chris Jan 26 '22 at 21:12
  • 1
    You can always make a symlink by `cd ~/bin` / `ln -s /usr/bin/python3 python`. – Tim Roberts Jan 26 '22 at 21:22
  • Needed to use /usr/local/bin because of [SIP](https://stackoverflow.com/questions/32659348/operation-not-permitted-when-on-root-el-capitan-rootless-disabled/38435256#38435256) when I did it on my Mac but Tim's suggestion is great. – Richard K Yu Jan 26 '22 at 21:44
  • @It_is_Chris I can't since I use it for [Ansible](https://www.ansible.com/). It calls `python` and expects that the correct version is there. That is why I use `pyenv`. I can define one default version using `pyenv global ` or `pyenv local ` for the current shell. – ThommyB Jan 27 '22 at 06:49

1 Answers1

0

I was able to follow Tim Roberts' suggestion to create a symlink in order to solve this problem on my own Mac. I am writing this answer to help clear up any ambiguity you might have.

The commands I used were:

cd /usr/local/bin
ln -s /usr/local/bin/python3 python
python -V

Which gives me:

[16:57:25] Richards-MBP:bin richardkyu$ python -V
Python 3.8.12

Typing in python to the command line opens up the 3.8.12 interpreter. Also, my python3 is installed by brew I believe.

Following up on the comment, I should clarify that I created a new symlink for python rather than rewriting the one for python3. When I execute

ls -l grep python3

in the /usr/local/bin directory, I get the following output, which I assume is similar to yours:

enter image description here

I am not sure of the exact issue with these symlinks you're seeing, but if you can clarify what you're worried about I would be glad to check it out.

Richard K Yu
  • 2,152
  • 3
  • 8
  • 21
  • Don't know if this is a good idea, it is already linked to /Cellar which is where `Homebrew` installs its software: ``` [bin] ll | grep python (output is shortened) [bin] ll | grep python python3 -> ../Cellar/python@3.9/3.9.10/bin/python3 python3-config -> ../Cellar/python@3.9/3.9.10/bin/python3-config python3.9 -> ../Cellar/python@3.9/3.9.10/bin/python3.9 python3.9-config -> ../Cellar/python@3.9/3.9.10/bin/python3.9-config ``` – ThommyB Jan 27 '22 at 06:59
  • @ThommyB My python3 folder was also linked to the one in Cellar I believe. This created a new symlink from python to the python3 folder, or did you mean your python was already pointing to the one in Cellar? It’s a bit hard to read your output in the comment – Richard K Yu Jan 27 '22 at 12:34