• Mac os下Python3安装Django


    1.查看pip版本 没有的话就是没安装成功 安装python的时候一般会自动安装pip

    //pip版本 
    pip -V //对应python2.7
    pip 9.0.1 from /Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg (python 2.7)
    
    pip3 -V //对应python3.6
    pip 9.0.1 from /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (python 3.6)

    2.用pip3/Python3安装Django,1.11.7是最新稳定版(官网download页面有 https://www.djangoproject.com/download )
    这里注意用sudo 不然会报错

    sudo pip3 install Django==1.11.7

    提示 :

    Installing collected packages: Django
    Found existing installation: Django 2.1.dev20171130142844 //之前用github下载安装的最新版,2.x 版本太高
    Uninstalling Django-2.1.dev20171130142844:
    Successfully uninstalled Django-2.1.dev20171130142844 //自动卸载掉之前的版本
    Successfully installed Django-1.11.7 //安装成功

    3.测试是否安装成功

    cd /Users/z/PyP/Django

    4.新建一个服务

    sudo django-admin.py startproject testLocalHost
    
    cd testLocalHost

    5.运行服务,因为是用pip3/python3安装的Django 所以应该用python3来运行

    python3 manage.py runserver
    ...xxx
    .....xxx
    django.db.utils.OperationalError: unable to open database file

    报错了。

    6.改用管理员权限运行:

    sudo python3 manage.py runserver


    打印:

    Performing system checks...
    
    System check identified no issues (0 silenced).
    
    You have 13 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
    Run 'python manage.py migrate' to apply them.
    
    December 01, 2017 - 08:33:50
    Django version 1.11.7, using settings 'testLocalHost.settings'
    Starting development server at http://127.0.0.1:8000/
    Quit the server with CONTROL-C.

    成功,浏览器输入http://127.0.0.1:8000/可以看到


    查看Django版本

    import django
    
    print(django.VERSION)

    打印:(1, 11, 7, 'final', 0) 说明是1.11.7版本。

    查看python3安装目录

    import sys
    
    print(sys.path)

    打印xxxxxx /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6 xxxx 即是python3安装目录

    pip3 安装目录:/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pip

    pip 安装目录在默认python目录下

    Django安装目录(用pip3安装) :/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django

  • 相关阅读:
    git的冲突解决--git rebase之abort、continue、skip
    iOS 13苹果登录
    mac上python3.x安装 图文详解
    iOS Bezier曲线
    《从零开始学Swift》学习笔记(Day 23)——尾随闭包
    《从零开始学Swift》学习笔记(Day 22)——闭包那些事儿!
    《从零开始学Swift》学习笔记(Day 21)——函数返回值
    《从零开始学Swift》学习笔记(Day 20)——函数中参数的传递引用
    《从零开始学Swift》学习笔记(Day 19)——函数参数传递
    《从零开始学Swift》学习笔记(Day 18)——有几个分支语句?
  • 原文地址:https://www.cnblogs.com/6324/p/7943560.html
Copyright © 2020-2023  润新知