setting up Python dev environment on Ubuntu - pyenv, pipx, poetry code example

Example: setting up Python dev environment on Ubuntu - pyenv, pipx, poetry

# 1. install pyenv: https://github.com/pyenv/pyenv-installer
	# install Prerequisites: https://github.com/pyenv/pyenv/wiki/Common-build-problems
    sudo apt install libedit-dev  libncurses5-dev
    # install pyenv
    curl https://pyenv.run | bash
    # configure for bash/Zsh
	echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.profile
	echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.profile
	echo 'eval "$(pyenv init --path)"' >> ~/.profile
    # for Bash:
    echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n  eval "$(pyenv init -)"\nfi' >> ~/.bashrc
	# for Zsh
    echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n  eval "$(pyenv init -)"\nfi' >> ~/.zshrc
	# restart the shell for changes to take effect
    # before you can install python, you need to install python dependancies:
    # https://github.com/pyenv/pyenv/wiki#suggested-build-environment
    sudo apt-get update; sudo apt-get install make build-essential libssl-dev zlib1g-dev \
libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm \
libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev
    # install some python versions
    pyenv install 3.8.10
    # set the default python version
    pyenv global 3.8.10
    
# 2. install pipx
python -m pip install pipx
# logout then login to make installation take effect
# 3. install poetry
pipx install poetry

# 4. for deployment
https://jacobian.org/2019/nov/11/python-environment-2020/

Tags:

Misc Example