当前系统使用 virtualenv 虚拟环境
当前python版本:
$ python --version
Python 3.5.3
启动 python
$ python
Python 3.5.3 (default, Jan 19 2017, 14:11:04)
[GCC 6.3.0 20170118] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
为了解决维护不同应用程序对应不同版本的问题,Python使用了虚拟环境的概念。 虚拟环境是Python解释器的完整副本。在虚拟环境中安装三方包时只会作用到虚拟环境,全局Python解释器不受影响。 那么,就为每个应用程序安装各自的虚拟环境吧。
# python2 要另安装 virtualenv
$ virtualenv venv
# 启动
$ source venv/bin/activate
(venv) $ _
# 退出当前虚拟环境
deactivate
# python3 内置有 venv
$ python3 -m venv venv
# 启动 虚拟环境
$ source venv/bin/activate
(venv) $ _
# 退出当前虚拟环境
deactivate
激活的虚拟环境为 临时的
多个终端激活虚拟环境,不会相互影响
启动虚拟环境下,安装其他的库,不会影响系统
(venv) $ pip install flask
(venv) $ python
Python 3.5.3 (default, Jan 19 2017, 14:11:04)
[GCC 6.3.0 20170118] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> import flask
>>>