Thursday, October 6, 2022

[SOLVED] Virtualenv failing with "does not start with prefix"

Issue

I have just downloaded python 3.6.1 from github and built it in a local dir. Now I am trying to make a virtualenv with that version of python but I keep getting:

Running virtualenv with interpreter /home/giorgio/tools/cpython-3.6.1/python
Using base prefix '/usr/local'
Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/virtualenv.py", line 2462, in <module>
    main()
  File "/usr/lib/python2.7/site-packages/virtualenv.py", line 762, in main
    symlink=options.symlink,
  File "/usr/lib/python2.7/site-packages/virtualenv.py", line 998, in create_environment
    install_python(home_dir, lib_dir, inc_dir, bin_dir, site_packages=site_packages, clear=clear, symlink=symlink)
  File "/usr/lib/python2.7/site-packages/virtualenv.py", line 1219, in install_python
    copy_required_modules(home_dir, symlink)
  File "/usr/lib/python2.7/site-packages/virtualenv.py", line 1147, in copy_required_modules
    dst_filename = change_prefix(filename, dst_prefix)
  File "/usr/lib/python2.7/site-packages/virtualenv.py", line 1111, in change_prefix
    assert False, "Filename {} does not start with any of these prefixes: {}".format(filename, prefixes)
AssertionError: Filename /home/giorgio/tools/cpython-3.6.1/Lib/os.py does not start with any of these prefixes: ['/usr/local', '/usr/local']

I don't want to install this version of python globally on the system. Is there another way to make virtualenv work with it?


Solution

I think Python 3.6 introduced a new way of creating virtual environments that don't depend on routing through usr/local.

python3 -m venv /path/to/new/virtual/environment

Here is documentation.



Answered By - rLevv
Answer Checked By - Cary Denson (WPSolving Admin)