Windows下安装python2与python3以及分别对应的virtualenv

时间:2023-03-09 19:53:02
Windows下安装python2与python3以及分别对应的virtualenv

第三次装python2与python3


除此之外还学会了如何在命令行复制代码
1.单击右键
2.菜单中选择标记
3.按住左键选中需要复制的内容
4.松开左键
5.单击右键


全局中python版本为python2.7.14
当分别转入python安装目录中时,就可以使用对应的python版本。


验证python2——命令行输入:

C:\Users\admin>cd /d G:\python\python2

G:\python\python2>python
Python 2.7.14 (v2.7.14:84471935ed, Sep 16 2017, 20:25:58) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()

验证python3——命令行输入:

G:\python\python2>cd /d G:\python\python3

G:\python\python3>python
Python 3.6.3 (v3.6.3:2c5fed8, Oct 3 2017, 18:11:49) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()

大创项目<python3 django==1.10.6>
1.在python3目录下安装 虚拟环境virtualenv

G:\python\python3>pip install virtualenv

2.创建虚拟环境

G:\python\python3>virtualenv G:\python\python3\VIRTUALENV

3.激活虚拟环境

G:\python\python3>G:\python\python3\VIRTUALENV\Scripts\activate

4.此时已经进入虚拟环境,验证python版本

(VIRTUALENV) G:\python\python3>python
Python 3.6.3 (v3.6.3:2c5fed8, Oct 3 2017, 18:11:49) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()

5.安装django

(VIRTUALENV) G:\python\python3>pip install django==1.10.6

6.验证django是否正确安装

G:\python\python2>cd /d G:\python\python3

G:\python\python3>python
Python 3.6.3 (v3.6.3:2c5fed8, Oct 3 2017, 18:11:49) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'django'
>>> exit()

报错,意思是当前目录下启用python,并未安装django模块。
翻看目录想找到django安装到的地方,被我找到了!在VIRTUALENV文件夹中。
于是我灵机一动——转入VIRTUALENV文件夹

(VIRTUALENV) G:\python\python3>cd /d G:\python\python3\VIRTUALENV

(VIRTUALENV) G:\python\python3\VIRTUALENV>python
Python 2.7.14 (v2.7.14:84471935ed, Sep 16 2017, 20:25:58) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
>>> django.get_version()
'1.10.6'
>>> exit()

成功!


heand项目<python2 django==1.9.8>

C:\Users\admin>cd /d G:\python\python2

1.在python2目录下安装 虚拟环境virtualenv

G:\python\python2>pip install virtualenv
Requirement already satisfied: virtualenv in g:\python\python2\lib\site-packages

2.创建虚拟环境

G:\python\python2>virtualenv G:\python\python2\VIRTUALENV

3.激活虚拟环境

G:\python\python2>G:\python\python2\VIRTUALENV\Scripts\activate

4.此时已经进入虚拟环境,验证python版本

(VIRTUALENV) G:\python\python2>python
Python 2.7.14 (v2.7.14:84471935ed, Sep 16 2017, 20:25:58) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()

5.安装django

(VIRTUALENV) G:\python\python2>pip install django==1.9.8

6.验证django是否正确安装

(VIRTUALENV) G:\python\python2>cd G:\python\python2\VIRTUALENV

(VIRTUALENV) G:\python\python2\VIRTUALENV>python
Python 2.7.14 (v2.7.14:84471935ed, Sep 16 2017, 20:25:58) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
>>> django.get_version()
'1.9.8'
>>> exit()