assert error when installing virtualenv with different python

Each Answer to this Q is separated by one/two green lines.

My server has Python2.5 I wanna be jump to newest Python (2.7.x in my case). I compiled python from source, I downloaded newest virtualenv (1.5.1).

Now basically what im trying to do:

./packages/virtualenv/virtualenv.py --python=packages/Python-2.7/python env/

Typing:

./packages/virtualenv/virtualenv.py

Provides:

1.5.1

While Typing:

packages/Python-2.7/python

Provides:

Python 2.7 (r27:82500, Nov 21 2010, 23:19:15) 
[GCC 4.3.2] on linux2
(cut help mesage)
>>>

However runing virutalenv results in:

AssertionError: Filename /packages/Python-2.7/Lib/os.py does not start with any of these prefixes: [‘/usr/local’]

Whatever it means and whatever I am or I am not doing wrong.

P.S.
While building env + python I based at question: How do I work around this problem creating a virtualenv environment with a custom-build Python?

After reading and messing with this.

I found that this error might be related with lack of --prefix while runing ./configure for python. So I’ve run ./configure --prefix=/Path/To/Where/I/Want/Python/After/Compilation/ (in my case $HOME/packages/Python-2.7), then I’ve typed make, then make install (without using sudo – so python was safely put into where I told it to be as current user not root). After that virtualenv initiation did not crash with AssertionError and everything worked like a charm.

Hope that this question answered by author will eventually help someone. 🙂

I don’t have enough rep to add this as a comment and this question is 3 years old, but this might be useful to someone. In Windows, you have to path out to python.exe, but it seems that in Linux/OS X you just path to the folder. Example:

Windows:

virtualenv -p <PATH TO PYTHON.EXE> venv

Creates a virtual environment in subfolder “venv” in current directory.

I don’t have enough rep to add comment. Mike’s answer save my day. I’m using windows.

I was getting the error :

AssertionError: Filename C:\Python35\Lib\os.py does not start with any of these prefixes: ['c:\\python35', 'c:\\python35']

I had to run this-

virtualenv -p C:\Python35\python.exe venv

also need to run this from a cmd opened as Administrator. Otherwise getting the error

PermissionError: [WinError 5] Access is denied

Someone with enough reps to comment please add this to Mike’s answer as a comment. I’ll then clear mine.


The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .