Python与Linux新手求助:无法安装Python包及升级pip、setuptools
Hey there! As someone who’s been in your shoes navigating older Linux distros and Python versions, I totally get how frustrating these permission and outdated tool hiccups can be. Let’s work through this step by step with safe, system-friendly fixes:
First Rule: Skip sudo pip — It’s Risky!
Using sudo to install Python packages messes with your system’s core Python dependencies, which can break built-in tools later. We’ll use two safer approaches instead:
Option 1: Quick User-Specific Install
This installs packages directly to your user folder (no system changes, no sudo required):
First upgrade your user-level
pip,setuptools, andwheelto versions that play nice with Python 3.4:pip3 install --user --upgrade pip setuptools wheelIf you get a warning about adding a directory to your
PATH, just follow the prompt to add~/.local/binto your~/.bashrcfile, then restart your terminal—this makes your upgraded tools accessible.Install the maintained
progressbar2package (the originalprogressbaris deprecated and often causes issues with Python 3.4):pip3 install --user progressbar2Now you can import it in your scripts with
import progressbar.
Option 2: Virtual Environment (Cleaner for Projects)
Virtual environments isolate your project dependencies from the system Python, preventing version conflicts down the line:
First install the
python3-venvpackage (Python 3.4 doesn’t include it by default):sudo apt-get update && sudo apt-get install python3-venvCreate a dedicated environment for your progressbar script:
python3 -m venv my_progress_envActivate the environment (you’ll see
(my_progress_env)at the start of your terminal prompt when it’s active):source my_progress_env/bin/activateUpgrade the tools inside the environment (no sudo needed here):
pip install --upgrade pip setuptools wheelInstall
progressbar2:pip install progressbar2When you’re done working, deactivate the environment with:
deactivate
Why This Solves Your Problem
Your original error came from the system’s default pip/setuptools/wheel being too outdated to handle modern package installs for Python 3.4. By using user-specific installs or virtual environments, you can upgrade these tools without touching the system’s critical Python setup—avoiding permission errors and accidental system breakage.
内容的提问来源于stack exchange,提问作者marbri

