[Vue + Django REST framework] before and after the end of the separation of platform development project initialization []

Project Initialization

System Environment

python 3.7.3

Django 2.2.4

DjangoRestFramework 3.10.2

 

Step one: Start the virtual environment

virtualenv virtualized environments built: https: //www.cnblogs.com/bk770466199/p/11366374.html

Step 2: Install dependent packages

# View the list of currently installed dependencies 
    PIP List
 # watercress speed up installation source Django 
    
    PIP install -i https://pypi.douban.com/ the Simple Django 
    
    although pycharm setting where you can install the dependencies, but some rely package download is too slow, with watercress source speed up installation, at the command line related packages installed inside, and then build the project in pycharm, the download package to avoid slow stuck. 

# PIP installation DRF 
    
    PIP install djangorestframework

 

The third step: pycharm build the project

 

Create a mysql database

Configuration setting, start using the database we created Django project

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': "myshop",
        'USER': "root",
        'PASSWORD': "12345678",
        'HOST': "127.0.0.1",
        "OPTIONS": {"init_command": "SET default_storage_engine=INNODB;"}
    }
}

数据库的配置从网上都可以搜到,生产环境中可以根据系统类型分别配置,使得测试环境和生产环境可以分别连接对应的数据库。

安装mysqlclient

  python连接mysql需要安装依赖包mysqlclient。

  正常使用豆瓣源加速安装会报错,如下:

  

(wText) C:\Users\zhangw>pip install -i https://pypi.douban.com/simple mysqlclient
Looking in indexes: https://pypi.douban.com/simple
Collecting mysqlclient
  Downloading https://pypi.doubanio.com/packages/4d/38/c5f8bac9c50f3042c8f05615f84206f77f03db79781db841898fde1bb284/mysqlclient-1.4.4.tar.gz (86kB)
     |████████████████████████████████| 92kB 68kB/s
Installing collected packages: mysqlclient
  Running setup.py install for mysqlclient ... error
    ERROR: Command errored out with exit status 1:
     command: 'd:\python3\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\zhangw\\AppData\\Local\\Temp\\pip-install-o3l0fmnv\\mysqlclient\\setup.py'"'"'; __file__='"'"'C:\\Users\\zhangw\\AppData\\Local\\Temp\\pip-install-o3l0fmnv\\mysqlclient\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\zhangw\AppData\Local\Temp\pip-record-6pjq9f0m\install-record.txt' --single-version-externally-managed --compile
         cwd: C:\Users\zhangw\AppData\Local\Temp\pip-install-o3l0fmnv\mysqlclient\
    Complete output (30 lines):
    running install
    running build
    running build_py
    creating build
    creating build\lib.win-amd64-3.7
    creating build\lib.win-amd64-3.7\MySQLdb
    copying MySQLdb\__init__.py -> build\lib.win-amd64-3.7\MySQLdb
    copying MySQLdb\_exceptions.py -> build\lib.win-amd64-3.7\MySQLdb
    copying MySQLdb\compat.py -> build\lib.win-amd64-3.7\MySQLdb
    copying MySQLdb\connections.py -> build\lib.win-amd64-3.7\MySQLdb
    copying MySQLdb\converters.py -> build\lib.win-amd64-3.7\MySQLdb
    copying MySQLdb\cursors.py -> build\lib.win-amd64-3.7\MySQLdb
    copying MySQLdb\release.py -> build\lib.win-amd64-3.7\MySQLdb
    copying MySQLdb\times.py -> build\lib.win-amd64-3.7\MySQLdb
    creating build\lib.win-amd64-3.7\MySQLdb\constants
    copying MySQLdb\constants\__init__.py -> build\lib.win-amd64-3.7\MySQLdb\constants
    copying MySQLdb\constants\CLIENT.py -> build\lib.win-amd64-3.7\MySQLdb\constants
    copying MySQLdb\constants\CR.py -> build\lib.win-amd64-3.7\MySQLdb\constants
    copying MySQLdb\constants\ER.py -> build\lib.win-amd64-3.7\MySQLdb\constants
    copying MySQLdb\constants\FIELD_TYPE.py -> build\lib.win-amd64-3.7\MySQLdb\constants
    copying MySQLdb\constants\FLAG.py -> build\lib.win-amd64-3.7\MySQLdb\constants
    running build_ext
    building 'MySQLdb._mysql' extension
    creating build\temp.win-amd64-3.7
    creating build\temp.win-amd64-3.7\Release
    creating build\temp.win-amd64-3.7\Release\MySQLdb
    C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -Dversion_info=(1,4,4,'final',0) -D__version__=1.4.4 "-IC:\Program Files (x86)\MySQL\MySQL Connector C 6.1\include\mariadb" -Id:\python3\include -Id:\python3\include "-IC:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\8.1\include\shared" "-IC:\Program Files (x86)\Windows Kits\8.1\include\um" "-IC:\Program Files (x86)\Windows Kits\8.1\include\winrt" /TcMySQLdb/_mysql.c /Fobuild\temp.win-amd64-3.7\Release\MySQLdb/_mysql.obj /Zl /D_CRT_SECURE_NO_WARNINGS
    _mysql.c
    MySQLdb/_mysql.c(29): fatal error C1083: Cannot open include file: 'mysql.h': No such file or directory
    error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\BIN\\x86_amd64\\cl.exe' failed with exit status 2
    ----------------------------------------
ERROR: Command errored out with exit status 1: 'd:\python3\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\zhangw\\AppData\\Local\\Temp\\pip-install-o3l0fmnv\\mysqlclient\\setup.py'"'"'; __file__='"'"'C:\\Users\\zhangw\\AppData\\Local\\Temp\\pip-install-o3l0fmnv\\mysqlclient\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\zhangw\AppData\Local\Temp\pip-record-6pjq9f0m\install-record.txt' --single-version-externally-managed --compile Check the logs for full command output.

  之前没有安装Microsoft Visual Studio 14.0的时候,是因为python3是依赖Microsoft Visual Studio 14.0解析的,需要安装Microsoft Visual Studio 14.0,安装完成之后就报这样的错,各种百度无果,祭出绝招:

  一个神奇的网站:https://www.lfd.uci.edu/~gohlke/pythonlibs/

  通过这个网站我下载了对应版本的whl文件,然后pip install,真的就不报错,成功安装。

 

 

  

Guess you like

Origin www.cnblogs.com/bk770466199/p/11370250.html