If I attempt to create a virtual env I get this error message, which I do not understand: bad interpreter: No such file or directory. I have reviewed this stack overflow answer and have tried to apply it in the diagnostic steps below.
This is my first day running on Mojave but I don't know if that is a factor in this issue or not.
I have created a new empty folder for the project at /Users/Wes/Dropbox/Programming/Python/glade_againn
My plan has been to run the project in the virtualenv /Users/Wes/.virtualenvs/glade_againn
However, when I attempt to use virtualenv I get this error message.
$ virtualenv --version
-bash: /usr/local/bin/virtualenv: /usr/local/opt/python/bin/python2.7: bad interpreter: No such file or directory
If I attempt to install virtualenv with PIP I am told it already exists.
$ pip install virtualenv
Requirement already satisfied: virtualenv in /usr/local/lib/python2.7/site-packages (15.2.0)
$
My current PATH is
echo $PATH
/Library/Frameworks/Python.framework/Versions/3.6/bin:/opt/local/bin:/opt/local/sbin:/usr/local/opt/postgresql#9.4/bin:/usr/local/Cellar/postgresql/9.5.4_1/bin/psql/:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Applications/Wireshark.app/Contents/MacOS:/usr/local/git/bin:/Users/Wes/bin:/sw/bin:/usr/local/bin:/Users/Wes/.sdkman/candidates/groovy/current/bin/
If you search for pyth* across all those directories you get this list, in this order.
/Library/Frameworks/Python.framework/Versions/3.6/bin/python3
/Library/Frameworks/Python.framework/Versions/3.6/bin/python3-config
/Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6
/Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6-config
/Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6m
/Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6m-config
/opt/local/bin/python2.7
/opt/local/bin/python2.7-config
/opt/local/bin/python3.4
/opt/local/bin/python3.4-config
/opt/local/bin/python3.4m
/opt/local/bin/python3.4m-config
/opt/local/bin/pythonw2.7
/usr/local/bin/python-32
/usr/local/bin/python2-32
/usr/local/bin/python2.7-32
/usr/local/bin/python3
/usr/local/bin/python3-config
/usr/local/bin/python3.6
/usr/local/bin/python3.6-config
/usr/local/bin/python3.6m
/usr/local/bin/python3.6m-config
/usr/local/bin/pythoni
/usr/local/bin/pythoni1
/usr/local/bin/pythonw-32
/usr/local/bin/pythonw2-32
/usr/local/bin/pythonw2.7-32
/usr/bin/python
/usr/bin/python-config
/usr/bin/python2.7
/usr/bin/python2.7-config
/usr/bin/pythonw
/usr/bin/pythonw2.7
/sw/bin/python2.7
/sw/bin/python2.7-config
/usr/local/bin/python-32
/usr/local/bin/python2-32
/usr/local/bin/python2.7-32
/usr/local/bin/python3
/usr/local/bin/python3-config
/usr/local/bin/python3.6
/usr/local/bin/python3.6-config
/usr/local/bin/python3.6m
/usr/local/bin/python3.6m-config
/usr/local/bin/pythoni
/usr/local/bin/pythoni1
/usr/local/bin/pythonw-32
/usr/local/bin/pythonw2-32
/usr/local/bin/pythonw2.7-32
Does anyone have a suggestion on how to get virtualenv to work again?
Try to reinstall using this
pip install -U --force-reinstall virtualenv
if above solution doesn't work for you
you should create a new virtualenv again because of mojave update
In my case I was renaming project and project's folder where venv has been located.
So in my case I was changing paths to python interpreter in the following files:
~/PycharmProjects/myproject/venv/bin/activate*
And modified ~/PycharmProjects/myproject/venv/bin/pip* files to:
#!/home/myuser/PycharmProjects/myproject/venv/bin/python
# -*- coding: utf-8 -*-
import re
import sys
from pip._internal.cli.main import main
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
sys.exit(main())
To modify it I was required to login with root permissions: sudo su. The sudo vim.tiny venv/bin/pip just not allowed me to edit the files.
I've changed only the first line starting with #!/home...
In my case, I was on MacOS and I had python3.9 installed, but virtualenv was installed using python3.7 and at some point I uninstalled python3.7.
$ /usr/local/bin/virtualenv --version
-bash: /usr/local/bin/virtualenv: /usr/local/opt/python/bin/python3.7: bad interpreter: No such file or directory
However, my python version:
$ which python3.9
/usr/local/bin/python3.9
No amount of pip or pip3 install/uninstall/install virtualenv worked for me.
Finally I did the following:
$ python3.9 -m pip install --user virtualenv
Collecting virtualenv
Using cached virtualenv-20.4.6-py2.py3-none-any.whl (7.2 MB)
<snip>
Successfully installed appdirs-1.4.4 distlib-0.3.1 filelock-3.0.12 virtualenv-20.4.6
And then
$ /usr/local/bin/virtualenv --version
virtualenv 20.4.6 from <mypath>
Yay!!
That solved the problem in my case: (my env file is called .venv)
mv .venv .venv_old
python3.7 -m venv .venv
source .venv/bin/activate
pip install wheel
pip install --upgrade pip wheel setuptools
pip install -r requirements.txt
In my case, the error shows in Github action and the root cause is the broken python symbolic link. As a workaround, I just simply re-create it during the process.
Error:
home/runner/work/_temp/810926a2-36c5-4488-ac84-6f3f57713147.sh: /home/runner/work/dataops/dataops/.venv/bin/pytest: /home/runner/work/dataops/dataops/.venv/bin/python: bad interpreter: No such file or directory
Root Cause:
/home/runner/work/dataops/dataops/.venv/bin/python: broken symbolic link to /opt/hostedtoolcache/Python/3.9.15/x64/bin/python3.9
Solution:
Add below scripts into wherever has broken link:
PYTHON_PATH=$(which python3)
source .venv/bin/activate
PYTHON_BROKEN_PATH=$(dirname $(which pip))
rm $PYTHON_BROKEN_PATH/python
ln -s $PYTHON_PATH $PYTHON_BROKEN_PATH/python
export PATH=$PATH:$(dirname $PYTHON_BROKEN_PATH)
Similar problem after switching package managers on a Mac. No reinstallation required for my use case, just updates to 2 files.
1st update config file
I updated pyvenv.cfg in the virtual environment directory (cd /to/your/venv/dir)
I had to update the home and the version settings.
home = /usr/local/bin
include-system-site-packages = false
version = 3.10.8
2nd fix symlinks
Lastly I updated the symlink to the python executable. It's in the virtual environment's bin directory.
cd /to/your/venv/dir/bin
ln -s /usr/local/bin/python3.10 python
Note, in my case there were 2 other symlinks to python executables in the venv/bin directory, python3 and python3.10. I didn't need to touch these as they were both pointers to the python symlink that was just updated.
I've been keeping all my python2.7 installs in my ~/.local/ directory that way I don't have to sudo every time I want to do a pip install. I also have $HOME/.local/lib/python2.7/site-packages on my $PYTHONPATH. This has worked well for years but now I find myself needing to run python3 programs more frequently. After much research it seems like virtualenv is the most recommended way to deal with python 2 and 3 on the same system. But I am running into troubles. I can spin up a python3 virtual environment but when I try to install new libs with pip, my old global path (i.e. ~/.local/) is still being searched by pip, which makes sense. However, this is even the case if I remove my ~/.local/bin/ directory from my $PATH and unset my $PYTHONPATH.
Here is are the steps I took:
First check the preliminaries before activating virtualenv. (I'm on Ubuntu 16.04 btw)
maddoxw#firefly:~$ echo $PATH
/usr/local/cuda-8.0/bin:/home/maddoxw/.node_modules_global/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/maddoxw/bin:/home/maddoxw/scripts
maddoxw#firefly:~$ echo $PYTHONPATH
maddoxw#firefly:~$ python --version
Python 2.7.12
maddoxw#firefly:~$ python3 --version
Python 3.5.2
maddoxw#firefly:~$ which pip
Since I removed my ~/.local/bin directory from my path, then I can be certain pip will not be found. Also, $PYTHONPATH is still empty. Now I create my virtualenv:
maddoxw#firefly:~$ mkdir test && cd test/
mkdir: created directory 'test'
maddoxw#firefly:~/test$ python3 -m venv .env
maddoxw#firefly:~/test$ source .env/bin/activate
(.env) maddoxw#firefly:~/test$ echo $PATH
/home/maddoxw/test/.env/bin:/usr/local/cuda-8.0/bin:/home/maddoxw/.node_modules_global/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/maddoxw/bin:/home/maddoxw/scripts
(.env) maddoxw#firefly:~/test$ echo $PYTHONPATH
(.env) maddoxw#firefly:~/test$ which python
/home/maddoxw/test/.env/bin/python
(.env) maddoxw#firefly:~/test$ python --version
Python 3.5.2
(.env) maddoxw#firefly:~/test$ which pip
/home/maddoxw/test/.env/bin/pip
Good. My ~/.local/ is still NOT on my $PATH, $PYTHONPATH is still empty, python points to the correct path and version, and pip is pointing to the correct location. Now lets try to pip install a fresh lib.
(.env) maddoxw#firefly:~/test$ pip install Cython
Requirement already satisfied: Cython in /home/maddoxw/.local/lib/python2.7/site-packages
Why is pip still looking in a non-$PATH path?
First, install pip3 to use with python3. You can install it with the following command and then use pip3 to install your packages.
sudo apt-get install python3-pip
[Solved]
When I initially set up my python2.7 environment way back when, I created for myself a handy little function wrapper around pip so that I wouldn't have to type out the --user every time I wanted to pip install
pip() {
if [ "$1" = "install" -o "$1" = "bundle" ]; then
cmd="$1"
shift
$HOME/.local/bin/pip $cmd --user $#
else
$HOME/.local/bin/pip $#
fi
}
I put this function in ~/.bash.d/bash_functions
and in my ~/.bashrc i added the line,
[ -f ~/.bash.d/bash_functions ] && source ~/.bash.d/bash_functions
So, although I removed $HOME/.local/ from my path. This wrapper function was still being called everytime I fired up a new terminal. Weather or not I was or was not in a virtualenv was irrelevant.
Solution?
Commented out (or delete completely) the function wrapper fixed it.
My system is running CentOS 6. I do not have admin access, so sudo is not available. I have Python 2.7.3 available, along with pip and virtualenv. I was hoping that I could use these to set up a new virtual environment in which to install & run Python 3.5 or above.
I tried the method described here:
Using Python 3 in virtualenv
But got this error:
$ virtualenv -p python3 venv
The path python3 (from --python=python3) does not exist
My system also has a Python 3.4 module installed, so I tried that, however virtualenv does not seem to work there:
$ module load python/3.4.3
$ virtualenv -p python3 venv
-bash: virtualenv: command not found
This appears to make sense since virtualenv is only installed for Python 2.7:
$ module unload python
$ module load python/2.7
$ which virtualenv
/local/apps/python/2.7.3/bin/virtualenv
So, the next logical step would seem to be installing virtualenv for my Python 3... but this does not work either:
$ pip3 install virtualenv
Traceback (most recent call last):
File "/local/apps/python/3.4.3/bin/pip3", line 7, in <module>
from pip import main
ImportError: cannot import name 'main'
also
$ pip3 install --user virtualenv
Traceback (most recent call last):
File "/local/apps/python/3.4.3/bin/pip3", line 7, in <module>
from pip import main
ImportError: cannot import name 'main'
I started Google'ing this new error message, but did not see anything that seemed relevant for this situation. Any ideas? Even if I could get virtualenv installed on my Python 3.4 module, would I still be unable to upgrade it to Python 3.5+?
To round things out, I also tried to compile my own Python 3.6 from source, but that does not work either:
Python-3.6.0$ make install
if test "no-framework" = "no-framework" ; then \
/usr/bin/install -c python /usr/local/bin/python3.6m; \
else \
/usr/bin/install -c -s Mac/pythonw /usr/local/bin/python3.6m; \
fi
/usr/bin/install: cannot create regular file `/usr/local/bin/python3.6m': Permission denied
make: *** [altbininstall] Error 1
more background info:
$ which pip3
/local/apps/python/3.4.3/bin/pip3
$ which python
/local/apps/python/3.4.3/bin/python
You can download miniconda or Anaconda. It does not require superuser privileges because it installs in your home directory. After you install you can create new environments like this:
conda create -n py35 python=3.5
Then you can switch to the new environment:
source activate py35
Try this for Windows.
virtualenv -p C:\Python35\python.exe django_concurrent_env
cd django_concurrent_env
.\Source\activate
deactivate
Try out the following commands:
pip3 install virtualenv
pip3 install virtualenvwrapper
mkdir ~/.virtualenvs
export WORKON_HOME=~/.virtualenvs
source /usr/local/bin/virtualenvwrapper.sh
source ~/.bash_profile
which python3
Now copy the result of path of python3 in the last command and put it in the following command:
mkvirtualenv --python=python3/path/in/last/command myenv
I'm assuming pip3 is already installed. If not, install it before running these commands.
Source: https://docs.coala.io/en/latest/Help/MAC_Hints.html#create-virtual-environments-with-pyvenv
(I do have sudo access on my machine. I've not tried the commands without it. Please post if any issues comes.)
Since you already have virtualenv installed, you might only need to update the files and then run the command mkvirtualenv with proper arguments.
I'm trying to create a virtual environment with 3.4. I have followed instructions found through searching stackoverflow, as well as posting this issue on reddit, and continue to have the same problem: even when I specify python3.4, it installs both 3.4 AND 2.7. This then leads to all of the problems I was trying to avoid by using a virtual environment in the first place.
$ which python3
/Library/Frameworks/Python.framework/Versions/3.4/bin/python3
$ mkdir test
$ cd test
$ virtualenv -p /Library/Frameworks/Python.framework/Versions/3.4/bin/python3.4 venv
(various output saying it's creating venv/bin/python with 3.4)
$ source venv/bin/activate
(venv)$ python --version
Python 2.7.9
when I look in the venv/bin folder it has binaries for both 2.7.9 and 3.4.
after activating the environment:
$ echo $PATH
/Users/theinevitable/Documents/python/test/venv/bin:/Library/Frameworks/Python.framework/Versions/3.4/bin:/Library/Frameworks/Python.framework/Versions/2.7/bin:/Library/Frameworks/Python.framework/Versions/3.4/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Applications/Postgres.app/Contents/Versions/9.4/bin
$ which python
/Users/theinevitable/Documents/python/test/venv/bin/python
$ which python3
/Library/Frameworks/Python.framework/Versions/3.4/bin/python3
one person on reddit suggested trying to use venv instead:
$ python3.4 -m venv my_venv
/Library/Frameworks/Python.framework/Versions/3.4/bin/python3.4: No module named venv
$ pyvenv tester
File "/Library/Frameworks/Python.framework/Versions/3.4/bin/pyvenv", line 10
print('Error: %s' % e, file=sys.stderr)
^
SyntaxError: invalid syntax
I have a shared account in a web-hosting that has Python 2.4 installed, but my code is not compatible with 2.4. Is it possible to install Python 2.6 directly to Virtualenv?
Note: I don´t have permission to install it in the shared server.
Here are the options for virtualenv
$ virtualenv
You must provide a DEST_DIR
Usage: virtualenv [OPTIONS] DEST_DIR
Options:
--version show program's version number and exit.
-h, --help show this help message and exit.
-v, --verbose Increase verbosity.
-q, --quiet Decrease verbosity.
-p PYTHON_EXE, --python=PYTHON_EXE
The Python interpreter to use, e.g.,
--python=python2.5 will use the python2.5 interpreter
to create the new environment. The default is the
interpreter that virtualenv was installed with
(/usr/bin/python)
--clear Clear out the non-root install and start from scratch
--no-site-packages Don't give access to the global site-packages dir to
the virtual environment
--unzip-setuptools Unzip Setuptools or Distribute when installing it
--relocatable Make an EXISTING virtualenv environment relocatable.
This fixes up scripts and makes all .pth files
relative
--distribute Use Distribute instead of Setuptools. Set environ
variable VIRTUALENV_USE_DISTRIBUTE to make it the
default
--prompt==PROMPT Provides an alternative prompt prefix for this
environment
1) What you want to do is install python to a directory that you are able to write too.
You can follow the instructions here.
For Python 2.7.1
Python source
mkdir ~/src
mkdir ~/.localpython
cd ~/src
wget http://www.python.org/ftp/python/2.7.1/Python-2.7.1.tgz
tar -zxvf Python-2.7.1.tgz
cd Python-2.7.1
make clean
./configure --prefix=/home/${USER}/.localpython
make
make install
2) Install virtualenv
virtualenv source
cd ~/src
wget http://pypi.python.org/packages/source/v/virtualenv/virtualenv-1.5.2.tar.gz#md5=fbcefbd8520bb64bc24a560c6019a73c
tar -zxvf virtualenv-1.5.2.tar.gz
cd virtualenv-1.5.2/
~/.localpython/bin/python setup.py install
3) Create a virtualenv using your local python
virtualenv docs
mkdir /home/${USER}/virtualenvs
cd /home/${USER}/virtualenvs
~/.localpython/bin/virtualenv py2.7 --python=/home/${USER}/.localpython/bin/python2.7
4) Activate the environment
cd ~/virtualenvs/py2.7/bin
source ./activate
5) Check
(py2.7)$ python
Python 2.7.1 (r271:86832, Mar 31 2011, 15:31:37)
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
(py2.7)$ deactivate
$ python
Python 2.6.6 (r266:84292, Sep 15 2010, 15:52:39)
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
Pre-requisites:
sudo easy_install virtualenv
sudo pip install virtualenvwrapper
Installing virtualenv with Python2.6:
You could manually download, build and install another version of Python to /usr/local or another location.
If it's another location other than /usr/local, add it to your PATH.
Reload your shell to pick up the updated PATH.
From this point on, you should be able to call the following 2 python binaries from your shell python2.5 and python2.6
Create a new instance of virtualenv with python2.6:
mkvirtualenv --python=python2.6 yournewenv
Now a days, the easiest way I found to have a more updated version of Python is to install it via conda into a conda environment.
Install conda(you may need a virtualenv for this)
pip install conda
Installing a new Python version inside a conda environent
I'm adding this answer here because no manual download is needed. conda will do that for you.
Now create an environment for the Python version you want. In this example I will use 3.5.2, because it it the latest version at this time of writing (Aug 2016).
conda create -n py35 python=3.5.2
Will create a environment for conda to install packages
To activate this environment(I'm assuming linux otherwise check the conda docs):
source activate py35
Now install what you need either via pip or conda in the environemnt(conda has better binary package support).
conda install <package_name>
Full guide with pyenv
If pyenv is not installed then install it with pyenv-installer:
$ curl https://pyenv.run | bash
To use any custom python version, e.g. 3.5.6 use the following:
pyenv install 3.5.6
pyenv virtualenv 3.5.6 NAME_OF_YOUR_ENV
cd YOUR_PROJECT_PATH
pyenv local NAME_OF_YOUR_ENV
The usual approach is to download the source and build and install locally (but not directly in virtualenv), and then create a new virtualenv using that local Python install. On some systems, it may be possible to download and install a prebuilt python, rather than building from source.
This procedure installs Python2.7 anywhere and eliminates any absolute path references within your env folder (managed by virtualenv). Even virtualenv isn't installed absolutely.
Thus, theoretically, you can drop the top level directory into a tarball, distribute, and run anything configured within the tarball on a machine that doesn't have Python (or any dependencies) installed.
Contact me with any questions. This is just part of an ongoing, larger project I am engineering. Now, for the drop...
Set up environment folders.
$ mkdir env
$ mkdir pyenv
$ mkdir dep
Get Python-2.7.3, and virtualenv without any form of root OS installation.
$ cd dep
$ wget http://www.python.org/ftp/python/2.7.3/Python-2.7.3.tgz
$ wget https://raw.github.com/pypa/virtualenv/master/virtualenv.py
Extract and install Python-2.7.3 into the pyenv dir. make clean is optional if you are doing this a 2nd, 3rd, Nth time...
$ tar -xzvf Python-2.7.3.tgz
$ cd Python-2.7.3
$ make clean
$ ./configure --prefix=/path/to/pyenv
$ make && make install
$ cd ../../
$ ls
dep env pyenv
Create your virtualenv
$ dep/virtualenv.py --python=/path/to/pyenv/bin/python --verbose env
Fix the symlink to python2.7 within env/include/
$ ls -l env/include/
$ cd !$
$ rm python2.7
$ ln -s ../../pyenv/include/python2.7 python2.7
$ cd ../../
Fix the remaining python symlinks in env. You'll have to delete the symbolically linked directories and recreate them, as above. Also, here's the syntax to force in-place symbolic link creation.
$ ls -l env/lib/python2.7/
$ cd !$
$ ln -sf ../../../pyenv/lib/python2.7/UserDict.py UserDict.py
[...repeat until all symbolic links are relative...]
$ cd ../../../
Test
$ python --version
Python 2.7.1
$ source env/bin/activate
(env)
$ python --version
Python 2.7.3
Aloha.
I'm using virtualenvwrapper and don't want to modify $PATH, here's how:
$ which python3
/usr/local/bin/python3
$ mkvirtualenv --python=/usr/local/bin/python3 env_name
You may use pyenv.
There are a lot of different versions anaconda, jython, pypy and so on...
https://github.com/yyuu/pyenv
Installation as simple as pyenv install 3.2.6
pyenv install --list
Available versions:
2.1.3
2.2.3
2.3.7
2.4
2.4.1
2.4.2
2.4.3
2.4.4
2.4.5
2.4.6
2.5
2.5.1
2.5.2
2.5.3
2.5.4
2.5.5
2.5.6
2.6.6
...
Although the question specifically describes installing 2.6, I would like to add some importants points to the excellent answers above in case someone comes across this. For the record, my case was that I was trying to install 2.7 on an ubuntu 10.04 box.
First, my motivation towards the methods described in all the answers here is that installing Python from deadsnake's ppa's has been a total failure. So building a local Python is the way to go.
Having tried so, I thought relying to the default installation of pip (with sudo apt-get install pip) would be adequate. This unfortunately is wrong. It turned out that I was getting all shorts of nasty issues and eventually not being able to create a virtualenv.
Therefore, I highly recommend to install pip locally with wget https://raw.github.com/pypa/pip/master/contrib/get-pip.py && python get-pip.py --user. This related question gave me this hint.
Now if this doesn't work, make sure that libssl-dev for Ubuntu or openssl-dev for CentOS is installed. Install them with apt-get or yum and then re-build Python (no need to remove anything if already installed, do so on top). get-pip complains about that, you can check so by running import ssl on a py shell.
Last, don't forget to declare .local/bin and local python to path, check with which pip and which python.
No, but you can install an isolated Python build (such as ActivePython) under your $HOME directory.
This approach is the fastest, and doesn't require you to compile Python yourself.
(as a bonus, you also get to use ActiveState's binary package manager)
I have not found suitable answer, so here goes my take, which builds upon #toszter answer, but does not use system Python (and you may know, it is not always good idea to install setuptools and virtualenv at system level when dealing with many Python configurations):
#!/bin/sh
mkdir python_ve
cd python_ve
MYROOT=`pwd`
mkdir env pyenv dep
cd ${MYROOT}/dep
wget https://pypi.python.org/packages/source/s/setuptools/setuptools-15.2.tar.gz#md5=a9028a9794fc7ae02320d32e2d7e12ee
wget https://raw.github.com/pypa/virtualenv/master/virtualenv.py
wget https://www.python.org/ftp/python/2.7.9/Python-2.7.9.tar.xz
xz -d Python-2.7.9.tar.xz
cd ${MYROOT}/pyenv
tar xf ../dep/Python-2.7.9.tar
cd Python-2.7.9
./configure --prefix=${MYROOT}/pyenv && make -j 4 && make install
cd ${MYROOT}/pyenv
tar xzf ../dep/setuptools-15.2.tar.gz
cd ${MYROOT}
pyenv/bin/python dep/virtualenv.py --no-setuptools --python=${MYROOT}/pyenv/bin/python --verbose env
env/bin/python pyenv/setuptools-15.2/setup.py install
env/bin/easy_install pip
echo "virtualenv in ${MYROOT}/env"
The trick of breaking chicken-egg problem here is to make virtualenv without setuptools first, because it otherwise fails (pip can not be found). It may be possible to install pip / wheel directly, but somehow easy_install was the first thing which came to my mind. Also, the script can be improved by factoring out concrete versions.
NB. Using xz in the script.
First of all, Thank you DTing for awesome answer. It's pretty much perfect.
For those who are suffering from not having GCC access in shared hosting, Go for ActivePython instead of normal python like Scott Stafford mentioned. Here are the commands for that.
wget http://downloads.activestate.com/ActivePython/releases/2.7.13.2713/ActivePython-2.7.13.2713-linux-x86_64-glibc-2.3.6-401785.tar.gz
tar -zxvf ActivePython-2.7.13.2713-linux-x86_64-glibc-2.3.6-401785.tar.gz
cd ActivePython-2.7.13.2713-linux-x86_64-glibc-2.3.6-401785
./install.sh
It will ask you path to python directory. Enter
../../.localpython
Just replace above as Step 1 in DTing's answer and go ahead with Step 2 after that. Please note that ActivePython package URL may change with new release. You can always get new URL from here : http://www.activestate.com/activepython/downloads
Based on URL you need to change the name of tar and cd command based on file received.
virtualenv --python=".localpython/bin/python2.7" env