Ubuntu 22.04 comes with Python 3.10.12
.
The default Python interpreter is located at /usr/bin/python3
.
To list all installed Python dependencies, use the following command:
apt list --installed | grep python
pyenv
is a utility for managing multiple Python versions, similar to nvm
for Node.js.
An alternative method is to use apt
:
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt-get update
sudo apt-get install python3.5
Install pyenv
This script installs the necessary dependencies and clones the pyenv
repository.
# Prerequisites
sudo apt install libedit-dev
sudo apt uninstall python3-pip
sudo apt-get install build-essential zlib1g-dev libffi-dev libssl-dev libbz2-dev libreadline-dev libsqlite3-dev liblzma-dev
sudo apt-get install python-tk python3-tk tk-dev
curl https://pyenv.run | bash
Add the following lines to the end of your ~/.bashrc
file to initialize pyenv
:
export PYENV_ROOT="$HOME/.pyenv"
[[ -d $PYENV_ROOT/bin ]] && export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"
# Build Location
export TMPDIR="$HOME/.pyenv-tmp"
# Load Virtualenv
# Load pyenv-virtualenv automatically by adding
# the following to ~/.bashrc:
eval "$(pyenv virtualenv-init -)"
pyenv install --list | grep " 3\.[12]"
# Downloads and builds the specified version
pyenv install 3.12.3
# List installed versions
pyenv versions
# Set global Python version
pyenv global 3.12.3
Once you have multiple Python versions running, you may need to set up global dependencies for your projects.
aider is a tool for managing virtual environments.
# Create an environment
pyenv virtualenv 3.12.3 aider
# Display newly created environment
pyenv versions
# Activate the environment
pyenv activate aider
# Deactivate the environment
pyenv deactivate
# Install aider
pip install aider-chat
# Display the number of installed packages
pip freeze | wc -l
By default, auto-commit changes are enabled. To override the default, add the following line to your ~/.bashrc
file:
export AIDER_AUTO_COMMITS=0
To add this automatically from a bash command, you can use the following script:
echo 'export AIDER_AUTO_COMMITS=0' >> ~/.bashrc
source ~/.bashrc
#OLLAMA_API_BASE=http://localhost:11434/
# https://aider.chat/docs/llms.html#azure
# aider --model azure/gpt-4-32k --no-auto-commits
AZURE_API_KEY=
AZURE_API_VERSION=
AZURE_API_BASE=
# https://github.com/paul-gauthier/aider/issues/596
# https://aider.chat/docs/llms.html#ollama
# export OLLAMA_API_BASE=http://127.0.0.1:11434
# aider --model ollama/mistral:latest
# aider --model ollama/codellama:7b --no-auto-commits
Poetry is another tool for dependency management and packaging in Python.
# Create an environment
pyenv virtualenv 3.12.3 poetry
# Display newly created environment
pyenv versions
# Activate the environment
pyenv activate poetry
# Deactivate the environment
pyenv deactivate
# Install Poetry
curl -sSL https://install.python-poetry.org | python -
# Configure Poetry to create virtual environments inside the project directory
poetry config virtualenvs.in-project true
# Create a new Poetry project
poetry new my-project
# Navigate to the project directory
cd my-project
# Add dependencies
poetry add requests
# Activate the virtual environment
poetry shell
# Deactivate the virtual environment
exit
To update all installed Python packages, use the following command:
pip list --outdated | grep -v '^\-e' | cut -d ' ' -f1 | xargs -n1 pip install -U
To uninstall a Python package, use the following command:
pip uninstall <package_name>
To create a virtual environment using venv
, use the following command:
python3 -m venv myenv
To activate the virtual environment:
source myenv/bin/activate
To deactivate the virtual environment:
deactivate
To check the current Python version, use the following command:
python --version
To initialize a new Git repository:
git init
To clone an existing repository:
git clone <repository_url>
To check the status of your repository:
git status
To add changes to the staging area:
git add <file_name>
To commit changes:
git commit -m "Your commit message"
To push changes to a remote repository:
git push origin <branch_name>