最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Python Version Management with Pyenv on MacBook Pro - Stack Overflow

programmeradmin1浏览0评论

I'm using pyenv to manage Python versions on my MacBook Pro. I have a question about how pyenv handles shim paths for each version.

I've installed different Python versions using pyenv.

 pyenv versions
  system
  3.10.16
  3.11.9
  3.11.9/envs/extra
  3.11.11
* 3.12.4 (set by /Users/xxxxx/.pyenv/version)
  3.12.4/envs/cost
  3.12.4/envs/myproject
  cost --> /Users/xxxxx/.pyenv/versions/3.12.4/envs/cost
  myproject --> /Users/xxxxx/.pyenv/versions/3.12.4/envs/myproject
  extra --> /Users/xxxxx/.pyenv/versions/3.11.9/envs/extra

However, when I try to run them using shims, only the default version works. The other versions show an error saying they're not specified.

shim path for python3.10

MySampleProject/src/MySampleProjectCDK (mainline)  % /Users/xxxxx/.pyenv/shims/python3.10 --version
pyenv: python3.10: command not found

The `python3.10' command exists in these Python versions:
  3.10.16

Note: See 'pyenv help global' for tips on allowing both
      python2 and python3 to be found.

shim path for python3.11

MySampleProject/src/MySampleProjectCDK (mainline)  % /Users/xxxxx/.pyenv/shims/python3.11 --version
pyenv: python3.11: command not found

The `python3.11' command exists in these Python versions:
  3.11.9
  3.11.9/envs/extra
  3.11.11
  extra

Note: See 'pyenv help global' for tips on allowing both
      python2 and python3 to be found.

shim path for python3.12

MySampleProject/src/MySampleProjectCDK (mainline)  % /Users/xxxxx/.pyenv/shims/python3.12 --version
Python 3.12.4

This is causing problems for a project I'm working on. I'm trying to build and test the project using Hatch for both Python 3.11 and 3.12.

I want to know how to make Python 3.10 and 3.11 behave like Python 3.12 when I'm using the shim path

I'm using pyenv to manage Python versions on my MacBook Pro. I have a question about how pyenv handles shim paths for each version.

I've installed different Python versions using pyenv.

 pyenv versions
  system
  3.10.16
  3.11.9
  3.11.9/envs/extra
  3.11.11
* 3.12.4 (set by /Users/xxxxx/.pyenv/version)
  3.12.4/envs/cost
  3.12.4/envs/myproject
  cost --> /Users/xxxxx/.pyenv/versions/3.12.4/envs/cost
  myproject --> /Users/xxxxx/.pyenv/versions/3.12.4/envs/myproject
  extra --> /Users/xxxxx/.pyenv/versions/3.11.9/envs/extra

However, when I try to run them using shims, only the default version works. The other versions show an error saying they're not specified.

shim path for python3.10

MySampleProject/src/MySampleProjectCDK (mainline)  % /Users/xxxxx/.pyenv/shims/python3.10 --version
pyenv: python3.10: command not found

The `python3.10' command exists in these Python versions:
  3.10.16

Note: See 'pyenv help global' for tips on allowing both
      python2 and python3 to be found.

shim path for python3.11

MySampleProject/src/MySampleProjectCDK (mainline)  % /Users/xxxxx/.pyenv/shims/python3.11 --version
pyenv: python3.11: command not found

The `python3.11' command exists in these Python versions:
  3.11.9
  3.11.9/envs/extra
  3.11.11
  extra

Note: See 'pyenv help global' for tips on allowing both
      python2 and python3 to be found.

shim path for python3.12

MySampleProject/src/MySampleProjectCDK (mainline)  % /Users/xxxxx/.pyenv/shims/python3.12 --version
Python 3.12.4

This is causing problems for a project I'm working on. I'm trying to build and test the project using Hatch for both Python 3.11 and 3.12.

I want to know how to make Python 3.10 and 3.11 behave like Python 3.12 when I'm using the shim path

Share asked Mar 3 at 20:06 Am1rr3zAAm1rr3zA 7,44118 gold badges87 silver badges134 bronze badges 2
  • if in /Users/xxxxx/.pyenv/shims there is python3.10.16 instead of python3.10 then I would simply copy it to new name cp python3.10.16 python3.10 or (on Linux) I would create "soft link" ln -s python3.10.16 python3.10. I use soft links also with folder to other tools - ie. if I have two versions of PyCharm then I can keep them in folders PyCharm-old-version, PyCharm-new-version and I can use ln -s ... to create folder PyCharm which links to folder PyCharm-old-1 and other day I can change link to PyCharm-new-version - this way I don't have to change all my scripts – furas Commented Mar 5 at 3:26
  • somethins I use ln also to create link /usr/bin/python3.12 but I don't change /usr/bin/python3 because system uses Python3 to run some elements. – furas Commented Mar 5 at 3:43
Add a comment  | 

1 Answer 1

Reset to default 0

The solution that worked for me was to use: https://github/pyenv/pyenv/blob/master/COMMANDS.md#pyenv-local-advanced

I tried to run the below on my shell:

pyenv local 3.11.11 3.12.4

Now when I build with python hatch it can find both version of python locally


I attempted various approaches and one other way of doing this is to use mise]1

Since it appears that mise is an alternative method for managing Python, and its approach to handling shim paths and the default PATH differs, I attempted to synchronize my pyenv version with mise to add them to the PATH.

https://mise.jdx.dev/cli/sync/python.html

mise sync python --pyenv

mise use [email protected] [email protected]

发布评论

评论列表(0)

  1. 暂无评论