为Python3.6安装pip时提示setuptools未找到,求助解决方法
Hey there, I’ve run into this exact head-scratcher before—let’s break down what’s going on and fix it.
The Root Cause
That pkg_resources.DistributionNotFound error doesn’t just check if the setuptools folder exists. It relies on metadata directories (like .dist-info or .egg-info) that tell Python’s package manager a package is properly installed. Looking at your directory listing, you have the setuptools code folder, but no corresponding metadata directory—this is why pkg_resources can’t recognize it as a valid installed distribution.
How to Fix It
The most reliable way to resolve this is a clean reinstall of setuptools and pip (manually adding metadata is messy and error-prone). Here’s what to do:
Grab the legacy bootstrap script for Python 3.6:
Since Python 3.6 is an older version, you need a tailored bootstrap script to avoid compatibility issues:curl https://bootstrap.pypa.io/setuptools/3.6/get-pip.py -o get-pip.pyRun the script with Python 3.6:
Execute it to install both setuptools and pip properly—this will automatically create the missing metadata directories:python3 get-pip.py
Why Your Current Approach Failed
Copying the setuptools folder into site-packages only adds the code files, not the metadata that pkg_resources uses to track installed packages. The official installation process generates these metadata directories automatically, which is why a clean reinstall fixes the issue.
For reference, here’s your original directory output confirming the missing metadata:
[me@my_server site-packages]$ ll total 8.0K drwxr-xr-x. 5 root 83 May 9 21:11 . drwxr-xr-x. 3 root 26 May 9 21:01 .. -rw-r--r--. 1 root 126 May 9 21:06 easy_install.py drwxr-xr-x. 4 root 56 May 9 21:11 pkg_resources drwxr-xr-x. 2 root 6 Jan 4 16:42 __pycache__ drwxr-xr-x. 4 root 4.0K May 9 21:10 setuptools # Notice no setuptools-*.dist-info folder here!
内容的提问来源于stack exchange,提问作者JacobIRR

