Virtualenv failing with "does not start with prefix"
Asked Answered
K

4

5

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?

Kwan answered 14/12, 2018 at 1:7 Comment(2)
Did you actually install it, or just run ./configure and make in your tools directory?Topmost
@Topmost I didn't want to actually install it system-wide, so i just run the ./configure and makeKwan
H
16

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.

Hagi answered 14/12, 2018 at 2:28 Comment(1)
Thank you, this is exactly what I was looking forKwan
E
5

I ran into this error attempting to use my brew-installed version of Python 3.9.5 to create a new virtual environment on macOS. (mkvirtualenv with virtualenvwrapper)

My command format is typically:

mkvirtualenv -p python3 [env-name]

Not sure what caused this to get messed up, but ultimately I got it working again by running:

python3.9 -m venv ~/.virtualenvs/myenvname

This puts the env in your normal spot, and you can still run workon myenvname

Evanevander answered 1/6, 2021 at 6:21 Comment(0)
H
2

The right way to achieve this is to set the prefix when you configure the build options to be a local directory and then perform make install. So if the directory you want to install things at is $HOME/pythons then in the build directory run:

./configure --prefix="${HOME}/pythons"
make
make install
Hanford answered 29/4, 2019 at 17:22 Comment(0)
O
0

I had a similar problem when trying to create an environment after having upgraded to Python 3.9. In my case, I still had the Python3.6 virtualenv packages installed from the OS repo, which created this conflict. The solution was to also upgrade the virtualenv infrastructure to its Python 3.9 equivalent:

sudo apt -y remove virtualenv python3-virtualenv virtualenvwrapper
pip install virtualenv virtualenvwrapper
Oakland answered 11/6, 2024 at 14:21 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.