Python多版本环境搭建

首先贴一幅Python基础知识梳理图片:

《Python多版本环境搭建》
《Python多版本环境搭建》

Python 3.5安装后,已自带了easy_install和pip.现因为要学习用Python学习数据分析,而书中例子是基于Python 2.7版本的,考虑到很多老代码也是基于2.7版本的,因此决定在机器上装上双版本.

(如果不知道已经安装的Python在哪里,可通过cmd–>Python 执行如下代码获得)

import sys

print(sys.prefix)

首先准备好安装文件:

《Python多版本环境搭建》
双击python-2.7.amd64.msi安装Python.安装完成后如图:

《Python多版本环境搭建》
《Python多版本环境搭建》 安装完成后,分别进入对应文件夹,重命名相关可执行文件,完毕后如图:

《Python多版本环境搭建》
《Python多版本环境搭建》 添加目录到环境变量PATH,如图(此时这里2.7版本的scripts文件夹还未生成,为操作省事先一并建上):

《Python多版本环境搭建》
此时两个版本的Python已经可以用了,如下所示:

C:\Users\m>python2
Python 2.7 (r27:82525, Jul 4 2010, 07:43:08) [MSC v.1500 64 bit (AMD64)] on win32
Type “help”, “copyright”, “credits” or “license” for more information.
>>> exit()

C:\Users\m>python3
Python 3.5.2 (v3.5.2:4def2a2901a5, Jun 25 2016, 22:18:55) [MSC v.1900 64 bit (AMD64)] on win32
Type “help”, “copyright”, “credits” or “license” for more information.
>>>

接下来为Python 2.7安装ez_install和pip.先cd到源代码目录.

C:\WINDOWS\system32>g:

G:\>cd baiduyundownload\python-2.7.amd64.msi

G:\baiduyundownload\python-2.7.amd64.msi>python2 ez_setup.py

Downloading
http://pypi.python.org/packages/2.7/s/setuptools/setuptools-0.6c11-py2.7.egg

Processing setuptools-0.6c11-py2.7.egg

Copying setuptools-0.6c11-py2.7.egg to d:\program files\python27\lib\site-packages

Adding setuptools 0.6c11 to easy-install.pth file

Installing easy_install-script.py script to D:\Program Files\Python27\Scripts

Installing easy_install.exe script to D:\Program Files\Python27\Scripts

Installing easy_install.exe.manifest script to D:\Program Files\Python27\Scripts

Installing easy_install-2.7-script.py script to D:\Program Files\Python27\Scripts

Installing easy_install-2.7.exe script to D:\Program Files\Python27\Scripts

Installing easy_install-2.7.exe.manifest script to D:\Program Files\Python27\Scripts

Installed d:\program files\python27\lib\site-packages\setuptools-0.6c11-py2.7.egg

Processing dependencies for setuptools==0.6c11

Finished processing dependencies for setuptools==0.6c11

安装pip

G:\baiduyundownload\python-2.7.amd64.msi>cd pip-8.1.1
G:\baiduyundownload\python-2.7.amd64.msi\pip-8.1.1>python2 setup.py install
running install
running bdist_egg
running egg_info
writing requirements to pip.egg-info\requires.txt
writing pip.egg-info\PKG-INFO
writing top-level names to pip.egg-info\top_level.txt

………………………

Installed d:\program files\python27\lib\site-packages\pip-8.1.1-py2.7.egg
Processing dependencies for pip==8.1.1
Finished processing dependencies for pip==8.1.1

G:\baiduyundownload\python-2.7.amd64.msi\pip-8.1.1>

安装完成!

针对一些IDE在重命名Python可执行程序之后无法找到可用解析器的问题,可以将exe程序再复制一份,改回python.exe即可.可以为项目指定特定版本的Python.

《Python多版本环境搭建》
《Python多版本环境搭建》

命令行使用时,输入python2|python3指定需要的版本.

    原文作者:奔跑的小明
    原文地址: https://zhuanlan.zhihu.com/p/24515742
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞