On the same computer at the same installation Python2 and Python3 (reprint)

Reprinted Source: https://www.cnblogs.com/zhengyihan1216/p/6011640.html

Currently two versions of Python and Python3 Python2 exist, and both versions at the same time

Updates and maintenance.

In the end is to choose Python2 or choose Python3, depending on the current library to be used, which supports the framework version.

For example: HTMLTestRunner, locustio support Python2, but does not support Python3.

So many times, you need to install Python2 and Python3 on a computer.

 

In this part mainly talk about how to install Python2 and Python3 on the same computer, and can be used normally pip.

 

A mounting Python 2 (and PIP)

1.1, Python's official website to download https://www.python.org/ Python installation file,

     For Windows users, if a 32-bit system, select the x86 version; if a 64-bit system, select the 64-bit version of the installation files.

     My own computer is a 64-bit, 64-bit in accordance with the following examples will be described.

     The name of the downloaded installation file looks like this: python-2.7.12.amd64.exe

 

1.2, click the "" python-2.7.12.amd64 "" this installation file has to click next, you need to pay special attention when choosing the installation path: Python installation path can not have spaces!

     In order to distinguish between Python2 or Python3, the files under the directory python.exe rename python2.exe, as shown in the screenshot below:

     

 

1.3, adding environment variables Python2

     This computer - Properties - Advanced System Settings - Advanced - Environment Variables - System variables --Path-- editor

     Add here; E: \ setup \ Python27 \ Scripts \; E: \ setup \ Python27 \; (here to write according to their own installation path, and note that the value separated by semicolons, and other variables;

                                                                                                   This variable is not configured, will prompt "is not an internal command" input Python2 in cmd)

 

1.4, in cmd, enter Python2, if prompt the figure appears, the installation was successful Python2

    

 

 1.5, installation setuptools.

     In step 1.6 pip to be installed depends on the setuptools, so it is necessary to install the setuptools, pip install.

     Https://pypi.python.org/pypi/setuptools to the official website to download, with names like like this "" setuptools-28.7.0.zip "" (download time is not the same, the version number may be different), decompress;

     To enter in cmd (directory files present in both setup.py) unpacked directory, performing> python2 setup.py install (Note: Due to the foregoing step 1.2 python.exe will rename the file for python2.exe, so here must write python2 when entering commands, rather than python)

 

1.6, install pip

       pip is a tool to install and manage python package to install python package by pip become very simple.

       To the official website https://pypi.python.org/pypi/pip, pip download compressed files, download similar name like this "" pip-8.1.2.tar "" (download time is not the same, the version number may not the same), decompress;

       Into (directory exists both setup.py file) unpacked directory in cmd, do> python2 setup.py install (Note: Here's why the command execution is pytho2, rather than the python, the same reason as 1.5)

       At this point we look at Python2 of pip installation directory E: \ setup \ Python27 \ Scripts, see the screenshot below, there pip, pip2.7, pip2, description or pip2.7 pip performed at this time or in cmd pip2 execution is Python2 the pip.

       

1.7, enter cmd in the pip2 or pip2.7, if the content of the following screenshot appears stating that the installation was successful pip

        

 

 

Second, the installation Python3 (due Python3 own PIP, there is no need to install PIP)

2.1, Python's official website to download the installation file Python3 of https://www.python.org/,

     For Windows users, if a 32-bit system, select the x86 version; if a 64-bit system, select the 64-bit version of the installation files.

     My own computer is a 64-bit, 64-bit in accordance with the following examples will be described.

     The name of the downloaded installation file looks like this: python-3.5.0-amd64.exe

 

2.2, click the "" python-3.5.0-amd64.exe "" this installation file has to click next, you need to pay special attention when choosing the installation path: Python installation path can not have spaces!

 

2.3, check Python3 environment variable to add

       Python3 during installation can choose to automatically add environment variables, but sometimes it can not be added automatically, so at this time to confirm their own.

       This computer - Properties - Advanced System Settings - Advanced - Environment Variables - System variables --Path

       If there is no environment variables related Python3 in here to add; E: \ setup \ Python35 \ Scripts \; E: \ setup \ Python35 \; (here to write according to their actual installation path)

 

2.4、检查python3是否安装成功,在cmd中输入python,若显示如下图所示,是有关python3的版本,则说明python3安装成功。

        

 

        你可能有疑问:为什么这里不输入python3?  答:因为没有修改E:\setup\Python35目录下python.exe文件的名字为python3.exe。Python2里做了修改,所以这                                                                                 里修改不修改都无所谓,只要是能与E:\setup\Python27目录下的python.exe文件不重名即可。

 

2.5、验证Python3里pip是否自动安装成功

       在cmd里输入pip3或是pip3.5(此时输入pip看不出是Python2还是Python3中的pip),若有截图中的显示则表明Python3中pip自动安装成功。

       

 

       此时你可能有疑问,你怎么知道是输入pip3或是pip3.5,而不是pip3.6?因为在E:\setup\Python35\Scripts目录下pip.exe文件的名字决定的:如下图所示:

       

 

以上一和二将python2和python3 以及各自的pip安装完成。

 

三、具体使用

若是在Python2中使用pip操作时,用pip2或是pip2.7相关命令。

      例:给Python2安装selenium,在cmd中输入 pip2 install selenium 或是 pip2.7 install selenium

 

若是在Python3中使用pip操作时,用pip3或是pip3.5相关命令。

      例:给Python3安装selenium,在cmd中输入 pip3 install selenium 或是 pip3.5 install selenium 

 

若有的包不支持pip的安装形式,将相应的文件下载解压后放入到某个目录下,用cmd进入到解压后的目录

      若是给Python2安装该包,则执行python2 setup.py install

      若是给Python3安装该包,则执行python setup.py install        

 

Guess you like

Origin blog.csdn.net/woyizhizaizhaoni/article/details/90732603