在Python3.6虚拟环境执行get-pip.py安装pip时遇WinError31错误求助
Fixing WinError 31 When Installing Pip in Python 3.6 Virtual Environment
Hey there, let's work through that frustrating WinError 31 you're hitting when trying to install pip in your myvenv_python3 virtual environment. I've dealt with similar Windows-specific glitches before, so here are actionable steps to resolve this:
1. Refresh Your Virtual Environment
Corrupted virtual environments can cause weird device-related errors. Let's start fresh:
- First, exit your current virtual environment:
deactivate - Delete the existing environment (use the command matching your terminal):
- Command Prompt:
rmdir /s myvenv_python3 - PowerShell:
Remove-Item -Recurse -Force myvenv_python3
- Command Prompt:
- Recreate the virtual environment:
python -m venv myvenv_python3 - Activate it again:
myvenv_python3\Scripts\activate - Now re-run your
get-pip.pycommand.
2. Use a Stable PyPI Mirror for Downloads
The error might stem from unstable connections to the official PyPI servers. Switch to a reliable mirror to avoid download interruptions:
python get-pip.py --trusted-host=pypi.org --trusted-host=pypi.python.org --trusted-host=files.pythonhosted.org -i https://pypi.tuna.tsinghua.edu.cn/simple
3. Check File Location and System Permissions
WinError 31 often ties to external storage devices or insufficient permissions:
- If you're running
get-pip.pyfrom an external drive (like a USB stick), move the file to your local C: drive (e.g.,C:\Users\Kaleab\Documents) and try again. - Launch your terminal as Administrator (right-click Command Prompt/PowerShell > "Run as administrator") before executing the install command—this ensures you have full access to system resources.
4. Manually Install Pip via Wheel Package
If the above steps fail, bypass the online download by manually installing the pip wheel:
- Download the pip 10.0.1 wheel file (
pip-10.0.1-py2.py3-none-any.whl) to your local machine. - Navigate to the folder containing the wheel file in your activated virtual environment, then run:
(If you don't have pip at all yet, usepython -m pip install pip-10.0.1-py2.py3-none-any.whlpython -m wheel install pip-10.0.1-py2.py3-none-any.whlinstead—ensure you have thewheelpackage installed first, or include it in yourget-pip.pycommand.)
内容的提问来源于stack exchange,提问作者Kaleab Woldemariam
相关产品推荐
相关产品推荐

