windows下搭建python开发环境

安装python

官网下载安装包后安装,以2.7为例,安装完成后在环境变量Path中添加C:\Python27;C:\Python27\Scripts。在cmd中输入python -V,输出版本信息则安装成功。

创建virtualenv虚拟环境

2.1 安装virtualenv

python 2.7中包含了pip,可以在cmd下输入pip -V验证。
执行:

1
pip install virtualenv


如需代理,windows下可执行:
1
pip --proxy proxy:port install virtualenv

linux下:
1
2
export https_proxy=proxy:port
sudo -E pip insatll virtualenv

安装完后输入virtualenv –version验证。

可以安装virtualenvwrapper进行更方便的操作,windows下是virtualenvwrapper-win
Virtaulenvwrapper是virtualenv的扩展包,用于更方便管理虚拟环境,它可以做:

  1. 将所有虚拟环境整合在一个目录下
  2. 管理(新增,删除,复制)虚拟环境
  3. 切换虚拟环境
1
2
3
4
5
6
7
8
9
C:\Work\WorkProject\Python>pip --proxy proxy:port install virtualenvwrapper-win
You are using pip version 7.0.1, however version 7.1.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
Collecting virtualenvwrapper-win
Downloading virtualenvwrapper-win-1.2.1.zip
Requirement already satisfied (use --upgrade to upgrade): virtualenv in c:\python27\lib\site-packages (from virtualenvwrapper-win)
Installing collected packages: virtualenvwrapper-win
Running setup.py install for virtualenvwrapper-win
Successfully installed virtualenvwrapper-win-1.2.1

2.2 创建虚拟环境

创建一个目录用来保存虚拟环境,进入该目录并在cmd下执行:

1
2
3
4
5
6
7
8
9
C:\Work\WorkProject\Python>mkvirtualenv dayaenv
New python executable in dayaenv\Scripts\python.exe
Installing setuptools, pip, wheel...done.

(dayaenv) C:\Work\WorkProject\Python>lsvirtualenv

dir /b /ad "C:\Users\jacob\Envs"
======================================================
dayaenv

退出虚拟环境:
1
2
3
(dayaenv) C:\Work\WorkProject\Python>deactivate

C:\Work\WorkProject\Python>