I compiled my own Python 3, then installed virtualenvwrapper. But after I switched from compiling my own Python to using the deadsnakes
PPA I ran into the issue described in the question above.
Seems there's something going on with the #!
part of the virtualenv script.
The error I was getting was as follows:
nb@ubuntu-0xA520322HC30H:~/proj/redis-py$ mkvirtualenv --python='/usr/bin/python3' redispytest
bash: /home/nb/.local/bin/virtualenv: /usr/local/bin/python3.6: bad interpreter: No such file or directory
My system Python setup had the following symlinks and Python locations:
nb@ubuntu-0xA520322HC30H:~/proj/redis-py$ ls -la /usr/bin/python3
lrwxrwxrwx 1 root root 9 Feb 8 11:43 /usr/bin/python3 -> python3.5
nb@ubuntu-0xA520322HC30H:~/proj/redis-py$ ls -la /usr/bin/python3.5
-rwxr-xr-x 2 root root 4464400 Nov 28 08:53 /usr/bin/python3.5
nb@ubuntu-0xA520322HC30H:~/proj/redis-py$ which python3.5
/usr/bin/python3.5
nb@ubuntu-0xA520322HC30H:~/proj/redis-py$ ls -la /usr/bin/python3.5
-rwxr-xr-x 2 root root 4464400 Nov 28 08:53 /usr/bin/python3.5
nb@ubuntu-0xA520322HC30H:~/proj/redis-py$ ls -la /usr/bin/python3.6
-rwxr-xr-x 2 root root 4695328 Jan 28 10:49 /usr/bin/python3.6
nb@ubuntu-0xA520322HC30H:~/proj/redis-py$ which virtualenv
/home/nb/.local/bin//virtualenv
And, in /home/nb/.local/bin/¹:
nb@ubuntu-0xA520322HC30H:~/proj/redis-py$ cd ~/.local/bin
nb@ubuntu-0xA520322HC30H:~/.local/bin$ ls
pbr pip2 pip3 virtualenv virtualenvwrapper_lazy.sh
pip pip2.7 pip3.5 virtualenv-clone virtualenvwrapper.sh
I wondered where this mysterious, and completely absent /usr/local/bin/python3.6 was in the code.
So I installed a full-text search tool and looked for it in the ~/.local folder.
nb@ubuntu-0xA520322HC30H:~$ cd .local
nb@ubuntu-0xA520322HC30H:~/.local$ sudo apt-get install --quiet --quiet silversearcher-ag
nb@ubuntu-0xA520322HC30H:~/.local$ ag '/usr/local/bin/python3.6'
bin/virtualenv-clone
1:#!/usr/local/bin/python3.6
bin/pbr
1:#!/usr/local/bin/python3.6
Looks like the static reference to Python's in 2 places.
I now have two options:
I can edit the /usr/local/bin/python3.6 text in there to refer to /usr/bin/python3.6
I can make a symlink from
/usr/local/bin/python3.6
->/usr/bin/python3.6
I went with option 1 for the bin/virtualenv-clone
file:
But I also did option 2, just in case this problem exists elsewhere on my system.
nb@ubuntu-0xA520322HC30H:~$ sudo ln -s /usr/bin/python3.6 /usr/local/bin/python3.6
Well, whatever it was, that worked:
nb@ubuntu-0xA520322HC30H:~/.local$ mkvirtualenv --python='/usr/bin/python3' redispytest
Running virtualenv with interpreter /usr/bin/python3
Using base prefix '/usr'
New python executable in /home/nb/Envs/redispytest/bin/python3
Also creating executable in /home/nb/Envs/redispytest/bin/python
Installing setuptools, pip, wheel...done.
virtualenvwrapper.user_scripts creating /home/nb/Envs/redispytest/bin/predeactivate
virtualenvwrapper.user_scripts creating /home/nb/Envs/redispytest/bin/postdeactivate
virtualenvwrapper.user_scripts creating /home/nb/Envs/redispytest/bin/preactivate
virtualenvwrapper.user_scripts creating /home/nb/Envs/redispytest/bin/postactivate
virtualenvwrapper.user_scripts creating /home/nb/Envs/redispytest/bin/get_env_details
(redispytest) nb@ubuntu-0xA520322HC30H:~/.local$
Summary: Find out which interpreter location your virtualenv is trying to use, and make a symlink from that location to your actual Python.
The reason you need to do this is that at least a few virtualenv locations will have a #!
line that refers to a specific location, but won't change if you, say, switch from compiling your own Python to using a PPA.
At first I was hesitant to do this, since I prefer to let the package manager handle this sort of thing, and not complicate my paths too much. But there really doesn't seem to be any other way to fix this. I tried uninstalling and reinstalling both virtualenv
and virtualenvwrapper
, to no avail.
¹Hmmm... there's pbr
's in my .local/bin. What's next, my .local/fridge? Damn hipsters.