You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用不同Python版本创建虚拟环境时遇到问题

Fixing Python 3 Virtual Environment Issues with virtualenvwrapper and venv

Hey there, let's break down your problems and fix them step by step:

1. virtualenvwrapper Creating Python 2.7 Envs Instead of 3.7

The root issue here is that your system is defaulting to the Python 2.7 version of virtualenvwrapper when you run mkvirtualenv, even though you installed the package for Python 3.7 too. Here's how to fix it:

Force Specify the Python 3.7 Interpreter

Instead of relying on the default mkvirtualenv command, explicitly tell it to use your Python 3.7 executable when creating the environment:

mkvirtualenv --python=C:\Users\user1\AppData\Local\Programs\Python\Python37\python3.exe envTest

This bypasses any path confusion and ensures the virtual environment is built with Python 3.7 from the start.

Adjust Your System PATH

Check your Windows PATH environment variable and make sure the Python 3.7 Scripts directory (e.g., C:\Users\user1\AppData\Local\Programs\Python\Python37\Scripts) appears before the Python 2.7 Scripts directory (C:\Python27\Scripts). This way, when you run mkvirtualenv, the system picks the Python 3.7 version first.

Bypass virtualenvwrapper Altogether (Temporary Fix)

If you want to avoid wrapper-related confusion, use Python 3.7's own virtualenv directly:

python3 -m virtualenv --python=C:\Users\user1\AppData\Local\Programs\Python\Python37\python3.exe envTest
# Activate the environment
.\envTest\Scripts\activate

Once activated, running python --version should show 3.7.4.

Note: Renaming the python.exe in your env to python0.exe didn't change the version because the environment was already created with Python 2.7—renaming just changes the executable's name, not its underlying version.

2. Fixing the venv WinError 2 Issue

Your venv command has incorrect syntax—you're passing two directory arguments (./venv_Test and venvEnv) when venv only expects one target directory. Here's the correct command:

python3 -m venv ./venv_Test

This will generate the full virtual environment structure, including the python.exe file in the Scripts folder.

If you still get the WinError 2 after fixing the syntax:

  • Verify that your Python 3.7 installation is complete. Try repairing the installation via the Python installer (use the "Modify" option) to ensure all venv-related files are present.
  • Make sure the Python 3.7 executable path is correctly added to your PATH, or use the full path to python3.exe in the command:
    C:\Users\user1\AppData\Local\Programs\Python\Python37\python3.exe -m venv ./venv_Test
    

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.06 12:28:13