LoginSignup
0
1

pyenv cheatsheet

Last updated at Posted at 2021-08-08

pyenv cheatsheet

Commands

List versions available on the Internet

% pyenv install --list
Available versions:
  2.1.3
  2.2.3
(...snip...)

Install specific version

% pyenv install 3.9.6
Downloading Python-3.9.6.tar.xz...
-> https://www.python.org/ftp/python/3.9.6/Python-3.9.6.tar.xz
Installing Python-3.9.6...
(...snip...)

Uninstall specific version

% pyenv uninstall 3.10.9
pyenv: remove ${HOME}/.pyenv/versions/3.10.9? [y|N] y
pyenv: 3.10.9 uninstalled

You can also uninstall a version by removing its directory like rm $(pyenv prefix 3.10.9).

List versions installed at local

% pyenv versions
* system (set by /home/foo/.pyenv/version)
  2.7.18
  3.9.6

Create virtualenv with specific version

Syntax:

% pyenv virtualenv [version] <virtualenv-name>

Example:

% pyenv virtualenv 3.9.6 sspa-py3.9
Looking in links: /tmp/tmpgfsv96lg
Requirement already satisfied: setuptools in /home/foo/.pyenv/versions/3.9.6/envs/sspa-py3.9/lib/python3.9/site-packages (56.0.0)
Requirement already satisfied: pip in /home/foo/.pyenv/versions/3.9.6/envs/sspa-py3.9/lib/python3.9/site-packages (21.1.3)
% pyenv versions
* system (set by /home/foo/.pyenv/version)
  2.7.18
  3.9.6
  3.9.6/envs/sspa-py3.9
  sspa-py3.9

Set application specific version with virtualenv

You can specify the virtualenv version created above.

% cd /path/to/your/application
% pyenv local sspa-py3.9
% python -V                       # check the python virsion
Python 3.9.6

Activate/deactivate virtualenv

% pyenv activate <virtualenv-name>
% pyenv deactivate

Delete virtualenv

% pyenv virtualenv-delete <virtualenv-name>

Note: Do not just pyenv uninstall <virtualenv-name>, although it is described in the README of pyenv-virtualenv. That will not delete $(pyenv root)/versions/<version>/envs/<virtualenv-name>. If you have done that, you will need to delete the directory manually.

Upgrade pyenv

% cd `pyenv root`
% git pull

see: https://github.com/pyenv/pyenv#upgrading

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1