wsgi_mod无法在CentOs上使用python3.10托管Django

rjzwgtxy  于 2022-11-07  发布在  Python
关注(0)|答案(1)|浏览(138)

我的目标是用python3.10在CentOs 7上托管Django应用程序
我已经设法下载和配置Python,sqlite与manage.py运行服务器一起工作,但当我试图用apache托管它时,它不工作。
Apache抛出错误:ImportError: /usr/local/lib/python3.10/lib-dynload/_sqlite3.cpython-310-x86_64-linux-gnu.so: undefined symbol: sqlite3_trace_v2
已安装的版本

  • 系统:CentOs 7
  • Python语言:3.10.4
  • 平方:3.28.0
  • 修改wsgi:4.9.0
  • Apache服务器:2.4.6

Apache .配置文件

WSGIScriptAlias / /var/www/portal/portal/wsgi.py
WSGIPythonPath /var/www/portal/:/var/www/venv/lib/python3.10/site-packages
<VirtualHost *:80>
  ServerName 192.168.1.25
  Alias /static /var/www/portal/static/
  DocumentRoot /var/www/portal

  <Directory /opt/portal/static>
    AllowOverride All
    Require all granted
    Allow from all
  </Directory>

  <Directory /var/www/portal/portal>
    <Files wsgi.py>
      Require all granted
    </Files>
  </Directory>
</VirtualHost>

完整追溯:

Traceback (most recent call last):
   File "/var/www/portal/portal/wsgi.py", line 22, in <module>
     application = get_wsgi_application()
   File "/var/www/venv/lib/python3.10/site-packages/django/core/wsgi.py", line 12, in get_wsgi_application
     django.setup(set_prefix=False)
   File "/var/www/venv/lib/python3.10/site-packages/django/__init__.py", line 24, in setup
     apps.populate(settings.INSTALLED_APPS)
   File "/var/www/venv/lib/python3.10/site-packages/django/apps/registry.py", line 116, in populate
     app_config.import_models()
   File "/var/www/venv/lib/python3.10/site-packages/django/apps/config.py", line 304, in import_models
     self.models_module = import_module(models_module_name)
   File "/usr/local/lib/python3.10/importlib/__init__.py", line 126, in import_module
     return _bootstrap._gcd_import(name[level:], package, level)
   File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
   File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
   File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
   File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
   File "<frozen importlib._bootstrap_external>", line 883, in exec_module
   File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
   File "/var/www/venv/lib/python3.10/site-packages/django/contrib/auth/models.py", line 3, in <module>
     from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
   File "/var/www/venv/lib/python3.10/site-packages/django/contrib/auth/base_user.py", line 49, in <module>
     class AbstractBaseUser(models.Model):
   File "/var/www/venv/lib/python3.10/site-packages/django/db/models/base.py", line 141, in __new__
     new_class.add_to_class("_meta", Options(meta, app_label))
   File "/var/www/venv/lib/python3.10/site-packages/django/db/models/base.py", line 369, in add_to_class
     value.contribute_to_class(cls, name)
   File "/var/www/venv/lib/python3.10/site-packages/django/db/models/options.py", line 235, in contribute_to_class
     self.db_table, connection.ops.max_name_length()
   File "/var/www/venv/lib/python3.10/site-packages/django/utils/connection.py", line 15, in __getattr__
     return getattr(self._connections[self._alias], item)
   File "/var/www/venv/lib/python3.10/site-packages/django/utils/connection.py", line 62, in __getitem__
     conn = self.create_connection(alias)
   File "/var/www/venv/lib/python3.10/site-packages/django/db/utils.py", line 208, in create_connection
     backend = load_backend(db["ENGINE"])
   File "/var/www/venv/lib/python3.10/site-packages/django/db/utils.py", line 113, in load_backend
     return import_module("%s.base" % backend_name)
   File "/usr/local/lib/python3.10/importlib/__init__.py", line 126, in import_module
     return _bootstrap._gcd_import(name[level:], package, level)
   File "/var/www/venv/lib/python3.10/site-packages/django/db/backends/sqlite3/base.py", line 15, in <module>
     from sqlite3 import dbapi2 as Database
   File "/usr/local/lib/python3.10/sqlite3/__init__.py", line 57, in <module>
     from sqlite3.dbapi2 import *
   File "/usr/local/lib/python3.10/sqlite3/dbapi2.py", line 27, in <module>
     from _sqlite3 import *
 ImportError: /usr/local/lib/python3.10/lib-dynload/_sqlite3.cpython-310-x86_64-linux-gnu.so: undefined symbol: sqlite3_trace_v2
jvlzgdj9

jvlzgdj91#

我没有找到任何解决这个问题的方法,但是我已经把python降级到3.9.12,现在它可以工作了。

INSTALLATION REQUIRED PACKAGES:
yum update 
yum groupinstall "Development Tools" -y
yum install wget httpd httpd-devel openssl-devel libffi-devel bzip2-devel -y
wget https://www.python.org/ftp/python/3.9.12/Python-3.9.12.tgz
tar xvf Python-3.9.12.tgz
wget https://www.sqlite.org/2019/sqlite-autoconf-3280000.tar.gz
tar zxvf sqlite-autoconf-3280000.tar.gz

SQLITE INSTALLATION:
cd ~/sqlite-autoconf-3280000
./configure
make
make install

PYTHON INSTALLATION:
cd ~/Python-3.9.12
./configure --enable-loadable-sqlite-extensions --enable-shared --with-ssl

SET UP LD_LIBRARY_PATH:
vi ~/.bashrc 
    export LD_LIBRARY_PATH=/usr/local/lib
source ~/.bashrc

CREATE VIRTUAL ENV: 
cd /opt
python3.9 -m venv venv

MOD_WSGI INSTALLATION FOR CURRENT VERSION OF PYTHONA:
source ./venv/bin/activate
pip install mod_wsgi
mod_wsgi-express install-module > /etc/httpd/conf.modules.d/02-wsgi.conf

UPDATE SQLITE (TODO: find better solution. Now sqlite verison works with 
installed django, after updating django you have to manually change it again, 
Right now can t find better solution):
source /opt/venv/bin/activate
pip install pysqlite3
pip install pysqlite3-binary
vi /opt/venv/lib/python3.9/site-modules/django/db/backends/sqlite3/base.py
    change 'from sqlite3 import ...' to 'from pysqlite3 import ...'

相关问题