0

I'm on MacOS, and I have latest python installed via brew. A few months ago, I started using pyenv to be able to switch between latest python and a project that was fixed at python v3.8. I think I got it all set up but I'm confused. pyenv refuses to show me information about system:

$ pyenv versions
* system (set by /Users/<user>/.pyenv/version)
  3.8.6

$ pyenv version system
system (set by /Users/<user>/.pyenv/version)

$ cat ~/.pyenv/version
system

How do I get pyenv to show me the version and/or location of system?? Obviously, I can get info about system python when it's the one in use, but why doesn't pyenv show anything about it? Showing info about the current config seems like basic functionality for a config management tool.

By comparison, when I run apt list --installed, it shows me what's installed, whether installed by me or bundled with the OS. It doesn't just show a placeholder for things installed by the system.

So I'm frustrated that pyenv is doing this.

Edit: Wow, nvm is the same way. How? Why? Why do these tools have a built-in disregard for the system config?

Mike B
  • 627
  • 3
  • 11
  • 19
  • 1
    `pyenv activate system ; python --version` ? The system version is not managed by pyenv, that's why it's the system version. – Mephy Feb 17 '22 at 17:55
  • @Mephy Oh, so it's like Homebrew? Where the tool is a layer on top of the system, and so inherently there's a piece that the tool doesn't manage and might not even have access to. – Mike B Feb 17 '22 at 20:12

2 Answers2

0

Pyenv is a shim tool. It's used to intercept calls to python and pip and transparently give the correct binaries for these commands. When you call python -m some_module, pyenv will find the correct python binary that makes sense for that call, either because it's locally set by a .python-version file or set by the current shell using pyenv shell or pyenv activate commands.

Pyenv tries to not mess up with current python installations, because the environment system may use these tools, and should keep using whatever version they are already using. Thus, it simply packs the currently existing binaries as "system" and does not touch it, so that the existing system prior to installing pyenv keeps working as it was before.

As a best practice, I recommend you to create a new environment and set it with pyenv global to something different of system (e.g. pyenv install 3.9.10 && pyenv virtualenv 3.9.10 myglobal && pyenv global myglobal) -- so that your default application python is different from the operating system python, and thus you can't mess with the system; just leave system as is. If you want to check what system is, you can activate it and call it normally, pyenv activate system ; python --version will show the version, but it's not something you should be doing in the first place, so pyenv doesn't support it.

Mephy
  • 2,978
  • 3
  • 25
  • 31
  • 1. Pyenv activate does not seem to be a command. $ pyenv --version pyenv 2.3.23 $ pyenv global system also DOES NOT WORK: $ python --version pyenv: python: command not found The `python' command exists in these Python versions: 3.7.11 3.9.10 – Zargold Aug 23 '23 at 16:25
  • @Zargold the activate command surely exists. And `pyenv global system` works as long as pyenv created a system shim from a previously existing system-wide python installation. It looks like you may have a faulty or incomplete pyenv installation. Feel free to open a new question describing your issue in detail. – Mephy Aug 23 '23 at 16:56
  • $ pyenv activate system ..... ..... pyenv: no such command `activate' ... – Zargold Aug 23 '23 at 17:18
  • pyenv help --version Display \ commands List all available \ exec Run \ global Set \ help Display \ hooks List \ init Configure \ install Install \ latest Print \ local Set \ prefix Display \ rehash Rehash \ root Display \ shell Set \ shims List \ uninstall Uninstall \ version Show \ version-file Detect \ version-name Show \ version-origin Explain \ versions List all \ whence List \ which Display – Zargold Aug 23 '23 at 17:45
0

pyenv notifies you that you have a system version when you do: pyenv versions

If you then do: pyenv global system

this does not actually set you to that as it would other versions:

like pyenv global 3.11

the correct way to determine your "system" version is:

/usr/bin/python3 --version
Python 3.9.6

Presumably you're using Python3, and this works for Mac OSX and python installed with brew, it may not work for your system.

Zargold
  • 1,892
  • 18
  • 24