Getting Python Running Properly on Linux Mint

Linux Mint ships with Python 3 already installed. Most people stop there and wonder why their scripts break in production. The default system Python is functional but it is also shared across the OS. Modifying it directly will cause other applications to misbehave. That is not a theoretical risk. I ran into this when a mintupgrade script failed because I had pointed pip at the system interpreter instead of a virtual environment. The fix was straightforward but finding the root cause took a while. The first thing to verify is your current Python version. Open a terminal and type python3 --version. Mint 21.x typically comes with Python 3.10. Mint 22.x moves to Python 3.11. The version matters because some packages have dropped support for older releases. If you need a newer version than what the base repo provides, you have two realistic options: use deadsnakes PPA or stick with pyenv. Dead snakes gives you a clean install alongside the system Python. Pyenv builds from source and takes longer but keeps everything isolated under your home directory. I prefer pyenv for development work. Here is how it actually goes. First install the build dependencies. Run sudo apt update && sudo apt install -y make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev. This alone takes about three minutes on a fresh install. Then install pyenv using the installer script or clone the repository. Add the initialization lines to your ~/.bashrc or ~/.zshrc file. Reload the shell with source ~/.bashrc. Now you can install any Python version you need with pyenv install 3.12.4 and set it globally or per-directory.

Virtual environments are non-negotiable. Every project gets its own. Run python -m venv .venv inside your project folder. Activate it with source .venv/bin/activate. Your prompt will change to show the environment name. When you deactivate with deactivate, you return to the system Python. This is the boundary that prevents dependency collisions. I once spent four hours debugging why a package would not import correctly only to realize the activated venv was stale and pointing at an old Python binary. pyenv makes this easier because each Python version is cleanly isolated. The venv just mirrors what pyenv installed.

Setting Up the Development Environment

After the interpreter and virtual environment are ready, you need tooling. My standard stack is uv for dependency management, ruff for linting and formatting, and pytest for testing. uv is fast and handles virtual environments automatically. Install it with curl -LsSf https://astral.sh/uv/install.sh | sh. Then initialize a project by creating a pyproject.toml file. ruff replaces both flake8 and black in most workflows. Configure it in pyproject.toml with a few lines and run ruff check . to validate. The formatting pass is ruff format .. It is significantly faster than running black separately. For automation tasks, I usually add schedule, subprocess, and requests to the mix. Requests is not part of the standard library and third-party HTTP libraries tend to rot if you do not pin versions. Always use a requirements.txt or pyproject.toml dependencies section and pin at least the major version. I lost a deployment once because a minor release of httpx changed how connection pooling worked and my async scheduler started dropping requests silently. That one cost about two days of my time. Git integration is worth mentioning early. Set up a .gitignore that includes .venv/, __pycache__/, and *.pyc files. I have seen repositories bloat to over 200MB because developers committed virtual environments. Git LFS is unnecessary unless you are storing large binary assets. Keep the repo clean and lightweight.

Get the Full Details

Unleashing the Power of Python Modules: A Comprehensive Guide - DEV ...
Unleashing the Power of Python Modules: A Comprehensive Guide - DEV ...

Common Pitfalls and What Actually Works

One thing beginners consistently miss is the difference between system packages and pip packages. Running sudo pip3 install package_name installs into the system Python and can break Mint's internal tools. The package might conflict with the version that the OS expects. Always install packages inside a virtual environment instead. If you absolutely need a global tool, use pipx rather than sudo pip. pipx install package_name creates an isolated environment for command-line tools without touching the system Python. Another issue is path ordering. After installing pyenv, if your PATH does not include the pyenv shims directory before /usr/bin, the shell will still resolve python3 to the system version. Check your PATH with echo $PATH and verify that ~/.pyenv/shims appears early. I encountered this on a fresh install where the pyenv initialization lines were appended after existing PATH exports in .bashrc. The shell kept picking the system Python and every virtual environment I created defaulted to 3.10 regardless of what pyenv had set as the global version. Reordering the export block fixed it immediately. Auto-starting automation scripts is another area where things go sideways. Systemd services for Python scripts require a proper WorkingDirectory, Environment, and Path to the virtual environment interpreter. Without these, the service may fail silently at boot or fail to locate installed packages. Here is a minimal unit file that actually works. Place it at ~/.config/systemd/user/myautomation.service:

[Unit]
Description=My Python Automation Script

[Service]
ExecStart=/home/youruser/.pyenv/versions/3.12.4/bin/python /home/youruser/projects/myautomation/main.py
WorkingDirectory=/home/youruser/projects/myautomation
Environment=PATH=/home/youruser/.pyenv/versions/3.12.4/envs/myautomation/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin

[Install]
WantedBy=default.target Enable it with systemctl --user enable myautomation.service. Note the --user flag. System-level services require root and introduce additional complications around environment variables and permissions. User-level services are simpler and sufficient for most personal automation. I manage about a dozen of them running on the same machine without issues. Some handle API polling. Others clean up temp files or rotate logs.

What Python on Linux Mint Does Not Do Well

Python is strong for text processing, scripting, API interaction, and background automation. It is not suitable for CPU-intensive numerical workloads without additional tooling. If you are doing heavy matrix operations, you will need NumPy and possibly Cython extensions. Even then, the gain over writing the core loop in C is limited unless you are optimizing the right bottleneck. Profile before optimizing. Python has reasonable profiling built in with cProfile and the statistics module. Use it before reaching for external tools. GUI automation with Python on Linux Mint works but has limitations. The pyautogui library relies on X11 and may not function correctly under Wayland. Mint defaults to X11 but Wayland support is growing. Test your GUI automation scripts under your actual display server before deploying them into production workflows. I learned this the hard way when a script that worked flawlessly on X11 failed silently on a Wayland session because the mouse coordinate mapping was different and the application under test did not receive the expected input events. Memory consumption is another factor. Python processes are heavier than comparable C or Go programs. A long-running automation daemon with a large in-memory data structure can consume several hundred megabytes without doing useful work. If you are processing large CSV files or logs, stream them line by line instead of loading everything into a list. Use generators. for line in open("large_file.csv"): does not load the entire file into memory. This is basic advice but people routinely ignore it until their automation script kills the machine.

How to Install Python on Linux Mint? - Linux Genie
How to Install Python on Linux Mint? - Linux Genie

Final Practical Notes

Keep your Python installations updated. Mint security updates sometimes patch OpenSSL or other system libraries that Python depends on. After a system update, run python3 -c "import sys; print(sys.version)" to confirm the interpreter is still functional. If something is broken after an OS update, rebuild your pyenv Python versions rather than trying to patch the existing installation. The rebuild usually takes fifteen to twenty minutes and is more reliable than fighting with partial updates. Documentation for Python itself is solid. The official docs at docs.python.org are the primary reference. Third-party package documentation quality varies widely. Read the source code when the docs are insufficient. Python source is readable and often more informative than any written guide. I check source code for edge cases in library behavior more often than I read documentation these days.