简体   繁体   English

Python无法激活虚拟环境

[英]Unable to activate virtual environment in Python

I am on Windows 10, Python 3.10.2.我在 Windows 10、Python 3.10.2。 Here are the commands that I ran to create the virtual environment:以下是我为创建虚拟环境而运行的命令:

Here are my versions for packages:这是我的软件包版本:

virtualenv==16.7.5
virtualenvwrapper-win==1.2.6
  1. I installed the virtual environment.我安装了虚拟环境。
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.

Then I ran these commands:然后我运行了这些命令:

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'?

Here are the commands I ran for activating the virtual environment and none of them worked:以下是我为激活虚拟环境而运行的命令,但没有一个有效:

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.

What is missing here?这里缺少什么?

Thanks.谢谢。

Using python 3.10.2 and virtualenv 16.7.5 gives me the same error.使用 python 3.10.2 和 virtualenv 16.7.5 给我同样的错误。 Looks like virtualenv 16.7.5 is too old for 3.10.2.看起来 virtualenv 16.7.5 对于 3.10.2 来说太旧了。 Upgrade you package with this command and everything will work out.使用此命令升级您的 package,一切都会成功。

pip install --upgrade virtualenv

Make sure that in the windows PATH variable there is an entry with your python installation and the scripts subfolder eg: C:\Program Files (x86)\Python36-32\ and C:\Program Files (x86)\Python36-32\Scripts确保在 windows PATH 变量中有一个包含您的 python 安装和脚本子文件夹的条目,例如:C:\Program Files (x86)\Python36-32\ 和 C:\Program Files (x86)\PythonScript36-
When using pip install virtualenv, make sure that you run cmd as administrator.使用 pip 安装 virtualenv 时,确保以管理员身份运行 cmd。 Otherwise, there might an access denied error during installation and virtualenv will not be installed properly.否则,安装过程中可能会出现 access denied 错误,导致 virtualenv 无法正常安装。 Make sure that virtualenv has been installed correctly.确保已正确安装 virtualenv。 Check in the python scripts subfolder - there must exist an.exe named virtualenv.exe.检查 python 脚本子文件夹 - 必须存在名为 virtualenv.exe 的 .exe。 If not, uninstall will pip uninstall virtualenv and install again.如果没有,卸载将 pip 卸载 virtualenv 并重新安装。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM