Home > Back-end >  Unable to activate virtual environment in Python
Unable to activate virtual environment in Python

Time:03-19

I am on 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.

CodePudding user response:

Using python 3.10.2 and virtualenv 16.7.5 gives me the same error. Looks like virtualenv 16.7.5 is too old for 3.10.2. Upgrade you package with this command and everything will work out.

pip install --upgrade virtualenv

CodePudding user response:

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
When using pip install virtualenv, make sure that you run cmd as administrator. Otherwise, there might an access denied error during installation and virtualenv will not be installed properly. Make sure that virtualenv has been installed correctly. Check in the python scripts subfolder - there must exist an .exe named virtualenv.exe. If not, uninstall will pip uninstall virtualenv and install again.

  • Related