Python3:ModuleNotFoundError: No module named ‘_sqlite3’
在Python3运行Django的时候,遇到了如题所示的错误,具体如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
[root@mysql1 project_2]# tree ../project_2/ ../project_2/ ├── django_02 │ ├── asgi.py │ ├── __init__.py │ ├── __pycache__ │ │ ├── __init__.cpython-39.pyc │ │ ├── settings.cpython-39.pyc │ │ └── urls.cpython-39.pyc │ ├── settings.py │ ├── urls.py │ └── wsgi.py └── manage.py 2 directories, 9 files [root@mysql1 project_2]# [root@mysql1 project_2]# ls -ltr total 4 -rwxr-xr-x 1 root root 665 Mar 4 05:32 manage.py drwxr-xr-x 3 root root 108 Mar 4 06:39 django_02 [root@mysql1 project_2]# [root@mysql1 project_2]# python3 manage.py runserver Watching for file changes with StatReloader Exception in thread django-main-thread: Traceback (most recent call last): File "/usr/local/python/Python-3.9.2/lib/python3.9/threading.py", line 954, in _bootstrap_inner self.run() File "/usr/local/python/Python-3.9.2/lib/python3.9/threading.py", line 892, in run self._target(*self._args, **self._kwargs) File "/usr/local/python/Python-3.9.2/lib/python3.9/site-packages/django/utils/autoreload.py", line 53, in wrapper fn(*args, **kwargs) File "/usr/local/python/Python-3.9.2/lib/python3.9/site-packages/django/core/management/commands/runserver.py", line 110, in inner_run autoreload.raise_last_exception() File "/usr/local/python/Python-3.9.2/lib/python3.9/site-packages/django/utils/autoreload.py", line 76, in raise_last_exception raise _exception[1] File "/usr/local/python/Python-3.9.2/lib/python3.9/site-packages/django/core/management/__init__.py", line 357, in execute autoreload.check_errors(django.setup)() File "/usr/local/python/Python-3.9.2/lib/python3.9/site-packages/django/utils/autoreload.py", line 53, in wrapper fn(*args, **kwargs) File "/usr/local/python/Python-3.9.2/lib/python3.9/site-packages/django/__init__.py", line 24, in setup apps.populate(settings.INSTALLED_APPS) File "/usr/local/python/Python-3.9.2/lib/python3.9/site-packages/django/apps/registry.py", line 114, in populate app_config.import_models() File "/usr/local/python/Python-3.9.2/lib/python3.9/site-packages/django/apps/config.py", line 211, in import_models self.models_module = import_module(models_module_name) File "/usr/local/python/Python-3.9.2/lib/python3.9/importlib/__init__.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "<frozen importlib._bootstrap>", line 1030, in _gcd_import File "<frozen importlib._bootstrap>", line 1007, in _find_and_load File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 680, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 790, in exec_module File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed File "/usr/local/python/Python-3.9.2/lib/python3.9/site-packages/django/contrib/auth/models.py", line 2, in <module> from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager File "/usr/local/python/Python-3.9.2/lib/python3.9/site-packages/django/contrib/auth/base_user.py", line 48, in <module> class AbstractBaseUser(models.Model): File "/usr/local/python/Python-3.9.2/lib/python3.9/site-packages/django/db/models/base.py", line 122, in __new__ new_class.add_to_class('_meta', Options(meta, app_label)) File "/usr/local/python/Python-3.9.2/lib/python3.9/site-packages/django/db/models/base.py", line 326, in add_to_class value.contribute_to_class(cls, name) File "/usr/local/python/Python-3.9.2/lib/python3.9/site-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/python/Python-3.9.2/lib/python3.9/site-packages/django/db/__init__.py", line 28, in __getattr__ return getattr(connections[DEFAULT_DB_ALIAS], item) File "/usr/local/python/Python-3.9.2/lib/python3.9/site-packages/django/db/utils.py", line 214, in __getitem__ backend = load_backend(db['ENGINE']) File "/usr/local/python/Python-3.9.2/lib/python3.9/site-packages/django/db/utils.py", line 111, in load_backend return import_module('%s.base' % backend_name) File "/usr/local/python/Python-3.9.2/lib/python3.9/importlib/__init__.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "/usr/local/python/Python-3.9.2/lib/python3.9/site-packages/django/db/backends/sqlite3/base.py", line 14, in <module> from sqlite3 import dbapi2 as Database File "/usr/local/python/Python-3.9.2/lib/python3.9/sqlite3/__init__.py", line 23, in <module> from sqlite3.dbapi2 import * File "/usr/local/python/Python-3.9.2/lib/python3.9/sqlite3/dbapi2.py", line 27, in <module> from _sqlite3 import * ModuleNotFoundError: No module named '_sqlite3' |
首先,查看下系统上有没有【_sqlite3】
1 2 3 |
[root@mysql1 project_2]# find / -name _sqlite3.so /usr/lib64/python2.7/lib-dynload/_sqlite3.so [root@mysql1 project_2]# |
可以看到:是有的。
看看Python3的系统路径:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
[root@mysql1 project_2]# python3 -V Python 3.9.2 [root@mysql1 project_2]# [root@mysql1 project_2]# python3 Python 3.9.2 (default, Mar 4 2021, 04:05:24) [GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux Type "help", "copyright", "credits" or "license" for more information. >>> >>> import sys >>> >>> sys.path ['', '/usr/local/python/Python-3.9.2/lib/python39.zip', '/usr/local/python/Python-3.9.2/lib/python3.9', '/usr/local/python/Python-3.9.2/lib/python3.9/lib-dynload', '/usr/local/python/Python-3.9.2/lib/python3.9/site-packages'] >>> >>> exit() [root@mysql1 project_2]# |
可以看到Python3也有目录:lib-dynload,而这个路径下是没有【_sqlite3.so】:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
[root@mysql1 project_2]# ls -ltr /usr/local/python/Python-3.9.2/lib/python3.9/lib-dynload total 12600 -rwxr-xr-x 1 root root 201816 Mar 4 04:00 _struct.cpython-39-x86_64-linux-gnu.so -rwxr-xr-x 1 root root 265768 Mar 4 04:00 math.cpython-39-x86_64-linux-gnu.so -rwxr-xr-x 1 root root 19432 Mar 4 04:00 _contextvars.cpython-39-x86_64-linux-gnu.so -rwxr-xr-x 1 root root 206232 Mar 4 04:00 array.cpython-39-x86_64-linux-gnu.so -rwxr-xr-x 1 root root 133816 Mar 4 04:00 cmath.cpython-39-x86_64-linux-gnu.so -rwxr-xr-x 1 root root 549840 Mar 4 04:00 _datetime.cpython-39-x86_64-linux-gnu.so -rwxr-xr-x 1 root root 136200 Mar 4 04:00 _zoneinfo.cpython-39-x86_64-linux-gnu.so -rwxr-xr-x 1 root root 60224 Mar 4 04:00 _random.cpython-39-x86_64-linux-gnu.so -rwxr-xr-x 1 root root 56000 Mar 4 04:00 _heapq.cpython-39-x86_64-linux-gnu.so -rwxr-xr-x 1 root root 46008 Mar 4 04:00 _bisect.cpython-39-x86_64-linux-gnu.so -rwxr-xr-x 1 root root 551784 Mar 4 04:00 _pickle.cpython-39-x86_64-linux-gnu.so -rwxr-xr-x 1 root root 71576 Mar 4 04:00 _lsprof.cpython-39-x86_64-linux-gnu.so -rwxr-xr-x 1 root root 178624 Mar 4 04:00 _json.cpython-39-x86_64-linux-gnu.so -rwxr-xr-x 1 root root 1197960 Mar 4 04:00 unicodedata.cpython-39-x86_64-linux-gnu.so -rwxr-xr-x 1 root root 26288 Mar 4 04:00 _opcode.cpython-39-x86_64-linux-gnu.so -rwxr-xr-x 1 root root 25816 Mar 4 04:00 _statistics.cpython-39-x86_64-linux-gnu.so -rwxr-xr-x 1 root root 32224 Mar 4 04:00 spwd.cpython-39-x86_64-linux-gnu.so -rwxr-xr-x 1 root root 113936 Mar 4 04:00 select.cpython-39-x86_64-linux-gnu.so -rwxr-xr-x 1 root root 44168 Mar 4 04:00 _queue.cpython-39-x86_64-linux-gnu.so -rwxr-xr-x 1 root root 94432 Mar 4 04:00 parser.cpython-39-x86_64-linux-gnu.so -rwxr-xr-x 1 root root 51328 Mar 4 04:00 grp.cpython-39-x86_64-linux-gnu.so -rwxr-xr-x 1 root root 52888 Mar 4 04:00 fcntl.cpython-39-x86_64-linux-gnu.so -rwxr-xr-x 1 root root 292448 Mar 4 04:00 _asyncio.cpython-39-x86_64-linux-gnu.so -rwxr-xr-x 1 root root 144424 Mar 4 04:00 _xxsubinterpreters.cpython-39-x86_64-linux-gnu.so -rwxr-xr-x 1 root root 32904 Mar 4 04:00 syslog.cpython-39-x86_64-linux-gnu.so -rwxr-xr-x 1 root root 97496 Mar 4 04:00 mmap.cpython-39-x86_64-linux-gnu.so -rwxr-xr-x 1 root root 76848 Mar 4 04:00 _posixsubprocess.cpython-39-x86_64-linux-gnu.so -rwxr-xr-x 1 root root 130808 Mar 4 04:00 _csv.cpython-39-x86_64-linux-gnu.so -rwxr-xr-x 1 root root 195152 Mar 4 04:00 audioop.cpython-39-x86_64-linux-gnu.so -rwxr-xr-x 1 root root 31024 Mar 4 04:00 _testinternalcapi.cpython-39-x86_64-linux-gnu.so -rwxr-xr-x 1 root root 17192 Mar 4 04:00 _testimportmultiple.cpython-39-x86_64-linux-gnu.so -rwxr-xr-x 1 root root 431840 Mar 4 04:00 _testcapi.cpython-39-x86_64-linux-gnu.so -rwxr-xr-x 1 root root 153840 Mar 4 04:00 _testbuffer.cpython-39-x86_64-linux-gnu.so -rwxr-xr-x 1 root root 65944 Mar 4 04:00 _xxtestfuzz.cpython-39-x86_64-linux-gnu.so -rwxr-xr-x 1 root root 65704 Mar 4 04:00 _testmultiphase.cpython-39-x86_64-linux-gnu.so -rwxr-xr-x 1 root root 24792 Mar 4 04:00 _crypt.cpython-39-x86_64-linux-gnu.so -rwxr-xr-x 1 root root 484192 Mar 4 04:00 _ssl.cpython-39-x86_64-linux-gnu.so -rwxr-xr-x 1 root root 367768 Mar 4 04:00 _socket.cpython-39-x86_64-linux-gnu.so -rwxr-xr-x 1 root root 77368 Mar 4 04:00 _sha512.cpython-39-x86_64-linux-gnu.so -rwxr-xr-x 1 root root 73840 Mar 4 04:00 _sha256.cpython-39-x86_64-linux-gnu.so -rwxr-xr-x 1 root root 40640 Mar 4 04:00 _sha1.cpython-39-x86_64-linux-gnu.so -rwxr-xr-x 1 root root 49840 Mar 4 04:00 _md5.cpython-39-x86_64-linux-gnu.so -rwxr-xr-x 1 root root 166376 Mar 4 04:00 _hashlib.cpython-39-x86_64-linux-gnu.so -rwxr-xr-x 1 root root 292000 Mar 4 04:00 _blake2.cpython-39-x86_64-linux-gnu.so -rwxr-xr-x 1 root root 53528 Mar 4 04:00 termios.cpython-39-x86_64-linux-gnu.so -rwxr-xr-x 1 root root 401296 Mar 4 04:00 _sha3.cpython-39-x86_64-linux-gnu.so -rwxr-xr-x 1 root root 44448 Mar 4 04:00 resource.cpython-39-x86_64-linux-gnu.so -rwxr-xr-x 1 root root 91592 Mar 4 04:00 ossaudiodev.cpython-39-x86_64-linux-gnu.so -rwxr-xr-x 1 root root 47832 Mar 4 04:00 nis.cpython-39-x86_64-linux-gnu.so -rwxr-xr-x 1 root root 160272 Mar 4 04:00 zlib.cpython-39-x86_64-linux-gnu.so -rwxr-xr-x 1 root root 102152 Mar 4 04:00 binascii.cpython-39-x86_64-linux-gnu.so -rwxr-xr-x 1 root root 942232 Mar 4 04:00 pyexpat.cpython-39-x86_64-linux-gnu.so -rwxr-xr-x 1 root root 367808 Mar 4 04:00 _elementtree.cpython-39-x86_64-linux-gnu.so -rwxr-xr-x 1 root root 189400 Mar 4 04:00 _multibytecodec.cpython-39-x86_64-linux-gnu.so -rwxr-xr-x 1 root root 168072 Mar 4 04:00 _codecs_kr.cpython-39-x86_64-linux-gnu.so -rwxr-xr-x 1 root root 311224 Mar 4 04:00 _codecs_jp.cpython-39-x86_64-linux-gnu.so -rwxr-xr-x 1 root root 137448 Mar 4 04:00 _codecs_tw.cpython-39-x86_64-linux-gnu.so -rwxr-xr-x 1 root root 88384 Mar 4 04:00 _codecs_iso2022.cpython-39-x86_64-linux-gnu.so -rwxr-xr-x 1 root root 185560 Mar 4 04:00 _codecs_hk.cpython-39-x86_64-linux-gnu.so -rwxr-xr-x 1 root root 182184 Mar 4 04:00 _codecs_cn.cpython-39-x86_64-linux-gnu.so -rwxr-xr-x 1 root root 27248 Mar 4 04:00 xxlimited.cpython-39-x86_64-linux-gnu.so -rwxr-xr-x 1 root root 30864 Mar 4 04:00 _posixshmem.cpython-39-x86_64-linux-gnu.so -rwxr-xr-x 1 root root 49040 Mar 4 04:00 _multiprocessing.cpython-39-x86_64-linux-gnu.so -rwxr-xr-x 1 root root 1702680 Mar 4 04:00 _decimal.cpython-39-x86_64-linux-gnu.so -rwxr-xr-x 1 root root 60312 Mar 4 04:00 _ctypes_test.cpython-39-x86_64-linux-gnu.so [root@mysql1 project_2]# [root@mysql1 project_2]# ls -ltr /usr/local/python/Python-3.9.2/lib/python3.9/lib-dynload | grep "sqlite3" [root@mysql1 project_2]# |
注意,这个时候,不能将Python2的sqlite3.so直接复制过来,这个是错误的做法;
正确的做法如下:
从SQLite官方获取【autoconf】包:
https://www.sqlite.org/download.html
或者,从官方获取最新的介质包:
https://www3.sqlite.org/cgi/src/doc/trunk/README.md
下载地址:
https://www.sqlite.org/2021/sqlite-autoconf-3340100.tar.gz
https://www.sqlite.org/src/tarball/sqlite.tar.gz?r=release
下载并解压:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
[root@mysql1 sqlite]# pwd /software/sqlite [root@mysql1 sqlite]# [root@mysql1 sqlite]# ls -ltr total 0 [root@mysql1 sqlite]# [root@mysql1 sqlite]# wget https://www.sqlite.org/2021/sqlite-autoconf-3340100.tar.gz --2021-03-04 06:51:22-- https://www.sqlite.org/2021/sqlite-autoconf-3340100.tar.gz Resolving www.sqlite.org (www.sqlite.org)... 45.33.6.223, 2600:3c00::f03c:91ff:fe96:b959 Connecting to www.sqlite.org (www.sqlite.org)|45.33.6.223|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 2930089 (2.8M) [application/x-gzip] Saving to: ‘sqlite-autoconf-3340100.tar.gz’ 100%[============================================================================================================================================>] 2,930,089 1.16MB/s in 2.4s 2021-03-04 06:51:26 (1.16 MB/s) - ‘sqlite-autoconf-3340100.tar.gz’ saved [2930089/2930089] [root@mysql1 sqlite]# [root@mysql1 sqlite]# tar -xzf sqlite-autoconf-3340100.tar.gz [root@mysql1 sqlite]# [root@mysql1 sqlite]# ls -ltr total 2868 drwxr-xr-x 3 adamhuan adamhuan 4096 Jan 20 09:38 sqlite-autoconf-3340100 -rw-r--r-- 1 root root 2930089 Mar 1 11:41 sqlite-autoconf-3340100.tar.gz [root@mysql1 sqlite]# [root@mysql1 sqlite]# cd sqlite-autoconf-3340100 [root@mysql1 sqlite-autoconf-3340100]# [root@mysql1 sqlite-autoconf-3340100]# ls -ltr total 10672 -rw-r--r-- 1 adamhuan adamhuan 78 Jan 20 09:38 sqlite3rc.h -rw-r--r-- 1 adamhuan adamhuan 1992 Jan 20 09:38 sqlite3.rc -rw-r--r-- 1 adamhuan adamhuan 267 Jan 20 09:38 sqlite3.pc.in -rw-r--r-- 1 adamhuan adamhuan 583202 Jan 20 09:38 sqlite3.h -rw-r--r-- 1 adamhuan adamhuan 35437 Jan 20 09:38 sqlite3ext.h -rw-r--r-- 1 adamhuan adamhuan 8182289 Jan 20 09:38 sqlite3.c -rw-r--r-- 1 adamhuan adamhuan 8928 Jan 20 09:38 sqlite3.1 -rw-r--r-- 1 adamhuan adamhuan 654331 Jan 20 09:38 shell.c -rw-r--r-- 1 adamhuan adamhuan 7272 Jan 20 09:38 Replace.cs -rw-r--r-- 1 adamhuan adamhuan 3558 Jan 20 09:38 README.txt -rw-r--r-- 1 adamhuan adamhuan 28814 Jan 20 09:38 Makefile.msc -rw-r--r-- 1 adamhuan adamhuan 547 Jan 20 09:38 Makefile.fallback -rw-r--r-- 1 adamhuan adamhuan 729 Jan 20 09:38 Makefile.am -rw-r--r-- 1 adamhuan adamhuan 15744 Jan 20 09:38 INSTALL -rw-r--r-- 1 adamhuan adamhuan 7998 Jan 20 09:38 configure.ac -rw-r--r-- 1 adamhuan adamhuan 372955 Jan 20 09:38 aclocal.m4 -rw-r--r-- 1 adamhuan adamhuan 324412 Jan 20 09:38 ltmain.sh -rwxr-xr-x 1 adamhuan adamhuan 6872 Jan 20 09:38 missing -rw-r--r-- 1 adamhuan adamhuan 37457 Jan 20 09:38 Makefile.in -rwxr-xr-x 1 adamhuan adamhuan 15155 Jan 20 09:38 install-sh -rwxr-xr-x 1 adamhuan adamhuan 23567 Jan 20 09:38 depcomp -rwxr-xr-x 1 adamhuan adamhuan 477413 Jan 20 09:38 configure -rwxr-xr-x 1 adamhuan adamhuan 36136 Jan 20 09:38 config.sub -rwxr-xr-x 1 adamhuan adamhuan 44283 Jan 20 09:38 config.guess -rwxr-xr-x 1 adamhuan adamhuan 7333 Jan 20 09:38 compile drwxr-xr-x 6 adamhuan adamhuan 192 Jan 20 09:38 tea [root@mysql1 sqlite-autoconf-3340100]# |
源码包编译:./configure
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
[root@mysql1 sqlite-autoconf-3340100]# mkdir /usr/local/sqlite [root@mysql1 sqlite-autoconf-3340100]# [root@mysql1 sqlite-autoconf-3340100]# ls -ltr /usr/local/sqlite/ total 0 [root@mysql1 sqlite-autoconf-3340100]# [root@mysql1 sqlite-autoconf-3340100]# ./configure --prefix=/usr/local/sqlite/ checking for a BSD-compatible install... /usr/bin/install -c checking whether build environment is sane... yes checking for a thread-safe mkdir -p... /usr/bin/mkdir -p checking for gawk... gawk checking whether make sets $(MAKE)... yes checking whether make supports nested variables... yes checking for style of include used by make... GNU checking for gcc... gcc checking whether the C compiler works... yes checking for C compiler default output file name... a.out checking for suffix of executables... checking whether we are cross compiling... no checking for suffix of object files... o checking whether we are using the GNU C compiler... yes checking whether gcc accepts -g... yes checking for gcc option to accept ISO C89... none needed checking whether gcc understands -c and -o together... yes checking dependency style of gcc... gcc3 checking for special C compiler options needed for large files... no checking for _FILE_OFFSET_BITS value needed for large files... no checking for gcc... (cached) gcc checking whether we are using the GNU C compiler... (cached) yes checking whether gcc accepts -g... (cached) yes checking for gcc option to accept ISO C89... (cached) none needed checking whether gcc understands -c and -o together... (cached) yes checking dependency style of gcc... (cached) gcc3 checking build system type... x86_64-pc-linux-gnu checking host system type... x86_64-pc-linux-gnu checking how to print strings... printf checking for a sed that does not truncate output... /usr/bin/sed checking for grep that handles long lines and -e... /usr/bin/grep checking for egrep... /usr/bin/grep -E checking for fgrep... /usr/bin/grep -F checking for ld used by gcc... /usr/bin/ld checking if the linker (/usr/bin/ld) is GNU ld... yes checking for BSD- or MS-compatible name lister (nm)... /usr/bin/nm -B checking the name lister (/usr/bin/nm -B) interface... BSD nm checking whether ln -s works... yes checking the maximum length of command line arguments... 1572864 checking how to convert x86_64-pc-linux-gnu file names to x86_64-pc-linux-gnu format... func_convert_file_noop checking how to convert x86_64-pc-linux-gnu file names to toolchain format... func_convert_file_noop checking for /usr/bin/ld option to reload object files... -r checking for objdump... objdump checking how to recognize dependent libraries... pass_all checking for dlltool... no checking how to associate runtime and link libraries... printf %s\n checking for ar... ar checking for archiver @FILE support... @ checking for strip... strip checking for ranlib... ranlib checking command to parse /usr/bin/nm -B output from gcc object... ok checking for sysroot... no checking for a working dd... /usr/bin/dd checking how to truncate binary pipes... /usr/bin/dd bs=4096 count=1 checking for mt... no checking if : is a manifest tool... no checking how to run the C preprocessor... gcc -E checking for ANSI C header files... yes checking for sys/types.h... yes checking for sys/stat.h... yes checking for stdlib.h... yes checking for string.h... yes checking for memory.h... yes checking for strings.h... yes checking for inttypes.h... yes checking for stdint.h... yes checking for unistd.h... yes checking for dlfcn.h... yes checking for objdir... .libs checking if gcc supports -fno-rtti -fno-exceptions... no checking for gcc option to produce PIC... -fPIC -DPIC checking if gcc PIC flag -fPIC -DPIC works... yes checking if gcc static flag -static works... no checking if gcc supports -c -o file.o... yes checking if gcc supports -c -o file.o... (cached) yes checking whether the gcc linker (/usr/bin/ld -m elf_x86_64) supports shared libraries... yes checking whether -lc should be explicitly linked in... no checking dynamic linker characteristics... GNU/Linux ld.so checking how to hardcode library paths into programs... immediate checking whether stripping libraries is possible... yes checking if libtool supports shared libraries... yes checking whether to build shared libraries... yes checking whether to build static libraries... yes checking for fdatasync... yes checking for usleep... yes checking for fullfsync... no checking for localtime_r... yes checking for gmtime_r... yes checking whether strerror_r is declared... yes checking for strerror_r... yes checking whether strerror_r returns char *... no checking editline/readline.h usability... no checking editline/readline.h presence... no checking for editline/readline.h... no checking readline/readline.h usability... no checking readline/readline.h presence... no checking for readline/readline.h... no checking for library containing pthread_create... -lpthread checking for library containing pthread_mutexattr_init... none required checking for library containing dlopen... -ldl checking for whether to support dynamic extensions... yes checking for library containing log... -lm checking for posix_fallocate... yes checking zlib.h usability... yes checking zlib.h presence... yes checking for zlib.h... yes checking for library containing deflate... -lz checking for library containing system... none required checking that generated files are newer than configure... done configure: creating ./config.status config.status: creating Makefile config.status: creating sqlite3.pc config.status: executing depfiles commands config.status: executing libtool commands [root@mysql1 sqlite-autoconf-3340100]# |
安装:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
[root@mysql1 sqlite-autoconf-3340100]# make /bin/sh ./libtool --tag=CC --mode=compile gcc -DPACKAGE_NAME=\"sqlite\" -DPACKAGE_TARNAME=\"sqlite\" -DPACKAGE_VERSION=\"3.34.1\" -DPACKAGE_STRING=\"sqlite\ 3.34.1\" -DPACKAGE_BUGREPORT=\"http://www.sqlite.org\" -DPACKAGE_URL=\"\" -DPACKAGE=\"sqlite\" -DVERSION=\"3.34.1\" -DSTDC_HEADERS=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRINGS_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_UNISTD_H=1 -DHAVE_DLFCN_H=1 -DLT_OBJDIR=\".libs/\" -DHAVE_FDATASYNC=1 -DHAVE_USLEEP=1 -DHAVE_LOCALTIME_R=1 -DHAVE_GMTIME_R=1 -DHAVE_DECL_STRERROR_R=1 -DHAVE_STRERROR_R=1 -DHAVE_POSIX_FALLOCATE=1 -DHAVE_ZLIB_H=1 -I. -D_REENTRANT=1 -DSQLITE_THREADSAFE=1 -DSQLITE_ENABLE_FTS4 -DSQLITE_ENABLE_FTS5 -DSQLITE_ENABLE_JSON1 -DSQLITE_ENABLE_RTREE -DSQLITE_ENABLE_GEOPOLY -DSQLITE_HAVE_ZLIB -g -O2 -MT sqlite3.lo -MD -MP -MF .deps/sqlite3.Tpo -c -o sqlite3.lo sqlite3.c libtool: compile: gcc -DPACKAGE_NAME=\"sqlite\" -DPACKAGE_TARNAME=\"sqlite\" -DPACKAGE_VERSION=\"3.34.1\" "-DPACKAGE_STRING=\"sqlite 3.34.1\"" -DPACKAGE_BUGREPORT=\"http://www.sqlite.org\" -DPACKAGE_URL=\"\" -DPACKAGE=\"sqlite\" -DVERSION=\"3.34.1\" -DSTDC_HEADERS=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRINGS_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_UNISTD_H=1 -DHAVE_DLFCN_H=1 -DLT_OBJDIR=\".libs/\" -DHAVE_FDATASYNC=1 -DHAVE_USLEEP=1 -DHAVE_LOCALTIME_R=1 -DHAVE_GMTIME_R=1 -DHAVE_DECL_STRERROR_R=1 -DHAVE_STRERROR_R=1 -DHAVE_POSIX_FALLOCATE=1 -DHAVE_ZLIB_H=1 -I. -D_REENTRANT=1 -DSQLITE_THREADSAFE=1 -DSQLITE_ENABLE_FTS4 -DSQLITE_ENABLE_FTS5 -DSQLITE_ENABLE_JSON1 -DSQLITE_ENABLE_RTREE -DSQLITE_ENABLE_GEOPOLY -DSQLITE_HAVE_ZLIB -g -O2 -MT sqlite3.lo -MD -MP -MF .deps/sqlite3.Tpo -c sqlite3.c -fPIC -DPIC -o .libs/sqlite3.o libtool: compile: gcc -DPACKAGE_NAME=\"sqlite\" -DPACKAGE_TARNAME=\"sqlite\" -DPACKAGE_VERSION=\"3.34.1\" "-DPACKAGE_STRING=\"sqlite 3.34.1\"" -DPACKAGE_BUGREPORT=\"http://www.sqlite.org\" -DPACKAGE_URL=\"\" -DPACKAGE=\"sqlite\" -DVERSION=\"3.34.1\" -DSTDC_HEADERS=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRINGS_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_UNISTD_H=1 -DHAVE_DLFCN_H=1 -DLT_OBJDIR=\".libs/\" -DHAVE_FDATASYNC=1 -DHAVE_USLEEP=1 -DHAVE_LOCALTIME_R=1 -DHAVE_GMTIME_R=1 -DHAVE_DECL_STRERROR_R=1 -DHAVE_STRERROR_R=1 -DHAVE_POSIX_FALLOCATE=1 -DHAVE_ZLIB_H=1 -I. -D_REENTRANT=1 -DSQLITE_THREADSAFE=1 -DSQLITE_ENABLE_FTS4 -DSQLITE_ENABLE_FTS5 -DSQLITE_ENABLE_JSON1 -DSQLITE_ENABLE_RTREE -DSQLITE_ENABLE_GEOPOLY -DSQLITE_HAVE_ZLIB -g -O2 -MT sqlite3.lo -MD -MP -MF .deps/sqlite3.Tpo -c sqlite3.c -o sqlite3.o >/dev/null 2>&1 mv -f .deps/sqlite3.Tpo .deps/sqlite3.Plo /bin/sh ./libtool --tag=CC --mode=link gcc -D_REENTRANT=1 -DSQLITE_THREADSAFE=1 -DSQLITE_ENABLE_FTS4 -DSQLITE_ENABLE_FTS5 -DSQLITE_ENABLE_JSON1 -DSQLITE_ENABLE_RTREE -DSQLITE_ENABLE_GEOPOLY -DSQLITE_HAVE_ZLIB -g -O2 -no-undefined -version-info 8:6:8 -o libsqlite3.la -rpath /usr/local/sqlite/lib sqlite3.lo -lz -lm -ldl -lpthread libtool: link: gcc -shared -fPIC -DPIC .libs/sqlite3.o -lz -lm -ldl -lpthread -g -O2 -Wl,-soname -Wl,libsqlite3.so.0 -o .libs/libsqlite3.so.0.8.6 libtool: link: (cd ".libs" && rm -f "libsqlite3.so.0" && ln -s "libsqlite3.so.0.8.6" "libsqlite3.so.0") libtool: link: (cd ".libs" && rm -f "libsqlite3.so" && ln -s "libsqlite3.so.0.8.6" "libsqlite3.so") libtool: link: ar cru .libs/libsqlite3.a sqlite3.o libtool: link: ranlib .libs/libsqlite3.a libtool: link: ( cd ".libs" && rm -f "libsqlite3.la" && ln -s "../libsqlite3.la" "libsqlite3.la" ) gcc -DPACKAGE_NAME=\"sqlite\" -DPACKAGE_TARNAME=\"sqlite\" -DPACKAGE_VERSION=\"3.34.1\" -DPACKAGE_STRING=\"sqlite\ 3.34.1\" -DPACKAGE_BUGREPORT=\"http://www.sqlite.org\" -DPACKAGE_URL=\"\" -DPACKAGE=\"sqlite\" -DVERSION=\"3.34.1\" -DSTDC_HEADERS=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRINGS_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_UNISTD_H=1 -DHAVE_DLFCN_H=1 -DLT_OBJDIR=\".libs/\" -DHAVE_FDATASYNC=1 -DHAVE_USLEEP=1 -DHAVE_LOCALTIME_R=1 -DHAVE_GMTIME_R=1 -DHAVE_DECL_STRERROR_R=1 -DHAVE_STRERROR_R=1 -DHAVE_POSIX_FALLOCATE=1 -DHAVE_ZLIB_H=1 -I. -D_REENTRANT=1 -DSQLITE_THREADSAFE=1 -DSQLITE_ENABLE_FTS4 -DSQLITE_ENABLE_FTS5 -DSQLITE_ENABLE_JSON1 -DSQLITE_ENABLE_RTREE -DSQLITE_ENABLE_GEOPOLY -DSQLITE_HAVE_ZLIB -DSQLITE_ENABLE_EXPLAIN_COMMENTS -DSQLITE_ENABLE_DBPAGE_VTAB -DSQLITE_ENABLE_STMTVTAB -DSQLITE_ENABLE_DBSTAT_VTAB -g -O2 -MT sqlite3-shell.o -MD -MP -MF .deps/sqlite3-shell.Tpo -c -o sqlite3-shell.o `test -f 'shell.c' || echo './'`shell.c mv -f .deps/sqlite3-shell.Tpo .deps/sqlite3-shell.Po gcc -DPACKAGE_NAME=\"sqlite\" -DPACKAGE_TARNAME=\"sqlite\" -DPACKAGE_VERSION=\"3.34.1\" -DPACKAGE_STRING=\"sqlite\ 3.34.1\" -DPACKAGE_BUGREPORT=\"http://www.sqlite.org\" -DPACKAGE_URL=\"\" -DPACKAGE=\"sqlite\" -DVERSION=\"3.34.1\" -DSTDC_HEADERS=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRINGS_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_UNISTD_H=1 -DHAVE_DLFCN_H=1 -DLT_OBJDIR=\".libs/\" -DHAVE_FDATASYNC=1 -DHAVE_USLEEP=1 -DHAVE_LOCALTIME_R=1 -DHAVE_GMTIME_R=1 -DHAVE_DECL_STRERROR_R=1 -DHAVE_STRERROR_R=1 -DHAVE_POSIX_FALLOCATE=1 -DHAVE_ZLIB_H=1 -I. -D_REENTRANT=1 -DSQLITE_THREADSAFE=1 -DSQLITE_ENABLE_FTS4 -DSQLITE_ENABLE_FTS5 -DSQLITE_ENABLE_JSON1 -DSQLITE_ENABLE_RTREE -DSQLITE_ENABLE_GEOPOLY -DSQLITE_HAVE_ZLIB -DSQLITE_ENABLE_EXPLAIN_COMMENTS -DSQLITE_ENABLE_DBPAGE_VTAB -DSQLITE_ENABLE_STMTVTAB -DSQLITE_ENABLE_DBSTAT_VTAB -g -O2 -MT sqlite3-sqlite3.o -MD -MP -MF .deps/sqlite3-sqlite3.Tpo -c -o sqlite3-sqlite3.o `test -f 'sqlite3.c' || echo './'`sqlite3.c mv -f .deps/sqlite3-sqlite3.Tpo .deps/sqlite3-sqlite3.Po /bin/sh ./libtool --tag=CC --mode=link gcc -D_REENTRANT=1 -DSQLITE_THREADSAFE=1 -DSQLITE_ENABLE_FTS4 -DSQLITE_ENABLE_FTS5 -DSQLITE_ENABLE_JSON1 -DSQLITE_ENABLE_RTREE -DSQLITE_ENABLE_GEOPOLY -DSQLITE_HAVE_ZLIB -DSQLITE_ENABLE_EXPLAIN_COMMENTS -DSQLITE_ENABLE_DBPAGE_VTAB -DSQLITE_ENABLE_STMTVTAB -DSQLITE_ENABLE_DBSTAT_VTAB -g -O2 -o sqlite3 sqlite3-shell.o sqlite3-sqlite3.o -lz -lm -ldl -lpthread libtool: link: gcc -D_REENTRANT=1 -DSQLITE_THREADSAFE=1 -DSQLITE_ENABLE_FTS4 -DSQLITE_ENABLE_FTS5 -DSQLITE_ENABLE_JSON1 -DSQLITE_ENABLE_RTREE -DSQLITE_ENABLE_GEOPOLY -DSQLITE_HAVE_ZLIB -DSQLITE_ENABLE_EXPLAIN_COMMENTS -DSQLITE_ENABLE_DBPAGE_VTAB -DSQLITE_ENABLE_STMTVTAB -DSQLITE_ENABLE_DBSTAT_VTAB -g -O2 -o sqlite3 sqlite3-shell.o sqlite3-sqlite3.o -lz -lm -ldl -lpthread [root@mysql1 sqlite-autoconf-3340100]# [root@mysql1 sqlite-autoconf-3340100]# make install make[1]: Entering directory `/software/sqlite/sqlite-autoconf-3340100' /usr/bin/mkdir -p '/usr/local/sqlite/lib' /bin/sh ./libtool --mode=install /usr/bin/install -c libsqlite3.la '/usr/local/sqlite/lib' libtool: install: /usr/bin/install -c .libs/libsqlite3.so.0.8.6 /usr/local/sqlite/lib/libsqlite3.so.0.8.6 libtool: install: (cd /usr/local/sqlite/lib && { ln -s -f libsqlite3.so.0.8.6 libsqlite3.so.0 || { rm -f libsqlite3.so.0 && ln -s libsqlite3.so.0.8.6 libsqlite3.so.0; }; }) libtool: install: (cd /usr/local/sqlite/lib && { ln -s -f libsqlite3.so.0.8.6 libsqlite3.so || { rm -f libsqlite3.so && ln -s libsqlite3.so.0.8.6 libsqlite3.so; }; }) libtool: install: /usr/bin/install -c .libs/libsqlite3.lai /usr/local/sqlite/lib/libsqlite3.la libtool: install: /usr/bin/install -c .libs/libsqlite3.a /usr/local/sqlite/lib/libsqlite3.a libtool: install: chmod 644 /usr/local/sqlite/lib/libsqlite3.a libtool: install: ranlib /usr/local/sqlite/lib/libsqlite3.a libtool: finish: PATH="/usr/local/python/Python-3.9.2/bin:/usr/local/python/Python-3.9.2/bin:/usr/local/mysql/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/sbin" ldconfig -n /usr/local/sqlite/lib ---------------------------------------------------------------------- Libraries have been installed in: /usr/local/sqlite/lib If you ever happen to want to link against installed libraries in a given directory, LIBDIR, you must either use libtool, and specify the full pathname of the library, or use the '-LLIBDIR' flag during linking and do at least one of the following: - add LIBDIR to the 'LD_LIBRARY_PATH' environment variable during execution - add LIBDIR to the 'LD_RUN_PATH' environment variable during linking - use the '-Wl,-rpath -Wl,LIBDIR' linker flag - have your system administrator add LIBDIR to '/etc/ld.so.conf' See any operating system documentation about shared libraries for more information, such as the ld(1) and ld.so(8) manual pages. ---------------------------------------------------------------------- /usr/bin/mkdir -p '/usr/local/sqlite/bin' /bin/sh ./libtool --mode=install /usr/bin/install -c sqlite3 '/usr/local/sqlite/bin' libtool: install: /usr/bin/install -c sqlite3 /usr/local/sqlite/bin/sqlite3 /usr/bin/mkdir -p '/usr/local/sqlite/include' /usr/bin/install -c -m 644 sqlite3.h sqlite3ext.h '/usr/local/sqlite/include' /usr/bin/mkdir -p '/usr/local/sqlite/share/man/man1' /usr/bin/install -c -m 644 sqlite3.1 '/usr/local/sqlite/share/man/man1' /usr/bin/mkdir -p '/usr/local/sqlite/lib/pkgconfig' /usr/bin/install -c -m 644 sqlite3.pc '/usr/local/sqlite/lib/pkgconfig' make[1]: Leaving directory `/software/sqlite/sqlite-autoconf-3340100' [root@mysql1 sqlite-autoconf-3340100]# |
安装完成后:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
[root@mysql1 sqlite-autoconf-3340100]# ls -ltr /usr/local/sqlite/ total 0 drwxr-xr-x 2 root root 21 Mar 4 06:55 bin drwxr-xr-x 2 root root 43 Mar 4 06:55 include drwxr-xr-x 3 root root 17 Mar 4 06:55 share drwxr-xr-x 3 root root 135 Mar 4 06:55 lib [root@mysql1 sqlite-autoconf-3340100]# [root@mysql1 sqlite-autoconf-3340100]# ls -ltr /usr/local/sqlite/bin/ total 6436 -rwxr-xr-x 1 root root 6586432 Mar 4 06:55 sqlite3 [root@mysql1 sqlite-autoconf-3340100]# [root@mysql1 sqlite-autoconf-3340100]# /usr/local/sqlite/bin/sqlite3 --version 3.34.1 2021-01-20 14:10:07 10e20c0b43500cfb9bbc0eaa061c57514f715d87238f4d835880cd846b9ebd1f [root@mysql1 sqlite-autoconf-3340100]# |
重新编译安装Python:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
[root@mysql1 python]# pwd /software/python [root@mysql1 python]# [root@mysql1 python]# ls -ltr total 2836 -rw-r--r-- 1 root root 26790 Mar 4 04:05 python_source_install_configure.log drwxr-xr-x 18 root root 4096 Mar 4 04:05 Python-3.9.2 -rw-r--r-- 1 root root 8000 Mar 4 04:05 python_source_install_make.log -rw-r--r-- 1 root root 2859689 Mar 4 04:05 python_source_install_make_install.log [root@mysql1 python]# [root@mysql1 python]# cd Python-3.9.2/ [root@mysql1 Python-3.9.2]# ls -ltr total 53080 drwxr-xr-x 23 root root 330 Feb 19 07:31 Tools -rwxr-xr-x 1 root root 109891 Feb 19 07:31 setup.py -rwxr-xr-x 1 root root 10132 Feb 19 07:31 README.rst -rwxr-xr-x 1 root root 45567 Feb 19 07:31 pyconfig.h.in drwxr-xr-x 2 root root 8192 Feb 19 07:31 PCbuild drwxr-xr-x 6 root root 4096 Feb 19 07:31 PC -rwxr-xr-x 1 root root 82 Feb 19 07:31 netlify.toml -rwxr-xr-x 1 root root 70514 Feb 19 07:31 Makefile.pre.in drwxr-xr-x 8 root root 164 Feb 19 07:31 Mac drwxr-xr-x 2 root root 70 Feb 19 07:31 m4 -rwxr-xr-x 1 root root 13925 Feb 19 07:31 LICENSE -rwxr-xr-x 1 root root 15368 Feb 19 07:31 install-sh drwxr-xr-x 4 root root 4096 Feb 19 07:31 Include drwxr-xr-x 2 root root 54 Feb 19 07:31 Grammar -rwxr-xr-x 1 root root 173556 Feb 19 07:31 configure.ac -rwxr-xr-x 1 root root 513139 Feb 19 07:31 configure -rwxr-xr-x 1 root root 36251 Feb 19 07:31 config.sub -rwxr-xr-x 1 root root 44166 Feb 19 07:31 config.guess -rwxr-xr-x 1 root root 630 Feb 19 07:31 CODE_OF_CONDUCT.md -rwxr-xr-x 1 root root 13421 Feb 19 07:31 aclocal.m4 drwxr-xr-x 18 root root 4096 Feb 19 08:34 Doc -rw-r--r-- 1 root root 47782 Mar 4 03:59 pyconfig.h drwxr-xr-x 4 root root 4096 Mar 4 03:59 Parser drwxr-xr-x 4 root root 4096 Mar 4 03:59 Objects drwxr-xr-x 35 root root 8192 Mar 4 04:00 Lib drwxr-xr-x 5 root root 82 Mar 4 04:00 build -rw-r--r-- 1 root root 65392 Mar 4 04:00 python-gdb.py -rwxr-xr-x 1 root root 41659 Mar 4 04:05 config.status -rw-r--r-- 1 root root 70263 Mar 4 04:05 Makefile.pre drwxr-xr-x 2 root root 4096 Mar 4 04:05 Misc -rw-r--r-- 1 root root 79621 Mar 4 04:05 Makefile -rw-r--r-- 1 root root 997566 Mar 4 04:05 config.log drwxr-xr-x 3 root root 4096 Mar 4 04:05 Python drwxr-xr-x 14 root root 8192 Mar 4 04:05 Modules -rw-r--r-- 1 root root 33979560 Mar 4 04:05 libpython3.9.a -rwxr-xr-x 1 root root 17896456 Mar 4 04:05 python -rw-r--r-- 1 root root 26 Mar 4 04:05 pybuilddir.txt drwxr-xr-x 2 root root 137 Mar 4 04:05 Programs -rw-r--r-- 1 root root 2063 Mar 4 04:05 python-config.py -rw-r--r-- 1 root root 3107 Mar 4 04:05 python-config [root@mysql1 Python-3.9.2]# |
修改:setup.py
1 2 3 4 5 |
[root@mysql1 Python-3.9.2]# ls -ltr | grep setup -rwxr-xr-x 1 root root 109891 Feb 19 07:31 setup.py [root@mysql1 Python-3.9.2]# [root@mysql1 Python-3.9.2]# cp setup.py setup.py_old [root@mysql1 Python-3.9.2]# |
在其中找到【sqlite_inc_paths】定义,增加前面编译安装的SQLite的路径:
1 2 3 4 5 6 7 8 9 |
sqlite_inc_paths = [ '/usr/include', '/usr/include/sqlite', '/usr/include/sqlite3', '/usr/local/include', '/usr/local/include/sqlite', '/usr/local/include/sqlite3', '/usr/local/sqlite/include', '/usr/local/sqlite/include/sqlite3', ] |
比较修改前后的文件:
1 2 3 4 5 6 7 |
[root@mysql1 Python-3.9.2]# vi setup.py [root@mysql1 Python-3.9.2]# [root@mysql1 Python-3.9.2]# diff setup.py setup.py_old 1449,1450d1448 < '/usr/local/sqlite/include', < '/usr/local/sqlite/include/sqlite3', [root@mysql1 Python-3.9.2]# |
重新编译Python:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
[root@mysql1 Python-3.9.2]# ls -ltr /usr/local/python/Python-3.9.2/ total 0 drwxr-xr-x 3 root root 23 Mar 4 04:00 include drwxr-xr-x 3 root root 17 Mar 4 04:00 share drwxr-xr-x 4 root root 62 Mar 4 04:05 lib drwxr-xr-x 3 root root 312 Mar 4 04:05 bin [root@mysql1 Python-3.9.2]# root@mysql1 Python-3.9.2]# ./configure --prefix=/usr/local/python/Python-3.9.2/ --enable-loadable-sqlite-extensions --enable-optimizations (过多的输出,...) checking for filter... no checking for has_key... no checking for typeahead... no checking for use_env... no configure: checking for device files checking for /dev/ptmx... yes checking for /dev/ptc... no checking for %zd printf() format support... yes checking for socklen_t... yes checking for broken mbstowcs... no checking for --with-computed-gotos... no value specified checking whether gcc -pthread supports computed gotos... yes checking for build directories... done checking for -O2... yes checking for glibc _FORTIFY_SOURCE/memmove bug... no checking for gcc ipa-pure-const bug... no checking for stdatomic.h... no checking for GCC >= 4.7 __atomic builtins... yes checking for ensurepip... upgrade checking if the dirent structure of a d_type field... yes checking for the Linux getrandom() syscall... yes checking for the getrandom() function... no checking for library containing shm_open... -lrt checking for sys/mman.h... (cached) yes checking for shm_open... yes checking for shm_unlink... yes checking for pkg-config... /usr/bin/pkg-config checking whether compiling and linking against OpenSSL works... yes checking for X509_VERIFY_PARAM_set1_host in libssl... yes checking for --with-ssl-default-suites... python checking for --with-builtin-hashlib-hashes... md5,sha1,sha256,sha512,sha3,blake2 configure: creating ./config.status config.status: creating Makefile.pre config.status: creating Misc/python.pc config.status: creating Misc/python-embed.pc config.status: creating Misc/python-config.sh config.status: creating Modules/ld_so_aix config.status: creating pyconfig.h config.status: pyconfig.h is unchanged creating Modules/Setup.local creating Makefile [root@mysql1 Python-3.9.2]# |
安装:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
[root@mysql1 Python-3.9.2]# make && make install (过多的输出,...) copying build/scripts-3.9/pydoc3.9 -> /usr/local/python/Python-3.9.2/bin copying build/scripts-3.9/idle3.9 -> /usr/local/python/Python-3.9.2/bin copying build/scripts-3.9/2to3-3.9 -> /usr/local/python/Python-3.9.2/bin changing mode of /usr/local/python/Python-3.9.2/bin/pydoc3.9 to 755 changing mode of /usr/local/python/Python-3.9.2/bin/idle3.9 to 755 changing mode of /usr/local/python/Python-3.9.2/bin/2to3-3.9 to 755 rm /usr/local/python/Python-3.9.2/lib/python3.9/lib-dynload/_sysconfigdata__linux_x86_64-linux-gnu.py rm -r /usr/local/python/Python-3.9.2/lib/python3.9/lib-dynload/__pycache__ /usr/bin/install -c -m 644 ./Misc/python.man \ /usr/local/python/Python-3.9.2/share/man/man1/python3.9.1 if test ! -d /usr/local/python/Python-3.9.2/lib/pkgconfig; then \ echo "Creating directory /usr/local/python/Python-3.9.2/lib/pkgconfig"; \ /usr/bin/install -c -d -m 755 /usr/local/python/Python-3.9.2/lib/pkgconfig; \ fi if test -f /usr/local/python/Python-3.9.2/bin/python3 -o -h /usr/local/python/Python-3.9.2/bin/python3; \ then rm -f /usr/local/python/Python-3.9.2/bin/python3; \ else true; \ fi (cd /usr/local/python/Python-3.9.2/bin; ln -s python3.9 python3) if test "3.9" != "3.9"; then \ rm -f /usr/local/python/Python-3.9.2/bin/python3.9-config; \ (cd /usr/local/python/Python-3.9.2/bin; ln -s python3.9-config python3.9-config); \ rm -f /usr/local/python/Python-3.9.2/lib/pkgconfig/python-3.9.pc; \ (cd /usr/local/python/Python-3.9.2/lib/pkgconfig; ln -s python-3.9.pc python-3.9.pc); \ rm -f /usr/local/python/Python-3.9.2/lib/pkgconfig/python-3.9-embed.pc; \ (cd /usr/local/python/Python-3.9.2/lib/pkgconfig; ln -s python-3.9-embed.pc python-3.9-embed.pc); \ fi rm -f /usr/local/python/Python-3.9.2/bin/python3-config (cd /usr/local/python/Python-3.9.2/bin; ln -s python3.9-config python3-config) rm -f /usr/local/python/Python-3.9.2/lib/pkgconfig/python3.pc (cd /usr/local/python/Python-3.9.2/lib/pkgconfig; ln -s python-3.9.pc python3.pc) rm -f /usr/local/python/Python-3.9.2/lib/pkgconfig/python3-embed.pc (cd /usr/local/python/Python-3.9.2/lib/pkgconfig; ln -s python-3.9-embed.pc python3-embed.pc) rm -f /usr/local/python/Python-3.9.2/bin/idle3 (cd /usr/local/python/Python-3.9.2/bin; ln -s idle3.9 idle3) rm -f /usr/local/python/Python-3.9.2/bin/pydoc3 (cd /usr/local/python/Python-3.9.2/bin; ln -s pydoc3.9 pydoc3) rm -f /usr/local/python/Python-3.9.2/bin/2to3 (cd /usr/local/python/Python-3.9.2/bin; ln -s 2to3-3.9 2to3) if test "x" != "x" ; then \ rm -f /usr/local/python/Python-3.9.2/bin/python3-32; \ (cd /usr/local/python/Python-3.9.2/bin; ln -s python3.9-32 python3-32) \ fi rm -f /usr/local/python/Python-3.9.2/share/man/man1/python3.1 (cd /usr/local/python/Python-3.9.2/share/man/man1; ln -s python3.9.1 python3.1) if test "xupgrade" != "xno" ; then \ case upgrade in \ upgrade) ensurepip="--upgrade" ;; \ install|*) ensurepip="" ;; \ esac; \ ./python -E -m ensurepip \ $ensurepip --root=/ ; \ fi Looking in links: /tmp/tmpls6olmf8 Requirement already up-to-date: setuptools in /usr/local/python/Python-3.9.2/lib/python3.9/site-packages (49.2.1) Requirement already up-to-date: pip in /usr/local/python/Python-3.9.2/lib/python3.9/site-packages (20.2.3) [root@mysql1 Python-3.9.2]# |
再查【_sqlite3.so】:
1 2 3 4 5 6 |
[root@mysql1 Python-3.9.2]# find / -name "_sqlite*.so" /usr/lib64/python2.7/lib-dynload/_sqlite3.so /usr/lib64/python2.7/site-packages/_sqlitecache.so /usr/local/python/Python-3.9.2/lib/python3.9/lib-dynload/_sqlite3.cpython-39-x86_64-linux-gnu.so /software/python/Python-3.9.2/build/lib.linux-x86_64-3.9/_sqlite3.cpython-39-x86_64-linux-gnu.so [root@mysql1 Python-3.9.2]# |
然后,再试试Django,看还会不会报错:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
[root@mysql1 project_2]# ls -ltr total 4 -rwxr-xr-x 1 root root 665 Mar 4 05:32 manage.py drwxr-xr-x 3 root root 108 Mar 4 06:39 django_02 [root@mysql1 project_2]# [root@mysql1 project_2]# python3 -V Python 3.9.2 [root@mysql1 project_2]# [root@mysql1 project_2]# python3 manage.py runserver Watching for file changes with StatReloader Exception in thread django-main-thread: Traceback (most recent call last): File "/usr/local/python/Python-3.9.2/lib/python3.9/threading.py", line 954, in _bootstrap_inner self.run() File "/usr/local/python/Python-3.9.2/lib/python3.9/threading.py", line 892, in run self._target(*self._args, **self._kwargs) File "/usr/local/python/Python-3.9.2/lib/python3.9/site-packages/django/utils/autoreload.py", line 53, in wrapper fn(*args, **kwargs) File "/usr/local/python/Python-3.9.2/lib/python3.9/site-packages/django/core/management/commands/runserver.py", line 110, in inner_run autoreload.raise_last_exception() File "/usr/local/python/Python-3.9.2/lib/python3.9/site-packages/django/utils/autoreload.py", line 76, in raise_last_exception raise _exception[1] File "/usr/local/python/Python-3.9.2/lib/python3.9/site-packages/django/core/management/__init__.py", line 357, in execute autoreload.check_errors(django.setup)() File "/usr/local/python/Python-3.9.2/lib/python3.9/site-packages/django/utils/autoreload.py", line 53, in wrapper fn(*args, **kwargs) File "/usr/local/python/Python-3.9.2/lib/python3.9/site-packages/django/__init__.py", line 24, in setup apps.populate(settings.INSTALLED_APPS) File "/usr/local/python/Python-3.9.2/lib/python3.9/site-packages/django/apps/registry.py", line 114, in populate app_config.import_models() File "/usr/local/python/Python-3.9.2/lib/python3.9/site-packages/django/apps/config.py", line 211, in import_models self.models_module = import_module(models_module_name) File "/usr/local/python/Python-3.9.2/lib/python3.9/importlib/__init__.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "<frozen importlib._bootstrap>", line 1030, in _gcd_import File "<frozen importlib._bootstrap>", line 1007, in _find_and_load File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 680, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 790, in exec_module File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed File "/usr/local/python/Python-3.9.2/lib/python3.9/site-packages/django/contrib/auth/models.py", line 2, in <module> from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager File "/usr/local/python/Python-3.9.2/lib/python3.9/site-packages/django/contrib/auth/base_user.py", line 48, in <module> class AbstractBaseUser(models.Model): File "/usr/local/python/Python-3.9.2/lib/python3.9/site-packages/django/db/models/base.py", line 122, in __new__ new_class.add_to_class('_meta', Options(meta, app_label)) File "/usr/local/python/Python-3.9.2/lib/python3.9/site-packages/django/db/models/base.py", line 326, in add_to_class value.contribute_to_class(cls, name) File "/usr/local/python/Python-3.9.2/lib/python3.9/site-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/python/Python-3.9.2/lib/python3.9/site-packages/django/db/__init__.py", line 28, in __getattr__ return getattr(connections[DEFAULT_DB_ALIAS], item) File "/usr/local/python/Python-3.9.2/lib/python3.9/site-packages/django/db/utils.py", line 214, in __getitem__ backend = load_backend(db['ENGINE']) File "/usr/local/python/Python-3.9.2/lib/python3.9/site-packages/django/db/utils.py", line 111, in load_backend return import_module('%s.base' % backend_name) File "/usr/local/python/Python-3.9.2/lib/python3.9/importlib/__init__.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "/usr/local/python/Python-3.9.2/lib/python3.9/site-packages/django/db/backends/sqlite3/base.py", line 70, in <module> check_sqlite_version() File "/usr/local/python/Python-3.9.2/lib/python3.9/site-packages/django/db/backends/sqlite3/base.py", line 67, in check_sqlite_version raise ImproperlyConfigured('SQLite 3.8.3 or later is required (found %s).' % Database.sqlite_version) django.core.exceptions.ImproperlyConfigured: SQLite 3.8.3 or later is required (found 3.7.17). |
可以看到,报错已经不一样了,刚刚的【_sqlite3.so】的问题已经解决了。
现在的这个SQLite版本过低的问题是因为前面的SQLite的安装没有写入环境变量:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
[root@mysql1 Python-3.9.2]# sqlite3 --version 3.7.17 2013-05-20 00:56:22 118a3b35693b134d56ebd780123b7fd6f1497668 [root@mysql1 Python-3.9.2]# [root@mysql1 Python-3.9.2]# cat ~/.bash_profile # .bash_profile # Get the aliases and functions if [ -f ~/.bashrc ]; then . ~/.bashrc fi # User specific environment and startup programs PATH=$PATH:$HOME/bin export PATH # MySQL Database export PATH=/usr/local/mysql/bin:$PATH # Python export PATH=/usr/local/python/Python-3.9.2/bin:$PATH # Python export PATH=/usr/local/python/Python-3.9.2/bin:$PATH # SQLite export PATH=/usr/local/sqlite/bin:$PATH [root@mysql1 Python-3.9.2]# [root@mysql1 Python-3.9.2]# source ~/.bash_profile [root@mysql1 Python-3.9.2]# [root@mysql1 Python-3.9.2]# sqlite3 --version 3.34.1 2021-01-20 14:10:07 10e20c0b43500cfb9bbc0eaa061c57514f715d87238f4d835880cd846b9ebd1f [root@mysql1 Python-3.9.2]# |
或者替换掉系统默认的SQLite3:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
[root@mysql1 project_2]# mv /usr/bin/sqlite3 /usr/bin/sqlite3_old [root@mysql1 project_2]# [root@mysql1 project_2]# ln -s /usr/local/sqlite/bin/sqlite3 /usr/bin/sqlite3 [root@mysql1 project_2]# [root@mysql1 project_2]# ls -ltr /usr/bin/sqlite3 lrwxrwxrwx 1 root root 29 Mar 4 07:57 /usr/bin/sqlite3 -> /usr/local/sqlite/bin/sqlite3 [root@mysql1 project_2]# [root@mysql1 project_2]# sqlite3 --version 3.34.1 2021-01-20 14:10:07 10e20c0b43500cfb9bbc0eaa061c57514f715d87238f4d835880cd846b9ebd1f [root@mysql1 project_2]# [root@mysql1 project_2]# /usr/bin/sqlite3 --version 3.34.1 2021-01-20 14:10:07 10e20c0b43500cfb9bbc0eaa061c57514f715d87238f4d835880cd846b9ebd1f [root@mysql1 project_2]# [root@mysql1 project_2]# /usr/local/sqlite/bin/sqlite3 --version 3.34.1 2021-01-20 14:10:07 10e20c0b43500cfb9bbc0eaa061c57514f715d87238f4d835880cd846b9ebd1f [root@mysql1 project_2]# |
或者:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
[root@mysql1 ~]# python3 Python 3.9.2 (default, Mar 4 2021, 07:44:07) [GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux Type "help", "copyright", "credits" or "license" for more information. >>> >>> import sqlite3 >>> sqlite3.sqlite_version '3.7.17' >>> >>> exit() [root@mysql1 ~]# [root@mysql1 ~]# cat .bash_profile # .bash_profile # Get the aliases and functions if [ -f ~/.bashrc ]; then . ~/.bashrc fi # User specific environment and startup programs PATH=$PATH:$HOME/bin export PATH # MySQL Database export PATH=/usr/local/mysql/bin:$PATH # Python export PATH=/usr/local/python/Python-3.9.2/bin:$PATH # Python export PATH=/usr/local/python/Python-3.9.2/bin:$PATH # SQLite export PATH=/usr/local/sqlite/bin:$PATH export LD_LIBRARY_PATH=/usr/local/sqlite/lib [root@mysql1 ~]# [root@mysql1 ~]# source ~/.bash_profile [root@mysql1 ~]# [root@mysql1 ~]# python3 Python 3.9.2 (default, Mar 4 2021, 07:44:07) [GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux Type "help", "copyright", "credits" or "license" for more information. >>> >>> import sqlite3 >>> sqlite3.sqlite_version '3.34.1' >>> >>> exit() [root@mysql1 ~]# |
如上,已经加好了环境变量,再试试:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
[root@mysql1 ~]# cd /django_base/project_2/ [root@mysql1 project_2]# [root@mysql1 project_2]# ls -ltr total 4 -rwxr-xr-x 1 root root 665 Mar 4 05:32 manage.py drwxr-xr-x 3 root root 108 Mar 4 06:39 django_02 [root@mysql1 project_2]# [root@mysql1 project_2]# python3 manage.py runserver Watching for file changes with StatReloader Performing system checks... System check identified no issues (0 silenced). You have 18 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. March 04, 2021 - 13:06:47 Django version 3.1.7, using settings 'django_02.settings' Starting development server at http://127.0.0.1:8000/ Quit the server with CONTROL-C. |
可以看到,跑成功了。