手记

Python+Django+Ansible Playbook自动化运维项目实战-迁移django3手记 一

环境:Ubuntu18,python 3.6  django 3.1


john@Vbox:~$ ls

download          PycharmProjects  模板  图片  下载  桌面

examples.desktop  公共的           视频  文档  音乐


john@Vbox:~$ hostnamectl 

   Static hostname: Vbox

         Icon name: computer-vm

           Chassis: vm

        Machine ID: b9d3a184bc8c481988f16da59cf27c32

           Boot ID: 1cd67b6c9fb64fd198a0001b15716fc0

    Virtualization: oracle

  Operating System: Ubuntu 18.04.5 LTS

            Kernel: Linux 5.4.0-42-generic

      Architecture: x86-64

john@Vbox:~$ cat /etc/hosts

127.0.0.1 localhost

127.0.1.1 john-Vbox


# The following lines are desirable for IPv6 capable hosts

::1     ip6-localhost ip6-loopback

fe00::0 ip6-localnet

ff00::0 ip6-mcastprefix

ff02::1 ip6-allnodes

ff02::2 ip6-allrouters

john@Vbox:~$ sudo -i

[sudo] john 的密码: 

root@Vbox:~# vim /etc/hosts

root@Vbox:~# ls

root@Vbox:~# pwd

/root

root@Vbox:~# ls

root@Vbox:~# ll

总用量 28

drwx------  3 root root 4096 8月  20 14:48 ./

drwxr-xr-x 24 root root 4096 8月  19 22:01 ../

-rw-------  1 root root  618 8月  20 14:47 .bash_history

-rw-r--r--  1 root root 3106 4月   9  2018 .bashrc

drwx------  2 root root 4096 8月   7 06:40 .cache/

-rw-r--r--  1 root root  148 8月  17  2015 .profile

-rw-------  1 root root  849 8月  20 14:48 .viminfo

root@Vbox:~# vim .profile 

root@Vbox:~# apt-get install python3-pip

正在读取软件包列表... 完成

正在分析软件包的依赖关系树       

正在读取状态信息... 完成       

将会同时安装下列软件:

  build-essential dh-python dpkg-dev fakeroot g++ g++-7 gcc gcc-7

  libalgorithm-diff-perl libalgorithm-diff-xs-perl libalgorithm-merge-perl

  libasan4 libatomic1 libc-dev-bin libc6-dev libcilkrts5 libexpat1-dev

  libfakeroot libgcc-7-dev libitm1 liblsan0 libmpx2 libpython3-dev

  libpython3.6-dev libquadmath0 libstdc++-7-dev libtsan0 libubsan0

  linux-libc-dev make manpages-dev python-pip-whl python3-dev

  python3-distutils python3-lib2to3 python3-setuptools python3-wheel

  python3.6-dev

建议安装:

  debian-keyring g++-multilib g++-7-multilib gcc-7-doc libstdc++6-7-dbg

  gcc-multilib autoconf automake libtool flex bison gcc-doc gcc-7-multilib

  gcc-7-locales libgcc1-dbg libgomp1-dbg libitm1-dbg libatomic1-dbg

  libasan4-dbg liblsan0-dbg libtsan0-dbg libubsan0-dbg libcilkrts5-dbg

  libmpx2-dbg libquadmath0-dbg glibc-doc libstdc++-7-doc make-doc

  python-setuptools-doc

下列【新】软件包将被安装:

  build-essential dh-python dpkg-dev fakeroot g++ g++-7 gcc gcc-7

  libalgorithm-diff-perl libalgorithm-diff-xs-perl libalgorithm-merge-perl

  libasan4 libatomic1 libc-dev-bin libc6-dev libcilkrts5 libexpat1-dev

  libfakeroot libgcc-7-dev libitm1 liblsan0 libmpx2 libpython3-dev

  libpython3.6-dev libquadmath0 libstdc++-7-dev libtsan0 libubsan0

  linux-libc-dev make manpages-dev python-pip-whl python3-dev

  python3-distutils python3-lib2to3 python3-pip python3-setuptools

  python3-wheel python3.6-dev

升级了 0 个软件包,新安装了 39 个软件包,要卸载 0 个软件包,有 8 个软件包未被升级。

需要下载 78.7 MB 的归档。

解压缩后会消耗 206 MB 的额外空间。

您希望继续执行吗? [Y/n] y


安装过程略


正在设置 python3-dev (3.6.7-1~18.04) ...

正在处理用于 man-db (2.8.3-2ubuntu0.1) 的触发器 ...

正在处理用于 libc-bin (2.27-3ubuntu1.2) 的触发器 ...

root@Vbox:~# pip3 install requests

Requirement already satisfied: requests in /usr/lib/python3/dist-packages

root@Vbox:~# python3

Python 3.6.9 (default, Jul 17 2020, 12:50:27) 

[GCC 8.4.0] on linux

Type "help", "copyright", "credits" or "license" for more information.

>>> import requests

>>> exit

Use exit() or Ctrl-D (i.e. EOF) to exit

>>> 

#安装django,默认的是3.1的最新版本,其他版本请用django==x.x

root@Vbox:~# pip3 install django

Collecting django

  Downloading https://files.pythonhosted.org/packages/2b/5a/4bd5624546912082a1bd2709d0edc0685f5c7827a278d806a20cf6adea28/Django-3.1-py3-none-any.whl (7.8MB)

    34% |███████████                     | 2.7MB 5.4kB/s eta 0:15:54Exception:



Successfully installed asgiref-3.2.10 django-3.1 sqlparse-0.3.1

root@Vbox:~# 

root@Vbox:~# 

root@Vbox:~# 

root@Vbox:~# 

#安装mysql-server

root@Vbox:~# apt-get install mysql-server

正在读取软件包列表... 完成

正在分析软件包的依赖关系树       

正在读取状态信息... 完成       

将会同时安装下列软件:

  libaio1 libevent-core-2.1-6 libhtml-template-perl mysql-client-5.7

  mysql-client-core-5.7 mysql-server-5.7 mysql-server-core-5.7

建议安装:

  libipc-sharedcache-perl mailx tinyca

下列【新】软件包将被安装:

  libaio1 libevent-core-2.1-6 libhtml-template-perl mysql-client-5.7

  mysql-client-core-5.7 mysql-server mysql-server-5.7 mysql-server-core-5.7

升级了 0 个软件包,新安装了 8 个软件包,要卸载 0 个软件包,有 8 个软件包未被升级。

需要下载 19.1 MB 的归档。

解压缩后会消耗 155 MB 的额外空间。

您希望继续执行吗? [Y/n] y

过程略


Created symlink /etc/systemd/system/multi-user.target.wants/mysql.service → /lib/systemd/system/mysql.service.

正在设置 mysql-server (5.7.31-0ubuntu0.18.04.1) ...

正在处理用于 libc-bin (2.27-3ubuntu1.2) 的触发器 ...

正在处理用于 systemd (237-3ubuntu10.42) 的触发器 ...

正在处理用于 man-db (2.8.3-2ubuntu0.1) 的触发器 ...

正在处理用于 ureadahead (0.100.0-21) 的触发器 ...


#安装MongoDB

root@Vbox:~# apt-get install mongodb

正在读取软件包列表... 完成

正在分析软件包的依赖关系树       

正在读取状态信息... 完成       

将会同时安装下列软件:

  libboost-program-options1.65.1 libgoogle-perftools4 libpcrecpp0v5

  libsnappy1v5 libtcmalloc-minimal4 libyaml-cpp0.5v5 mongo-tools

  mongodb-clients mongodb-server mongodb-server-core

下列【新】软件包将被安装:

  libboost-program-options1.65.1 libgoogle-perftools4 libpcrecpp0v5

  libsnappy1v5 libtcmalloc-minimal4 libyaml-cpp0.5v5 mongo-tools mongodb

  mongodb-clients mongodb-server mongodb-server-core

升级了 0 个软件包,新安装了 11 个软件包,要卸载 0 个软件包,有 8 个软件包未被升级。

需要下载 53.4 MB 的归档。

解压缩后会消耗 217 MB 的额外空间。

您希望继续执行吗? [Y/n] y

获取:1 http://cn.archive.ubuntu.com/ubuntu bionic/main amd64 libboost-program-options1.65.1 amd64 1.65.1+dfsg-0ubuntu5 [137 kB]


正在设置 mongodb (1:3.6.3-0ubuntu1.1) ...

正在处理用于 systemd (237-3ubuntu10.42) 的触发器 ...

正在处理用于 man-db (2.8.3-2ubuntu0.1) 的触发器 ...

正在处理用于 ureadahead (0.100.0-21) 的触发器 ...

正在处理用于 libc-bin (2.27-3ubuntu1.2) 的触发器 ...


#安装redis

root@Vbox:~# apt-get install redis

正在读取软件包列表... 完成

正在分析软件包的依赖关系树       

正在读取状态信息... 完成       

将会同时安装下列软件:

  libjemalloc1 redis-server redis-tools

建议安装:

  ruby-redis

下列【新】软件包将被安装:

  libjemalloc1 redis redis-server redis-tools

升级了 0 个软件包,新安装了 4 个软件包,要卸载 0 个软件包,有 8 个软件包未被升级。

需要下载 637 kB 的归档。

解压缩后会消耗 3,083 kB 的额外空间。

您希望继续执行吗? [Y/n] y 

获取:1 http://cn.archive.ubuntu.com/ubuntu bionic/universe amd64 libjemalloc1 amd64 3.6.0-11 [82.4 kB]

获取:2 http://cn.archive.ubuntu.com/ubuntu bionic-updates/universe amd64 redis-tools amd64 5:4.0.9-1ubuntu0.2 [516 kB]

获取:3 http://cn.archive.ubuntu.com/ubuntu bionic-updates/universe amd64 redis-server amd64 5:4.0.9-1ubuntu0.2 [35.4 kB]

获取:4 http://cn.archive.ubuntu.com/ubuntu bionic-updates/universe amd64 redis all 5:4.0.9-1ubuntu0.2 [3,084 B]

已下载 637 kB,耗时 17秒 (36.4 kB/s)                                           

正在选中未选择的软件包 libjemalloc1。

(正在读取数据库 ... 系统当前共安装有 142154 个文件和目录。)

正准备解包 .../libjemalloc1_3.6.0-11_amd64.deb  ...

正在解包 libjemalloc1 (3.6.0-11) ...

正在选中未选择的软件包 redis-tools。

正准备解包 .../redis-tools_5%3a4.0.9-1ubuntu0.2_amd64.deb  ...

正在解包 redis-tools (5:4.0.9-1ubuntu0.2) ...

正在选中未选择的软件包 redis-server。

正准备解包 .../redis-server_5%3a4.0.9-1ubuntu0.2_amd64.deb  ...

正在解包 redis-server (5:4.0.9-1ubuntu0.2) ...

正在选中未选择的软件包 redis。

正准备解包 .../redis_5%3a4.0.9-1ubuntu0.2_all.deb  ...

正在解包 redis (5:4.0.9-1ubuntu0.2) ...

正在设置 libjemalloc1 (3.6.0-11) ...

正在设置 redis-tools (5:4.0.9-1ubuntu0.2) ...

正在设置 redis-server (5:4.0.9-1ubuntu0.2) ...

Created symlink /etc/systemd/system/redis.service → /lib/systemd/system/redis-server.service.

Created symlink /etc/systemd/system/multi-user.target.wants/redis-server.service → /lib/systemd/system/redis-server.service.

正在设置 redis (5:4.0.9-1ubuntu0.2) ...

正在处理用于 libc-bin (2.27-3ubuntu1.2) 的触发器 ...

正在处理用于 systemd (237-3ubuntu10.42) 的触发器 ...

正在处理用于 man-db (2.8.3-2ubuntu0.1) 的触发器 ...

正在处理用于 ureadahead (0.100.0-21) 的触发器 ...

 

#启动测试下mongo

     

root@Vbox:~# mongo start

MongoDB shell version v3.6.3

connecting to: mongodb://127.0.0.1:27017/start

MongoDB server version: 3.6.3

Welcome to the MongoDB shell.

For interactive help, type "help".

For more comprehensive documentation, see

http://docs.mongodb.org/

Questions? Try the support group

http://groups.google.com/group/mongodb-user

Server has startup warnings: 

2020-08-20T16:20:45.618+0800 I STORAGE  [initandlisten] 

2020-08-20T16:20:45.618+0800 I STORAGE  [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine

2020-08-20T16:20:45.618+0800 I STORAGE  [initandlisten] **          See http://dochub.mongodb.org/core/prodnotes-filesystem

2020-08-20T16:20:46.292+0800 I CONTROL  [initandlisten] 

2020-08-20T16:20:46.292+0800 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.

2020-08-20T16:20:46.292+0800 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.

2020-08-20T16:20:46.292+0800 I CONTROL  [initandlisten] 

> q

2020-08-20T16:25:15.546+0800 E QUERY    [thread1] ReferenceError: q is not defined :

@(shell):1:1

> exit

bye

#使用systemctl控制服务器

root@Vbox:~# systemctl start mongodb.service 

root@Vbox:~# systemctl status  mongodb.service 

● mongodb.service - An object/document-oriented database

   Loaded: loaded (/lib/systemd/system/mongodb.service; enabled; vendor preset: 

   Active: active (running) since Thu 2020-08-20 16:20:45 CST; 4min 47s ago

     Docs: man:mongod(1)

 Main PID: 18602 (mongod)

    Tasks: 23 (limit: 2326)

   CGroup: /system.slice/mongodb.service

           └─18602 /usr/bin/mongod --unixSocketPrefix=/run/mongodb --config /etc


8月 20 16:20:45 Vbox systemd[1]: Started An object/document-oriented database.

#修改下绑定ip为 0.0.0.0

root@Vbox:~# vim /etc/mongodb.conf 

root@Vbox:~# systemctl restart  mongodb.service 


#查看是否是 0.0.0.0的绑定ip

root@Vbox:~# netstat -antlp|grep mon

tcp        0      0 0.0.0.0:27017           0.0.0.0:*               LISTEN      20325/mongod        

root@Vbox:~# netstat -anp|grep mon

tcp        0      0 0.0.0.0:27017           0.0.0.0:*               LISTEN      20325/mongod        


#启动redis 

root@Vbox:~# systemctl start redis

redis-server@         redis-server.service  redis.service

root@Vbox:~# systemctl start redis-server

redis-server@         redis-server.service  

root@Vbox:~# systemctl start redis-server.service 

root@Vbox:~# systemctl status redis-server.service 

● redis-server.service - Advanced key-value store

   Loaded: loaded (/lib/systemd/system/redis-server.service; enabled; vendor pre

   Active: active (running) since Thu 2020-08-20 16:24:27 CST; 2min 59s ago

     Docs: http://redis.io/documentation,

           man:redis-server(1)

 Main PID: 19566 (redis-server)

    Tasks: 4 (limit: 2326)

   CGroup: /system.slice/redis-server.service

           └─19566 /usr/bin/redis-server 127.0.0.1:6379


8月 20 16:24:27 Vbox systemd[1]: Starting Advanced key-value store...

8月 20 16:24:27 Vbox systemd[1]: Started Advanced key-value store.


#修改reids的绑定ip为 0.0.0.0

root@Vbox:~# vim /etc/redis/redis.conf 

root@Vbox:~# netstat -antlp |grep redis

tcp        0      0 127.0.0.1:6379          0.0.0.0:*               LISTEN      19566/redis-server  

tcp6       0      0 ::1:6379                :::*                    LISTEN      19566/redis-server  

root@Vbox:~# systemctl restart redis-server.service 

root@Vbox:~# netstat -antlp |grep redis

tcp        0      0 0.0.0.0:6379            0.0.0.0:*               LISTEN      20533/redis-server  

tcp6       0      0 ::1:6379                :::*                    LISTEN      20533/redis-server  

root@Vbox:~# redi

rediff           redis-check-aof  redis-cli        

redis-benchmark  redis-check-rdb  redis-server     

#连接 redis测试,生产

root@Vbox:~# redis-cli 

127.0.0.1:6379> help

redis-cli 4.0.9

To get help about Redis commands type:

      "help @<group>" to get a list of commands in <group>

      "help <command>" for help on <command>

      "help <tab>" to get a list of possible help topics

      "quit" to exit


127.0.0.1:6379> exit


#设置mysql的root,及清理不必要的权限及表

root@Vbox:~# mysql_secure_installation 


Securing the MySQL server deployment.


Connecting to MySQL using a blank password.


VALIDATE PASSWORD PLUGIN can be used to test passwords

and improve security. It checks the strength of password

and allows the users to set only those passwords which are

secure enough. Would you like to setup VALIDATE PASSWORD plugin?


Press y|Y for Yes, any other key for No: y


There are three levels of password validation policy:


LOW    Length >= 8

MEDIUM Length >= 8, numeric, mixed case, and special characters

STRONG Length >= 8, numeric, mixed case, special characters and dictionary                  file


Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 1

Please set the password for root here.


New password: 


Re-enter new password: 


Estimated strength of the password: 25 

Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y

By default, a MySQL installation has an anonymous user,

allowing anyone to log into MySQL without having to have

a user account created for them. This is intended only for

testing, and to make the installation go a bit smoother.

You should remove them before moving into a production

environment.


Remove anonymous users? (Press y|Y for Yes, any other key for No) : y

Success.



Normally, root should only be allowed to connect from

'localhost'. This ensures that someone cannot guess at

the root password from the network.


Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y

Success.


By default, MySQL comes with a database named 'test' that

anyone can access. This is also intended only for testing,

and should be removed before moving into a production

environment.



Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y

 - Dropping test database...

Success.


 - Removing privileges on test database...

Success.


Reloading the privilege tables will ensure that all changes

made so far will take effect immediately.


Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y

Success.


All done! 


#测试使用新密码连接

root@Vbox:~# mysql -uroot -p

Enter password: 

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 4

Server version: 5.7.31-0ubuntu0.18.04.1 (Ubuntu)


Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.


Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.


Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.


mysql> eixt

    -> q

q

^C

mysql> exit

Bye

# 将下载后的python3的项目下载下来,放到新建的/opt/code/ 下 并解压

root@Vbox:~# cd /opt/code/


root@Vbox:/opt/code# cp /home/john/download/imoocc_python3_online.tgz  .


root@Vbox:/opt/code# gunzip imoocc_python3_online.tgz 

root@Vbox:/opt/code# ls

imoocc_python3_online.tar


root@Vbox:/opt/code# file imoocc_python3_online.tar 

imoocc_python3_online.tar: POSIX tar archive

root@Vbox:/opt/code# tar -xvf imoocc_python3_online.tar ./imoocc_py3_online/

./imoocc_py3_online/

./imoocc_py3_online/taskdo/

./imoocc_py3_online/error.logs

./imoocc_py3_online/requirements.txt

./imoocc_py3_online/._admin

./imoocc_py3_online/admin/

略.......



./imoocc_py3_online/taskdo/migrations/__pycache__/__init__.cpython-36.pyc


#解压完毕后,查看内容

root@Vbox:/opt/code# ls

imoocc_py3_online  imoocc_python3_online.tar

root@Vbox:/opt/code# cd imoocc_py3_online/

root@Vbox:/opt/code/imoocc_py3_online# ls

admin  error.logs   logs       README.md         script  templates

apps   extra_apps   main.py    requirements.txt  static

conf   __init__.py  manage.py  scanhosts         taskdo

root@Vbox:/opt/code/imoocc_py3_online# cd ..

root@Vbox:/opt/code# ls

imoocc_py3_online  imoocc_python3_online.tar

root@Vbox:/opt/code# mv imoocc_py

imoocc_py3_online/         imoocc_python3_online.tar  


#为了跟视频的名称一样,我修改了下文件夹名称为 imoocc

root@Vbox:/opt/code# mv imoocc_py3_online/ imoocc

root@Vbox:/opt/code# ll

总用量 9672

drwxr-xr-x  3 root root     4096 8月  20 17:25 ./

drwxr-xr-x  3 root root     4096 8月  20 17:21 ../

drwxr-xr-x 13  501 staff    4096 4月  19  2018 imoocc/

-rw-r--r--  1 root root  9891840 8月  20 17:22 imoocc_python3_online.tar

root@Vbox:/opt/code# cd imoocc/

root@Vbox:/opt/code/imoocc# 

root@Vbox:/opt/code/imoocc# vim admin/

__init__.py   __init__.pyc  __pycache__/  settings/     urls.py       urls.pyc      wsgi.py       wsgi.pyc    

#修改下  数据库的配置信息,包括mysql的,mongo,redis的配置也在这里

#修改数据库名称,用户名密码端口等。


root@Vbox:/opt/code/imoocc# vim admin/settings/settings.py


#修改mysqld 的字符集

root@Vbox:/opt/code/imoocc# vim /etc/mysql/my.cnf


#添加如下内容

[client]

default-character-set=utf8


[mysqld]

character-set-server=utf8

collation-server=utf8_general_ci



#重启数据库

root@Vbox:/opt/code/imoocc# systemctl restart mysql.service 



root@Vbox:/opt/code/imoocc# mysql -uroot -p

Enter password: 

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 3

Server version: 5.7.31-0ubuntu0.18.04.1 (Ubuntu)


Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.


Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.


Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.


mysql> ls

    -> ;

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ls' at line 1

mysql> 

mysql> create database imoocc;

Query OK, 1 row affected (0.00 sec)



mysql>  grant all on imoocc.* to imoocc@'127.0.0.1' identified by '123456';

Query OK, 0 rows affected, 1 warning (0.00 sec)


mysql> exit


#使用新用户登陆测试

root@Vbox:/opt/code/imoocc# mysql -u imoocc -p -h 127.0.0.1

Enter password: 

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 9

Server version: 5.7.31-0ubuntu0.18.04.1 (Ubuntu)


Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.


Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.


Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.


mysql> exit

Bye


#执行迁移:原则是发现啥错误,改啥错误,没啥模块,装啥模块。

root@Vbox:/opt/code/imoocc# python3 manage.py makemigrations

Traceback (most recent call last):

  File "/usr/local/lib/python3.6/dist-packages/django/core/management/base.py", line 330, in run_from_argv

 

  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed

  File "/opt/code/imoocc/admin/__init__.py", line 1, in <module>

    import pymysql

ModuleNotFoundError: No module named 'pymysql'


ModuleNotFoundError: No module named 'pymysql'

root@Vbox:/opt/code/imoocc# pip3 install pymysql

Collecting pymysql





  Could not find a version that satisfies the requirement pymysql (from versions: )

No matching distribution found for pymysql


root@Vbox:/opt/code/imoocc# 

#装pymysql,这个版本很低,导致后面有个判断直接读这个版本

root@Vbox:/opt/code/imoocc# pip3 install pymysql

Collecting pymysql

  Downloading https://files.pythonhosted.org/packages/2c/57/af502e0e113f139b3f3add4f1efba899a730a365d2264d476e85b9591da5/PyMySQL-0.10.0-py2.py3-none-any.whl (47kB)

    100% |████████████████████████████████| 51kB 3.8kB/s 

Installing collected packages: pymysql

Successfully installed pymysql-0.10.0

root@Vbox:/opt/code/imoocc# 


root@Vbox:/opt/code/imoocc# python3 manage.py makemigrations

Traceback (most recent call last):

  File "manage.py", line 15, in <module>

    execute_from_command_line(sys.argv)

  File "/usr/local/lib/python3.6/dist-packages/django/core/management/__init__.py", line 401, in execute_from_command_line

    utility.execute()

  File "/usr/local/lib/python3.6/dist-packages/django/core/management/__init__.py", line 377, in execute

    django.setup()

  File "/usr/local/lib/python3.6/dist-packages/django/__init__.py", line 24, in setup

    apps.populate(settings.INSTALLED_APPS)

  File "/usr/local/lib/python3.6/dist-packages/django/apps/registry.py", line 91, in populate

    app_config = AppConfig.create(entry)

  File "/usr/local/lib/python3.6/dist-packages/django/apps/config.py", line 90, in create

    module = import_module(entry)

  File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module

    return _bootstrap._gcd_import(name[level:], package, level)

  File "<frozen importlib._bootstrap>", line 994, in _gcd_import

  File "<frozen importlib._bootstrap>", line 971, in _find_and_load

  File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked

ModuleNotFoundError: No module named 'django_crontab'

#装 django_crontab

root@Vbox:/opt/code/imoocc# pip3 install django_crontab

Collecting django_crontab

  Downloading https://files.pythonhosted.org/packages/37/bd/a122ba96167f5dfab70a58ca22fa046b7ef1ebad9ff026f7831bd6c2a49c/django-crontab-0.7.1.tar.gz

Requirement already satisfied: Django>=1.8 in /usr/local/lib/python3.6/dist-packages (from django_crontab)

Requirement already satisfied: sqlparse>=0.2.2 in /usr/local/lib/python3.6/dist-packages (from Django>=1.8->django_crontab)

Requirement already satisfied: pytz in /usr/lib/python3/dist-packages (from Django>=1.8->django_crontab)

Requirement already satisfied: asgiref~=3.2.10 in /usr/local/lib/python3.6/dist-packages (from Django>=1.8->django_crontab)

Building wheels for collected packages: django-crontab

  Running setup.py bdist_wheel for django-crontab ... done

  Stored in directory: /root/.cache/pip/wheels/24/f9/cc/62f87c4bc00383af995adc4a870e4d74cc1d632a172e548679

Successfully built django-crontab

Installing collected packages: django-crontab

Successfully installed django-crontab-0.7.1

root@Vbox:/opt/code/imoocc# python3 manage.py makemigrations

Traceback (most recent call last):

  File "manage.py", line 15, in <module>

    execute_from_command_line(sys.argv)

  File "/usr/local/lib/python3.6/dist-packages/django/core/management/__init__.py", line 401, in execute_from_command_line

    utility.execute()

  File "/usr/local/lib/python3.6/dist-packages/django/core/management/__init__.py", line 377, in execute

    django.setup()

  File "/usr/local/lib/python3.6/dist-packages/django/__init__.py", line 24, in setup

    apps.populate(settings.INSTALLED_APPS)

  File "/usr/local/lib/python3.6/dist-packages/django/apps/registry.py", line 91, in populate

    app_config = AppConfig.create(entry)

  File "/usr/local/lib/python3.6/dist-packages/django/apps/config.py", line 90, in create

    module = import_module(entry)

  File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module

    return _bootstrap._gcd_import(name[level:], package, level)

  File "<frozen importlib._bootstrap>", line 994, in _gcd_import

  File "<frozen importlib._bootstrap>", line 971, in _find_and_load

  File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked

ModuleNotFoundError: No module named 'crispy_forms'


装 crispy_forms,但是名称不是这个,提示找不到,应该是django-crispy-forms

root@Vbox:/opt/code/imoocc# pip3 install crispy_forms

Collecting crispy_forms

Exception:

Traceback (most recent call last):

  File "/usr/lib/python3/dist-packages/pip/basecommand.py", line 215, in main


root@Vbox:/opt/code/imoocc# pip3 install django-crispy-forms

Collecting django-crispy-forms

  Downloading https://files.pythonhosted.org/packages/37/04/06760b426a3dd7eb3e43ed7bcb9d085670c1e60453f4abd56357c4f187ce/django_crispy_forms-1.9.2-py3-none-any.whl (108kB)

    100% |████████████████████████████████| 112kB 4.0kB/s 

Installing collected packages: django-crispy-forms

Successfully installed django-crispy-forms-1.9.2

root@Vbox:/opt/code/imoocc# python3 manage.py makemigrations

Traceback (most recent call last):

  File "manage.py", line 15, in <module>

    execute_from_command_line(sys.argv)

  File "/usr/local/lib/python3.6/dist-packages/django/core/management/__init__.py", line 401, in execute_from_command_line

    utility.execute()

  File "/usr/local/lib/python3.6/dist-packages/django/core/management/__init__.py", line 377, in execute

    django.setup()

  File "/usr/local/lib/python3.6/dist-packages/django/__init__.py", line 24, in setup

    apps.populate(settings.INSTALLED_APPS)

  File "/usr/local/lib/python3.6/dist-packages/django/apps/registry.py", line 114, in populate

    app_config.import_models()

  File "/usr/local/lib/python3.6/dist-packages/django/apps/config.py", line 211, in import_models

    self.models_module = import_module(models_module_name)

  File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module

    return _bootstrap._gcd_import(name[level:], package, level)

  File "<frozen importlib._bootstrap>", line 994, in _gcd_import

  File "<frozen importlib._bootstrap>", line 971, in _find_and_load

  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked

  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked

  File "<frozen importlib._bootstrap_external>", line 678, in exec_module

  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed

  File "/usr/local/lib/python3.6/dist-packages/django/contrib/auth/models.py", line 2, in <module>

    from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager

  File "/usr/local/lib/python3.6/dist-packages/django/contrib/auth/base_user.py", line 48, in <module>

    class AbstractBaseUser(models.Model):

  File "/usr/local/lib/python3.6/dist-packages/django/db/models/base.py", line 122, in __new__

    new_class.add_to_class('_meta', Options(meta, app_label))

  File "/usr/local/lib/python3.6/dist-packages/django/db/models/base.py", line 326, in add_to_class

    value.contribute_to_class(cls, name)

  File "/usr/local/lib/python3.6/dist-packages/django/db/models/options.py", line 206, in contribute_to_class

    self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())

  File "/usr/local/lib/python3.6/dist-packages/django/db/__init__.py", line 28, in __getattr__

    return getattr(connections[DEFAULT_DB_ALIAS], item)

  File "/usr/local/lib/python3.6/dist-packages/django/db/utils.py", line 214, in __getitem__

    backend = load_backend(db['ENGINE'])

  File "/usr/local/lib/python3.6/dist-packages/django/db/utils.py", line 111, in load_backend

    return import_module('%s.base' % backend_name)

  File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module

    return _bootstrap._gcd_import(name[level:], package, level)

  File "/usr/local/lib/python3.6/dist-packages/django/db/backends/mysql/base.py", line 36, in <module>

    raise ImproperlyConfigured('mysqlclient 1.4.0 or newer is required; you have %s.' % Database.__version__)

django.core.exceptions.ImproperlyConfigured: mysqlclient 1.4.0 or newer is required; you have 0.10.0.


#就是这个mysqlclient版本,总是读的pymysql中的mysqlclient的版本,是0.10.0,后续装了几个模块,都没搞定,只能屏蔽对应的代码绕过了

root@Vbox:/opt/code/imoocc# 

root@Vbox:/opt/code/imoocc# pip3 install pymysql

Requirement already satisfied: pymysql in /usr/local/lib/python3.6/dist-packages

root@Vbox:/opt/code/imoocc# python3

Python 3.6.9 (default, Jul 17 2020, 12:50:27) 

[GCC 8.4.0] on linux

Type "help", "copyright", "credits" or "license" for more information.

>>> import pymysql

>>> dir()

['__annotations__', '__builtins__', '__doc__', '__loader__', '__name__', '__package__', '__spec__', 'pymysql']

>>> dir(pymysql)

['BINARY', 'Binary', 'Connect', 'Connection', 'DATE', 'DATETIME', 'DBAPISet', 'DataError', 'DatabaseError', 'Date', 'DateFromTicks', 'Error', 'FIELD_TYPE', 'IntegrityError', 'InterfaceError', 'InternalError', 'MySQLError', 'NULL', 'NUMBER', 'NotSupportedError', 'OperationalError', 'PY2', 'ProgrammingError', 'ROWID', 'STRING', 'TIME', 'TIMESTAMP', 'Time', 'TimeFromTicks', 'Timestamp', 'TimestampFromTicks', 'VERSION', 'VERSION_STRING', 'Warning', '__all__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__', '__version__', '_auth', '_compat', 'apilevel', 'charset', 'connect', 'connections', 'constants', 'converters', 'cursors', 'err', 'escape_dict', 'escape_sequence', 'escape_string', 'get_client_info', 'install_as_MySQLdb', 'optionfile', 'paramstyle', 'protocol', 'sys', 'thread_safe', 'threadsafety', 'times', 'util', 'version_info']

>>> pymysql.version_info

(1, 3, 13, 'final', 0)

>>> exit

Use exit() or Ctrl-D (i.e. EOF) to exit

>>> 



#安装了MySQL-python尝试

root@Vbox:/opt/code/imoocc# pip3 install MySQL-python

Collecting MySQL-python

  Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ReadTimeoutError("HTTPSConnectionPool(host='pypi.python.org', port=443): Read timed out. (read timeout=15)",)': /simple/mysql-python/

  Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ReadTimeoutError("HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Read timed out. (read timeout=15)",)': /packages/a5/e9/51b544da85a36a68debe7a7091f068d802fc515a3a202652828c73453cad/MySQL-python-1.2.5.zip

  Downloading https://files.pythonhosted.org/packages/a5/e9/51b544da85a36a68debe7a7091f068d802fc515a3a202652828c73453cad/MySQL-python-1.2.5.zip (108kB)

    100% |████████████████████████████████| 112kB 4.2kB/s 

    Complete output from command python setup.py egg_info:

    Traceback (most recent call last):

      File "<string>", line 1, in <module>

      File "/tmp/pip-build-k_73p2c0/MySQL-python/setup.py", line 13, in <module>

        from setup_posix import get_config

      File "/tmp/pip-build-k_73p2c0/MySQL-python/setup_posix.py", line 2, in <module>

        from ConfigParser import SafeConfigParser

    ModuleNotFoundError: No module named 'ConfigParser'

    

    ----------------------------------------

Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-k_73p2c0/MySQL-python/

#安装了mysqlclient尝试

root@Vbox:/opt/code/imoocc# pip3 install mysqlclient

Collecting mysqlclient

  Downloading https://files.pythonhosted.org/packages/a5/e1/e5f2b231c05dc51d9d87fa5066f90d1405345c54b14b0b11a1c859020f21/mysqlclient-2.0.1.tar.gz (87kB)

    100% |████████████████████████████████| 92kB 2.2kB/s 

    Complete output from command python setup.py egg_info:

    /bin/sh: 1: mysql_config: not found

    /bin/sh: 1: mariadb_config: not found

    /bin/sh: 1: mysql_config: not found

    Traceback (most recent call last):

      File "<string>", line 1, in <module>

      File "/tmp/pip-build-g13d2uh6/mysqlclient/setup.py", line 15, in <module>

        metadata, options = get_config()

      File "/tmp/pip-build-g13d2uh6/mysqlclient/setup_posix.py", line 65, in get_config

        libs = mysql_config("libs")

      File "/tmp/pip-build-g13d2uh6/mysqlclient/setup_posix.py", line 31, in mysql_config

        raise OSError("{} not found".format(_mysql_config_path))

    OSError: mysql_config not found

    

    ----------------------------------------

Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-g13d2uh6/mysqlclient/


#安装软件包尝试

root@Vbox:/opt/code/imoocc# apt-get install mysql-devel

正在读取软件包列表... 完成

正在分析软件包的依赖关系树       

正在读取状态信息... 完成       

E: 无法定位软件包 mysql-devel

root@Vbox:/opt/code/imoocc# apt-get install libmysqlclient-dev

正在读取软件包列表... 完成

正在分析软件包的依赖关系树       

正在读取状态信息... 完成       

将会同时安装下列软件:

  libssl-dev zlib1g-dev

建议安装:

  libssl-doc

下列【新】软件包将被安装:

  libmysqlclient-dev libssl-dev zlib1g-dev

升级了 0 个软件包,新安装了 3 个软件包,要卸载 0 个软件包,有 8 个软件包未被升级。

需要下载 2,733 kB 的归档。

解压缩后会消耗 14.3 MB 的额外空间。

您希望继续执行吗? [Y/n] y

获取:1 http://cn.archive.ubuntu.com/ubuntu bionic-updates/main amd64 libssl-dev amd64 1.1.1-1ubuntu2.1~18.04.6 [1,566 kB]

获取:1 http://cn.archive.ubuntu.com/ubuntu bionic-updates/main amd64 libssl-dev amd64 1.1.1-1ubuntu2.1~18.04.6 [1,566 kB]                  

获取:1 http://cn.archive.ubuntu.com/ubuntu bionic-updates/main amd64 libssl-dev amd64 1.1.1-1ubuntu2.1~18.04.6 [1,566 kB]                  

获取:1 http://cn.archive.ubuntu.com/ubuntu bionic-updates/main amd64 libssl-dev amd64 1.1.1-1ubuntu2.1~18.04.6 [1,566 kB]                  

获取:1 http://cn.archive.ubuntu.com/ubuntu bionic-updates/main amd64 libssl-dev amd64 1.1.1-1ubuntu2.1~18.04.6 [1,566 kB]                  

获取:1 http://cn.archive.ubuntu.com/ubuntu bionic-updates/main amd64 libssl-dev amd64 1.1.1-1ubuntu2.1~18.04.6 [1,566 kB]                  

获取:2 http://cn.archive.ubuntu.com/ubuntu bionic/main amd64 zlib1g-dev amd64 1:1.2.11.dfsg-0ubuntu2 [176 kB]                              

获取:3 http://cn.archive.ubuntu.com/ubuntu bionic-updates/main amd64 libmysqlclient-dev amd64 5.7.31-0ubuntu0.18.04.1 [992 kB]             

获取:3 http://cn.archive.ubuntu.com/ubuntu bionic-updates/main amd64 libmysqlclient-dev amd64 5.7.31-0ubuntu0.18.04.1 [992 kB]             

已下载 1,532 kB,耗时 6分 1秒 (4,245 B/s)    

正在选中未选择的软件包 libssl-dev:amd64。

(正在读取数据库 ... 系统当前共安装有 142200 个文件和目录。)

正准备解包 .../libssl-dev_1.1.1-1ubuntu2.1~18.04.6_amd64.deb  ...

正在解包 libssl-dev:amd64 (1.1.1-1ubuntu2.1~18.04.6) ...

正在选中未选择的软件包 zlib1g-dev:amd64。

正准备解包 .../zlib1g-dev_1%3a1.2.11.dfsg-0ubuntu2_amd64.deb  ...

正在解包 zlib1g-dev:amd64 (1:1.2.11.dfsg-0ubuntu2) ...

正在选中未选择的软件包 libmysqlclient-dev。

正准备解包 .../libmysqlclient-dev_5.7.31-0ubuntu0.18.04.1_amd64.deb  ...

正在解包 libmysqlclient-dev (5.7.31-0ubuntu0.18.04.1) ...

正在设置 libssl-dev:amd64 (1.1.1-1ubuntu2.1~18.04.6) ...

正在设置 zlib1g-dev:amd64 (1:1.2.11.dfsg-0ubuntu2) ...

正在设置 libmysqlclient-dev (5.7.31-0ubuntu0.18.04.1) ...

正在处理用于 man-db (2.8.3-2ubuntu0.1) 的触发器 ...


root@Vbox:/opt/code/imoocc# python3 manage.py makemigrations

Traceback (most recent call last):

  File "manage.py", line 15, in <module>

    execute_from_command_line(sys.argv)

  File "/usr/local/lib/python3.6/dist-packages/django/core/management/__init__.py", line 401, in execute_from_command_line

    utility.execute()

  File "/usr/local/lib/python3.6/dist-packages/django/core/management/__init__.py", line 377, in execute

    django.setup()

  File "/usr/local/lib/python3.6/dist-packages/django/__init__.py", line 24, in setup

    apps.populate(settings.INSTALLED_APPS)

  File "/usr/local/lib/python3.6/dist-packages/django/apps/registry.py", line 114, in populate

    app_config.import_models()

  File "/usr/local/lib/python3.6/dist-packages/django/apps/config.py", line 211, in import_models

    self.models_module = import_module(models_module_name)

  File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module

    return _bootstrap._gcd_import(name[level:], package, level)

  File "<frozen importlib._bootstrap>", line 994, in _gcd_import

  File "<frozen importlib._bootstrap>", line 971, in _find_and_load

  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked

  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked

  File "<frozen importlib._bootstrap_external>", line 678, in exec_module

  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed

  File "/usr/local/lib/python3.6/dist-packages/django/contrib/auth/models.py", line 2, in <module>

    from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager

  File "/usr/local/lib/python3.6/dist-packages/django/contrib/auth/base_user.py", line 48, in <module>

    class AbstractBaseUser(models.Model):

  File "/usr/local/lib/python3.6/dist-packages/django/db/models/base.py", line 122, in __new__

    new_class.add_to_class('_meta', Options(meta, app_label))

  File "/usr/local/lib/python3.6/dist-packages/django/db/models/base.py", line 326, in add_to_class

    value.contribute_to_class(cls, name)

  File "/usr/local/lib/python3.6/dist-packages/django/db/models/options.py", line 206, in contribute_to_class

    self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())

  File "/usr/local/lib/python3.6/dist-packages/django/db/__init__.py", line 28, in __getattr__

    return getattr(connections[DEFAULT_DB_ALIAS], item)

  File "/usr/local/lib/python3.6/dist-packages/django/db/utils.py", line 214, in __getitem__

    backend = load_backend(db['ENGINE'])

  File "/usr/local/lib/python3.6/dist-packages/django/db/utils.py", line 111, in load_backend

    return import_module('%s.base' % backend_name)

  File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module

    return _bootstrap._gcd_import(name[level:], package, level)

  File "/usr/local/lib/python3.6/dist-packages/django/db/backends/mysql/base.py", line 36, in <module>

    raise ImproperlyConfigured('mysqlclient 1.4.0 or newer is required; you have %s.' % Database.__version__)

django.core.exceptions.ImproperlyConfigured: mysqlclient 1.4.0 or newer is required; you have 0.10.0.

root@Vbox:/opt/code/imoocc# vim /usr/local/lib/python3.6/dist-packages/django/db/backends/mysql/base.py


0人推荐
随时随地看视频
慕课网APP