Deploy the django project to the actual combat of stepping on the pit of centos
- 2021-11-14 06:25:43
- OfStack
Preface
This article describes some of the problems encountered in deploying an django project to an centos. For the steps of deploying an Django project to an CentOs server, please refer to this article: https://www.ofstack.com/article/149135. htm
FAQ1: When installing the library using pip3, you are prompted to upgrade pip
pip3 install --upgrade pip
FAQ2: When creating a soft link, prompt: ln: failed to create symbolic link '/usr/bin/python3': File exists
We can add an f to the parameter to create it forcibly
ln -sf /huyang/python395/bin/python3.9 /usr/bin/python3
FAQ3: When running the django3 project, it does not work and is always prompted: DJANGO. CORE. EXCEPTIONS. IMPROPERLYCONFIGURED: SQLITE 3.9. 0 OR LATER IS REQUIRED (FOUND 3.7. 17).
The default installation of centos is SQLite version 2. x, but django is required to be larger than version 3.9. 0, so it will not run.
This is a headache, but there are two solutions:
Method 1: Upgrade sqlite version of centos. At present, I haven't completely solved this method. ps: After upgrading sqlite of centos, the import version from Python3 is still 2. x. This problem is left to be studied later.
Although this method has not been solved, you can record the sqlite with centos installed first
1. Create a folder and enter the folder
mkdir -p /usr/local/sqlite && cd /usr/local/sqlite
2. Download sqlite
wget wget https://www.sqlite.org/2021/sqlite-autoconf-3350500.tar.gz
3. Unzip and enter the unzipped folder
tar -zxvf sqlite-autoconf-3350500.tar.gz && cd sqlite-autoconf-3350500
4. Set configuration file, installation location
./configure --prefix=/usr/local/sqlite
5. Compile + Installation
make && make install
6. Will the previous sqlite Make a backup of the link, and then create a soft link
mv /usr/bin/sqlite3 /usr/bin/sqlite3.bak
ln -sf /usr/local/sqlite/bin/sqlite3 /usr/bin/sqlite3
7. Configure environment variables and take effect
export LD_LIBRARY_PATH = "/usr/local/lib"
source ~/.bashrc
8. Check sqlite Version
sqlite3 --version
Method 2: Replace sqlite with pysqlite. This method is relatively simple. Let's talk about this method below
This method does not depend on the system's sqlite, but uses pysqlite3 and pysqlite3-binary to operate
1. Install the libraries first
pip3 install pysqlite3
pip3 install pysqlite3-binary
2. Modify the base. py file
vi /huyang/python395/lib/python3.9.5/site-packages/django/db/backends/sqlite3/base.py
# from sqlite3 import dbapi2 as Database ( Comment out this paragraph )
from pysqlite3 import dbapi2 as Database # Enable pysqlite3
Then press ESC and enter: wq! Save the exit file
Then, after running the project, it can run normally.
FAQ4: When installing the Python library, prompt: ModuleNotFoundError: No module named '_ ctypes'
You need to install libffi-devel, and then recompile and install Python
yum install libffi-devel -y
cd Python-3.9.5
make install
Summarize