ubuntu use python in virtualenv

2016-12-05  本文已影响12人  mugtmag

when you have installed python3.5 or python2.7, then copy codes following to use python3.5 or python2.7 in virtualenv.

  1. install pip
$ sudo apt-get install python-pip
  1. use pip to install virtualenv
$ pip install virtualenv
  1. make a directory noly for virtualenv environment
 $ mkdir virtualenvs
  1. Install python3.5 virtualenv, "--no-site-packages" means to make site-packages for python3.5 in virtualenv are separated from site-packages out of the virtualenv.
$ cd virtualenvs/
$ virtualenv --no-site-packages --distribute -p /usr/bin/python3.5 py3.5
  1. activate py3.5
$ source py3.5/bin/activate
  1. check the python version at present.
$ which python
  1. you can also deactivate py3.5
$ deactivate
  1. you may have python2.7 virtualenv as well. Use code like py3.5.
$ virtualenv --no-site-packages --distribute -p /usr/bin/python2.7 py2.7

If you have two python version (python2 and python3),you can use sudo apt install virtualenv
Also, you can use source py3.5/bin/activate and deactivate to change python versions.

上一篇下一篇

猜你喜欢

热点阅读