1. #need to setup python in your own folder under your home folder, mkdir -p python2.6/{bin,include,share,lib/python2.6/site-packages} 2. # get virtualenv package wget http://pypi.python.org/packages/source/v/virtualenv/virtualenv-1.6.4.tar.gz tar zxvf virtualenv-1.6.4.tar.gz cd virtualenv-1.6.4 /usr/local/bin/python2.6 setup.py install \ --prefix=/home/your_user_name/python2.6/
Setup
Update 2011-09-27: Turns out virtualenv and virtualenvwrapper support this out of the box. Most of what’s written below is horrifically complex compared to just using the -p switch when you make your virtualenv. You simply need to do this:
$ mkvirtualenv -p /path/to/some/python coolname
That’ll create a new virtualenv called “coolname” that uses /path/to/some/python for it’s Python interpreter. I’ve tested this with PyPy and it worked great.
I don't get the hook_loader error, but it's complaining about lack of DEST_DIR $ mkvirtualenv --python /opt/local/bin/python2.7 Running virtualenv with interpreter /opt/local/bin/python2.7 You must provide a DEST_DIR – wmfox3 Jun 23 '11 at 3:04
Whoops, sorry--left out the key argument! That should be mkvirtualenv --python /path/to/python2.6 env_name. mkvirtualenv makes a folder called "env_name" in your $WORKON_HOME, which gets passed on to virtualenv as its DEST_DIR argument. Without specifying a name, it would have a hard time figuring out where to set things up, that's for sure. – Greg Haskins Jun 23 '11 at 4:48
Duh. I should have caught that. Yes, that worked. Guess the answer is to leave port select to python27 and run mkvirtualenv with the --python flag when I need to use something else. – wmfox3 Jun 25 '11 at 11:37
4 thoughts on “Linux下Python版本切换脚本”
Zhe says:
2011年11月18日 at 22:49
如果你用virtualenvwrapper的话
建立env时使用-p 指明python版本,
然后就可以随时用workon [env名]在不同版本间切换了。