Skip to content
Search

Pyenv

lastmod 2026-09-04created 2016-04-2528 edits

Simple Python Version Management: pyenv.

How to install

Simple usage

pyenv versions  ## 설치된 버전 목록
pyenv install --list  ## 설치 가능한 버전 목록
pyenv install 3.9.11  ## 3.9.11 버전 설치
pyenv uninstall 3.9.11  ## 3.9.11 버전 삭제
pyenv virtualenv 3.9.1 py39  ## 3.9.11 버전을 기반으로 py39 라는 가상환경 설치 (`pyenv install 3.9.11` 이 선결되어야 한다)

Commands

Subcommand

Description

local

Check and set the python version for the current directory

global

Globally set python version

shell

Set the Python version for the shell

install

Install a Python version using python-build

uninstall

Remove the specified Python version

version

Print the currently active Python version

versions

Print the versions installed with pyenv and available for use

which

Print the location of the active Python command

whence

Print all Python versions that contain the specified command

Mac OSX

On Mac OSX, you can install it via brew as follows.

$ brew update  
$ brew install pyenv  

If you use the pyenv root directory installed by brew (note: the default directory is ~/.pyenv), you must add the following to your profile.

export PYENV_ROOT=/usr/local/var/pyenv

Add the following to your profile and you're done.

if which pyenv > /dev/null; then eval "$(pyenv init -)"; fi

Of course, if you want to apply the above environment right away, you need to load the profile as follows.

$ source ~/.bash_profile

Check!

If you also want to manage package dependencies with pip, you need to install virtualenv.

How to build CPython with Framework support on OS X

$ env PYTHON_CONFIGURE_OPTS="--enable-framework" pyenv install 3.5.0

How to build CPython with --enable-shared

$ env PYTHON_CONFIGURE_OPTS="--enable-shared" pyenv install 3.5.0

How to use

You can see the list of installable Python versions with the following command.

$ pyenv install --list

INFORMATION

If the latest Python version is missing, go to ~/.pyenv and run git pull.

Then enter a version name found above to install it.

$ pyenv install 2.7.11

To check the Python version currently in use, enter the following.

$ pyenv version
system (set by /Users/your/.pyenv/version)

Note that if it prints system, you are using the Python installed on the system.

To see all currently installed Python versions, enter the following.

$ pyenv versions
* system (set by /Users/your/.pyenv/version)
  2.7.11

Create a Virtual Environment:

$ pyenv virtualenv 3.9.11 answer-python3

Then activate it:

$ pyenv activate answer-python3

To deactivate:

$ pyenv deactivate

Run pip and check the package list. Only pip and setuptools should be there.

$ python3 -m pip list

Update bash profile

See the site for the exact details. Use the content below for reference only.

echo 'eval "$(pyenv init --path)"' >>~/.profile
echo 'eval "$(pyenv init -)"' >> ~/.bashrc

Troubleshooting

no such command shell

If you get an error that the shell command cannot be found1, you need to apply the following command.

$ eval "$(pyenv init -)"

The Python ssl extension was not compiled. Missing the OpenSSL lib?

If you have homebrew openssl and pyenv installed, you may need to tell the compiler where the openssl package is located:

CFLAGS="-I$(brew --prefix openssl)/include" \
LDFLAGS="-L$(brew --prefix openssl)/lib" \
pyenv install -v 3.4.3

pyenv: shell integration not enabled. Run `pyenv init' for instructions

This summarizes how to deal with the following error.

pyenv: shell integration not enabled. Run `pyenv init' for instructions.

1. If the following code is not in ~/.bash_profile, add it.

export PYENV_ROOT="$HOME/.pyenv"
command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"

2. When integrating into a script, you can use which to assign it to a variable and then run the command.

PYENV_EXE=$(which pyenv 2> /dev/null)
eval $("$PYENV_EXE" init -)

When used as above, the timing of exporting the PATH environment variable

PYENV_ROOT="$("$PYENV_EXE" root)"
PATH="$PYENV_ROOT/bin:$PATH"

export PYENV_ROOT
export PATH

From then on, use pyenv instead of "$PYENV_EXE".

eval $(pyenv init -)

Using the eval command can tangle the paths in use and cause the error above.

prompt changing will be removed from future release

See Virtualenv#prompt changing will be removed from future release.

In short, this happens because the pyenv-virtualenv environment has changed. Leave it as is.

Local Download

Pyenv-a8664a2.tar.gz
Latest commit a8664a2
Download: 2016-05-04

See also

Favorite site

References


  1. pyenv: no such command 'shell' ↩

  2. Pyenv_virtualenv_autoenv_-_Python_dev_env.pdf ↩

author Zer0 sitemap