Skip to content

Instantly share code, notes, and snippets.

@marcellobenigno
Forked from luzfcb/configurar_pyenv.md
Created June 29, 2021 20:53
Show Gist options
  • Save marcellobenigno/44607cd56241f73d55867256b9ee933f to your computer and use it in GitHub Desktop.
Save marcellobenigno/44607cd56241f73d55867256b9ee933f to your computer and use it in GitHub Desktop.
instalar pyenv no ubuntu

baseado no meu outro tutorial https://gist.github.com/luzfcb/1a7f64adf5d12c2d357d0b4319fe9dcd

Use o pyenv https://github.com/pyenv/pyenv para baixar, instalar e gerenciar múltiplas versões do INTERPRETADOR Python na sua maquina.

Primeiro instale as dependências:

Linux (Ubuntu):

Abra um terminal, apertando o atalho CRTL + ALT + T ou digite aperte a tecla do windows e digite terminal, ou clique com o botão direito na tela, e escolha a opção "Abrir Terminal" (somente para Ubuntu 15.10 ou superior, para 14.04 é necessário instalar o pacote nautilus-open-terminal e reiniciar)

Primeiro, atualize a lista de pacotes:

sudo apt-get update

Instale os pacotes básicos

sudo apt-get install -y build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm gettext libncurses5-dev tk-dev tcl-dev blt-dev libgdbm-dev git python-dev python3-dev aria2

depois:

curl -L https://raw.githubusercontent.com/pyenv/pyenv-installer/master/bin/pyenv-installer | bash

logo após, edite o arquivo .bashrc localizado na "Pasta Pessoal" ou Home do seu usuário, com o comando:

gedit ~/.bashrc

adicione esses comandos ao final do arquivo:

export PYTHON_BUILD_ARIA2_OPTS="-x 10 -k 1M"

export PATH="~/.pyenv/bin:$PATH"
eval "$(pyenv init --path)"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"

feito isso, salve o arquivo, feche o gedit e feche TODOS os terminais para poder aplicar a configuração.

Abra novamente um terminal, apertando o atalho CRTL + SHIFT + T .

Você pode ver as versões do interpretador Python que podem ser instalados com o comando:

pyenv install -l

Se a versão do interpretador Python que você quer instalar não aparecer na lista, tente atualizar da base de dados de versões do interpretadores rodando pyenv

pyenv update

Instale o pyenv (vou usar a versão 3.5.1 nos exemplos a seguir, mas você pode usar qualquer uma das versões listadas ao executar pyenv install -l )

pyenv install 3.5.1

logo após, defina o Python 3.5.1 como o python padrão do seu usuário:

pyenv global 3.5.1

ps: Se você instalou múltiplas versões do interpretador python e quer deixa-las disponíveis para uso execute

pyenv global versao_principal segunda_versao terceira_versao

exemplo, vamos supor que você instalou o Python 3.5.1, 3.6.2, 2.7.13 , então o comando seria:

pyenv global 3.5.1 3.6.2 2.7.13

Verifique a versão instalada com:

python -V
@marcellobenigno
Copy link
Author

marcellobenigno commented Jul 7, 2021

# (The below instructions are intended for common
# shell setups. See the README for more guidance
# if they don't apply and/or don't work for you.)

# Add pyenv executable to PATH and
# enable shims by adding the following
# to ~/.profile:

export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init --path)"

# If your ~/.profile sources ~/.bashrc,
# the lines need to be inserted before the part
# that does that. See the README for another option.

# If you have ~/.bash_profile, make sure that it
# also executes the above lines -- e.g. by
# copying them there or by sourcing ~/.profile

# Load pyenv into the shell by adding
# the following to ~/.bashrc:

eval "$(pyenv init -)"

# Make sure to restart your entire logon session
# for changes to profile files to take effect.

# Load pyenv-virtualenv automatically by adding
# the following to ~/.bashrc:

eval "$(pyenv virtualenv-init -)"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment