无法在 Python 中激活虚拟环境

Unable to activate virtual environment in Python

我在 Windows 10,Python 3.10.2。以下是我 运行 创建虚拟环境的命令:

这是我的软件包版本:

virtualenv==16.7.5
virtualenvwrapper-win==1.2.6
  1. 我安装了虚拟环境
D:\voice-cloning\real-time-voice-cloning>python -m pip install virtualenv
WARNING: Ignoring invalid distribution -ip (d:\python\lib\site-packages)
WARNING: Ignoring invalid distribution - (d:\python\lib\site-packages)
WARNING: Ignoring invalid distribution -ip (d:\python\lib\site-packages)
WARNING: Ignoring invalid distribution - (d:\python\lib\site-packages)
Requirement already satisfied: virtualenv in d:\python\lib\site-packages (16.7.5)
WARNING: Ignoring invalid distribution -ip (d:\python\lib\site-packages)
WARNING: Ignoring invalid distribution - (d:\python\lib\site-packages)
WARNING: Ignoring invalid distribution -ip (d:\python\lib\site-packages)
WARNING: Ignoring invalid distribution - (d:\python\lib\site-packages)
WARNING: Ignoring invalid distribution -ip (d:\python\lib\site-packages)
WARNING: Ignoring invalid distribution - (d:\python\lib\site-packages)
WARNING: Ignoring invalid distribution -ip (d:\python\lib\site-packages)
WARNING: Ignoring invalid distribution - (d:\python\lib\site-packages)
WARNING: You are using pip version 21.2.4; however, version 22.0.4 is available.
You should consider upgrading via the 'D:\python\python.exe -m pip install --upgrade pip' command.

然后我 运行 这些命令:

D:\voice-cloning\real-time-voice-cloning>python -m virtualenv venv310
D:\python\lib\site-packages\virtualenv.py:24: DeprecationWarning: The distutils package is deprecated and slated for removal in Python 3.12. Use setuptools or check PEP 632 for potential alternatives
  import distutils.spawn
D:\python\lib\site-packages\virtualenv.py:25: DeprecationWarning: The distutils.sysconfig module is deprecated, use sysconfig instead
  import distutils.sysconfig
Using base prefix 'D:\python'
New python executable in D:\voice-cloning\real-time-voice-cloning\venv310\Scripts\python.exe
Traceback (most recent call last):
  File "D:\python\lib\runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "D:\python\lib\runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "D:\python\lib\site-packages\virtualenv.py", line 2632, in <module>
    main()
  File "D:\python\lib\site-packages\virtualenv.py", line 860, in main
    create_environment(
  File "D:\python\lib\site-packages\virtualenv.py", line 1156, in create_environment
    install_python(home_dir, lib_dir, inc_dir, bin_dir, site_packages=site_packages, clear=clear, symlink=symlink)
  File "D:\python\lib\site-packages\virtualenv.py", line 1719, in install_python
    fix_local_scheme(home_dir, symlink)
  File "D:\python\lib\site-packages\virtualenv.py", line 1805, in fix_local_scheme
    if sysconfig._get_default_scheme() == "posix_local":
AttributeError: module 'sysconfig' has no attribute '_get_default_scheme'. Did you mean: 'get_default_scheme'?

以下是我 运行 用于激活虚拟环境的命令,其中 none 有效:

D:\voice-cloning\real-time-voice-cloning>venv310/scripts/activate
'venv310' is not recognized as an internal or external command,
operable program or batch file.

D:\voice-cloning\real-time-voice-cloning>python venv310/scripts/activate
python: can't open file 'D:\voice-cloning\real-time-voice-cloning\venv310\scripts\activate': [Errno 2] No such file or directory

D:\voice-cloning\real-time-voice-cloning>venv310/Scripts/activate
'venv310' is not recognized as an internal or external command,
operable program or batch file.

D:\voice-cloning\real-time-voice-cloning>activate
'activate' is not recognized as an internal or external command,
operable program or batch file.

D:\voice-cloning\real-time-voice-cloning>cd venv310

D:\voice-cloning\real-time-voice-cloning\venv310>.\Scripts\activate
'.\Scripts\activate' is not recognized as an internal or external command,
operable program or batch file.

这里缺少什么?

谢谢。

确保在 windows PATH 变量中有一个包含您的 python 安装和脚本子文件夹的条目,例如:C:\Program Files (x86)\Python36- 32\ 和 C:\Program Files (x86)\Python36-32\Scripts
使用 pip install virtualenv 时,请确保您 运行 以管理员身份执行 cmd。否则,安装过程中可能会出现 access denied 错误,导致 virtualenv 无法正常安装。 确保已正确安装 virtualenv。检查 python 脚本子文件夹 - 必须存在名为 virtualenv.exe 的 .exe。如果没有,卸载将pip卸载virtualenv并重新安装。

使用 python 3.10.2 和 virtualenv 16.7.5 给我同样的错误。看起来 virtualenv 16.7.5 对于 3.10.2 来说太旧了。使用此命令升级您的软件包,一切都会成功。

pip install --upgrade virtualenv