Pyenv Operatons: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
 
(15 intermediate revisions by the same user not shown)
Line 6: Line 6:
brew install pyenv
brew install pyenv
</syntaxhighlight>
</syntaxhighlight>
You need to [[#Setup_Shell|setup your shell]] after installation.
=Setup Shell=
=Setup Shell=
{{External|https://github.com/pyenv/pyenv#set-up-your-shell-environment-for-pyenv}}
{{External|https://github.com/pyenv/pyenv#set-up-your-shell-environment-for-pyenv}}
Line 17: Line 19:
export PYENV_ROOT="${HOME}/.pyenv"
export PYENV_ROOT="${HOME}/.pyenv"
eval "$(pyenv init -)"
eval "$(pyenv init -)"
</syntaxhighlight>
=Commands=
==<tt>versions</tt>==
List <code>pyenv</code>-managed versions:
<syntaxhighlight lang='bash'>
pyenv versions
</syntaxhighlight>
<syntaxhighlight lang='bash'>
* system (set by /Users/ovidiu/.pyenv/version)
  3.9.9
</syntaxhighlight>
==<tt>install</tt>==
Installs a new Python version:
<syntaxhighlight lang='bash'>
pyenv install 3.9.9
</syntaxhighlight>
To understand what happens, see: {{Internal|Pyenv_Concepts#What_Happens_if_pyenv_Installs_a_new_Python_Version|pyenv Concepts &#124; What Happens if pyenv Installs a new Python Version}}
===List of Available Python Versions===
<syntaxhighlight lang='bash'>
pyenv install -l
</syntaxhighlight>
==<tt>shell</tt>==
{{External|https://github.com/pyenv/pyenv/blob/master/COMMANDS.md#pyenv-shell}}
Selects a <code>pyenv</code>-installed Python version for the current shell session:
<syntaxhighlight lang='bash'>
pyenv shell 3.9.9
</syntaxhighlight>
==<tt>local</tt>==
{{External|https://github.com/pyenv/pyenv/blob/master/COMMANDS.md#pyenv-local}}
<syntaxhighlight lang='bash'>
pyenv local 3.9.9
</syntaxhighlight>
It sets a directory-specific Python version by writing the <code>.python-version</code> file in the directory:
<font size=-2>
3.9.9
</font>
==<tt>global</tt>==
{{External|https://github.com/pyenv/pyenv/blob/master/COMMANDS.md#pyenv-global}}
==<tt>root</tt>==
Lists the content of <code>PYENV_ROOT</code> environment variable:
<syntaxhighlight lang='bash'>
pyenv root
</syntaxhighlight>
=Troubleshooting=
==<tt>pyenv: version '...' is not installed</tt>==
<syntaxhighlight lang='bash'>
pyenv install 3.12.2
</syntaxhighlight>
</syntaxhighlight>

Latest revision as of 22:46, 5 April 2024

Internal

Installation

brew install pyenv

You need to setup your shell after installation.

Setup Shell

https://github.com/pyenv/pyenv#set-up-your-shell-environment-for-pyenv

Bash

Add this to .bashrc:

# pyenv setup
export PYENV_ROOT="${HOME}/.pyenv"
eval "$(pyenv init -)"

Commands

versions

List pyenv-managed versions:

pyenv versions
* system (set by /Users/ovidiu/.pyenv/version)
  3.9.9

install

Installs a new Python version:

pyenv install 3.9.9

To understand what happens, see:

pyenv Concepts | What Happens if pyenv Installs a new Python Version

List of Available Python Versions

pyenv install -l

shell

https://github.com/pyenv/pyenv/blob/master/COMMANDS.md#pyenv-shell

Selects a pyenv-installed Python version for the current shell session:

pyenv shell 3.9.9

local

https://github.com/pyenv/pyenv/blob/master/COMMANDS.md#pyenv-local
pyenv local 3.9.9

It sets a directory-specific Python version by writing the .python-version file in the directory:

3.9.9

global

https://github.com/pyenv/pyenv/blob/master/COMMANDS.md#pyenv-global

root

Lists the content of PYENV_ROOT environment variable:

pyenv root

Troubleshooting

pyenv: version '...' is not installed

pyenv install 3.12.2