Switching between python2 and python3 as the default python
<p>Is there a standard way to switch between python2 to python3 as the default python, similar to how virtualenv can be used to switch between different sandboxed python environments?</p>

<p>I would like to avoid manually fiddling with symlinks and the PATH variable so that the solution is portable.</p>

<p>Since it is about switching python version, the solution must obviously not be written in python but rather in bash or something portable.</p>

<p>And a slight deviation from the original question: if there was a way to have something like <code>mkvirtualenv2</code> and <code>mkvirtualenv3</code> that would be an ever better solution. Is it possible? I understand it's not, because virtualenv can only operate within a single Python interpreter env. If I install virtualenv for both python2 and python3, then how to switch between executables in a clean way?</p>

<p>Ideally it would be something like <a href="https://github.com/creationix/nvm" rel="nofollow">nvm</a> for nodejs or <a href="http://rbenv.org/" rel="nofollow">rbenv</a> for Ruby.</p>

<p>After some more research it looks like a possible solution could have been <a href="https://github.com/yyuu/pyenv" rel="nofollow">pyenv</a> which is supposed to be used as described in the <a href="https://amaral.northwestern.edu/resources/guides/pyenv-tutorial" rel="nofollow">pyenv tutorial</a> <strong><em>but</em></strong> it only recognizes a <em>single</em> system-wide python runtime (whichever is the default at the moment), and for some strange reason it doesn't provide the option to switch between the system-wide python2 and python3. </p>

<p>Looks like pyenv can switch only between the system python and any of the versions explicitly installed via pyenv which can all be seen via <code>pyenv install --list</code> and installed with e.g. <code>pyenv install 3.6-dev</code>.</p>

<p><a href="http://stackoverflow.com/a/29950604/191246">Pyenv can integrate with virtualenv</a> which could be handy for dev testing since it includes all versions of anaconda, miniconda, pypy, jython, stackless, etc. It's probably the easiest way of installing multiple versions of python which do not come with your package manager, ie on older Linux distros that don't have a modern python in their repos.</p>

<p>But in the long run, all things considered, I found that the solution proposed by <a href="http://stackoverflow.com/users/2904896/metatoaster">metatoaster</a> is simpler and totally meets my requirements since I can use the python2 virtualenv to create both python2 and python3 environments without any overhead:</p>

<pre><code>python -V
Python 2.7.12
mkdir -p ~/.virtualenvs &amp;&amp; cd ~/.virtualenvs
virtualenv -p /usr/bin/python3 mypy3env
workon mypy3env
python -V
&gt;&gt;&gt; Python 3.5.2
</code></pre>

python python-3.x virtualenv python-2.x pyenv