无法在Python中激活虚拟环境

Rea*_*oob 5 python virtualenv python-3.x

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

这是我的软件包版本:

virtualenv==16.7.5
virtualenvwrapper-win==1.2.6
Run Code Online (Sandbox Code Playgroud)
  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.
Run Code Online (Sandbox Code Playgroud)

然后我运行这些命令:

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'?
Run Code Online (Sandbox Code Playgroud)

以下是我运行的用于激活虚拟环境的命令,但它们都不起作用:

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.
Run Code Online (Sandbox Code Playgroud)

这里缺少什么?

谢谢。

小智 9

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

pip install --upgrade virtualenv
Run Code Online (Sandbox Code Playgroud)