win10系统安装两个版本的python,该怎么安装Django
最近遇到一个问题,系统上安装了python2,7 和python3.5两个版本,然后使用命令:pip install Django 安装Django后却发现以下情况:
Traceback (most recent call last):
File "manage.py", line 17, in <module>
"Couldn't import Django. Are you sure it's installed and "
ImportError: Couldn't import Django. Are you sure it's installed and available on your PYTHONPATH environment variable? Did you forget to activate a virtual environment?
有些奇怪明明按照成功了,再安装的时候也提示已存在:
Requirement already satisfied: django in f:\python\lib\site-packages (1.11.15)
Requirement already satisfied: pytz in f:\python\lib\site-packages (from django) (2018.5)
但这个提示提醒了我,路径显示的是python,这是安装的python2.7版本的路径
于是重新使用命令:pip3 install django 安装后ok:
Python 3.5.2 (default, Nov 23 2017, 16:37:01)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>>
>>> import django>>>
当你有两个不同的Python3版本时,需要下载 Django 压缩包,解压并和Python安装目录放在同一个根目录,进入 Django 目录,
想用python2.7版本Django 执行python2 setup.py install
想用python3.6版本Django 执行python36 setup.py install
想用python3.7版本Django 执行python37 setup.py install
然后开始安装,Django将要被安装到Python的Lib下site-packages。
注意:在命令行中使用Python36或者python37 之前需要添加对应版本的环境变量到系统中
最好的办法还是建立虚拟环境然后设置不同的环境