25

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?

Community
  • 1
  • 1
Drachenfels
  • 3,037
  • 2
  • 32
  • 47

3 Answers3

55

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. :)

Community
  • 1
  • 1
Drachenfels
  • 3,037
  • 2
  • 32
  • 47
  • I am having this problem on Windows 7, where there is no ./configure used. – Sabuncu Apr 08 '12 at 19:08
  • On Windows, I fixed the problem w/ a fresh install - see: http://stackoverflow.com/questions/8688709/virtualenv-on-windows-7-returns-assertionerror/10078890#10078890 – Sabuncu Apr 09 '12 at 19:56
  • // , Can you compile `Python` with a relative `--prefix` argument? That is to say, will an relative paths given via `--prefix` remain relative if the compiled `Python` gets moved? – Nathan Basanese Sep 08 '15 at 19:25
  • This worked for me (on Ubuntu), only when I realised that the Path/To/Python cannot be the same as the directory where you unzipped the tar.gz. – James Bradbury Aug 24 '18 at 17:38
  • This presumes that you've done the build and installation yourself, right? As opposed to using something like pip to install virtualenv... – fraxture Oct 08 '18 at 17:39
19

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.

Mike Davlantes
  • 1,038
  • 14
  • 16
2

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.

Community
  • 1
  • 1
nayak
  • 2,807
  • 1
  • 17
  • 19