简体   繁体   English

点Django版本与Python版本不同

[英]Pip Django Version Different than Python's

I am currently trying to complete the Django tutorial found here: https://docs.djangoproject.com/en/1.9/intro/tutorial01/ 我目前正在尝试完成在此处找到的Django教程: https//docs.djangoproject.com/zh/1.9/intro/tutorial01/

However, when I try to run python manage.py migrate I get the error Unknown command: 'migrate' . 但是,当我尝试运行python manage.py migrate ,出现错误Unknown command: 'migrate' I looked this up and discovered that this means I am using a version of Django that doesn't support migrate. 我查了一下,发现这意味着我使用的是不支持迁移的Django版本。 So I ran python -c "import django; print(django.get_version())" to see what version of Django Python was using. 所以我运行了python -c "import django; print(django.get_version())"来查看使用的是哪个版本的Django Python。 Turns out it's 1.6.1. 原来是1.6.1。 This doesn't make sense though because when I do pip list I get Django (1.9.2). 但这没有任何意义,因为当我执行pip list我得到了Django(1.9.2)。 If I look in my settings.py file it even says "Generated by 'django-admin startproject' using Django 1.9.1." 如果我查看settings.py文件,它甚至会显示“由django-admin startproject使用Django 1.9.1生成”。

Does anyone know why Python is using a different version of Django than is installed using pip? 有谁知道为什么Python使用与使用pip安装的版本不同的Django?

It's highly recommended that you run Django in a virtual environment as it will make managing Django a lot easier, and you don't want to mess with the python version on your system. 强烈建议您在虚拟环境中运行Django,因为这将使Django的管理变得更加容易,并且您不想弄乱系统上的python版本。

use virtualenv -p /usr/bin/python3.5 <path/to/new/virtualenv/> to use virtualenv with a specific python version. 使用virtualenv -p /usr/bin/python3.5 <path/to/new/virtualenv/>将virtualenv与特定的python版本一起使用。

Then pip install Django to get the latest version of Django. 然后pip install Django以获取最新版本的Django。

Edit: 编辑:

Don't forget that when you're messing with Django settings and files, that you need to activate your virtualenv in your command prompt. 不要忘记,当您弄乱Django设置和文件时,需要在命令提示符下激活virtualenv。

Type source myprojectenv/bin/activate and your prompt should change to 键入source myprojectenv/bin/activate ,您的提示应更改为

(myprojectenv)user@host:~/myproject$

Maybe your using diferent version of python python2 and python3 can have diffent versions of libraries. 也许您使用的Python版本不同python2和python3的库版本可能不同。 Try run python3 manage.py migrate 尝试运行python3 manage.py migrate

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM