Buscar nos desafios e nas vagas

    Pyenv no Ubuntu

    Gerenciador que permite alternar entre múltiplas versões de Python.

    Requisitos

    • Git instalado.
    • Um usuário com permissão para usar sudo.

    Instalação

    1. Clone o repositório do pyenv

    git clone https://github.com/pyenv/pyenv.git ~/.pyenv

    O comando acima clona o repositório do pyenv em um diretório oculto chamado .pyenv, no diretório home (~) do usuário atual. Todas as outras instruções se baseiam nessa mesma localização (~/.pyenv).

    2. Exporte as variáveis de ambiente

    echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc
    echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc

    Se você usa zsh, substitua bashrc por zshenv.

    3. Adicione pyenv init ao seu shell

    echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n  eval "$(pyenv init -)"\nfi' >> ~/.bashrc
    • Se você usa zsh, substitua bashrc por zshenv.
    • Se você usa fish, substitua eval (pyenv init -) por pyenv init - | source.

    4. Reinicie seu shell

    exec "$SHELL"

    5. Instale as dependências de build

    O pyenv possui uma seção de problemas comuns de build com orientações para cada um dos possíveis erros de dependência. No Ubuntu, é conveniente instalar as seguintes dependências:

    sudo apt-get install -y make build-essential libssl-dev zlib1g-dev libbz2-dev \
    libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev \
    xz-utils tk-dev libffi-dev liblzma-dev python-openssl

    6. Instale uma versão do Python

    Para instalar uma versão do Python:

    pyenv install 3.7.2

    Para verificar as versões já instaladas:

    pyenv versions

    Para definir uma versão como global:

    pyenv global 3.7.2

    Verificação

    pyenv

    A saída deverá ser algo como:

    pyenv 1.2.6
    Usage: pyenv <command> [<args>]
    
    Some useful pyenv commands are:
       commands    List all available pyenv commands
       local       Set or show the local application-specific Python version
       global      Set or show the global Python version
       shell       Set or show the shell-specific Python version
       install     Install a Python version using python-build
       uninstall   Uninstall a specific Python version
       rehash      Rehash pyenv shims (run this after installing executables)
       version     Show the current Python version and its origin
       versions    List all Python versions available to pyenv
       which       Display the full path to an executable
       whence      List all Python versions that contain the given executable
    
    See `pyenv help <command>' for information on a specific command.
    For full documentation, see: https://github.com/pyenv/pyenv#readme

    Referências