Python 3.6使用pip安装包时出现ImportError: cannot import name 'main'错误
Hey there, let's get that pip issue sorted out so you can install httpie. This error usually pops up because of a mismatch between pip's internal structure and the way the pip executable tries to import the main function. Here are a few reliable fixes:
Method 1: Use Python's module runner (simplest fix)
Instead of calling pip.exe directly, run pip as a Python module. Open your command prompt and execute this command:
python -m pip install --user httpie
This bypasses the problematic pip executable script and uses Python's built-in module system to launch pip correctly.
Method 2: Update the pip import in the executable script
If you prefer to keep using pip directly, you can tweak the import statement in the pip main script:
- Navigate to
C:\Python36\Scripts\pip.exe\(you might need to access this via File Explorer, as Command Prompt might not display it directly) - Open the
__main__.pyfile with a text editor like Notepad or VS Code - Change the line
from pip import mainto:from pip._internal import main - Save the file and try running your original
pip install --user httpiecommand again.
Method 3: Reinstall/upgrade pip
If the above methods don't work, you can repair pip by reinstalling it to fix any corrupted or outdated files:
Run this command in Command Prompt:
python -m ensurepip --upgrade
This will make sure you have the latest compatible version of pip for Python 3.6, resolving the underlying import issue.
内容的提问来源于stack exchange,提问作者Jacob Fuchs

