You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

Windows下执行python -m venv创建虚拟环境失败的问题咨询

Fixing the python -m venv Failure on Network Drives

Your Scenario Recap

You tried running this command to create a virtual environment:

python -m venv my_venv_name

But hit this error:

Error: Command '['\\ (redacted path) \python.exe', '-Im', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 2.

Context: You're in an offline enterprise environment, have a fresh local-only install of Python 3.6.5 (with pip 9.0.3, and python -m pip works fine), but both your Python install directory and the target venv directory are on a network drive.

Root Cause

The core issue here is that Python's venv module (especially in older versions like 3.6.x) has poor compatibility with UNC paths (the raw format of network drive paths). This incompatibility breaks the ensurepip step that venv runs under the hood, leading to the non-zero exit status error.

The Fix

Here's the straightforward solution that works:

  • Stop using UNC paths for the network drive. Instead, map the network share to a local drive letter (like Z: or X:), then run the venv command using this mapped drive path.

For example: If your Python is installed at \\corp-server\python36, map \\corp-server to Z: first. Then you can run Z:\python36\python.exe -m venv Z:\my_venv_name (or navigate to the mapped drive's directory first and run the command from there) — this will create the virtual environment successfully.

Should You Report This as a Bug?

Since Python 3.6.x is no longer officially maintained (its support ended years ago), reporting a bug for this version won't lead to a fix. However, if you encounter the same issue in a currently supported Python release, it would be valid to submit a bug report to the Python core team. Also, you're right that this error message is very unclear — it's definitely confusing for beginners following basic tutorials, which is a legitimate UX shortcoming.

内容的提问来源于stack exchange,提问作者Michael Grazebrook

火山引擎 最新活动