Django - 如何在 venv 中正确安装没有 pip 的库以在部署后工作

Django - how to correctly install library without pip in venv to work after deployment

根据 this 指南,我在虚拟环境中成功连接到我的 django 项目中的 Sybase 数据库。

Apache 中部署后,网络写入此错误消息

Environment:


Request Method: GET
Request URL: http://localhost:8080/

Django Version: 1.8
Python Version: 3.6.9
Installed Applications:
('django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'blog',
 'sybase_app')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware',
 'django.middleware.security.SecurityMiddleware')


Traceback:
File "/home/pd/sibp/env/lib/python3.6/site-packages/django/core/handlers/base.py" in get_response
  132.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/usr/lib/python3.6/contextlib.py" in inner
  51.             with self._recreate_cm():
File "/home/pd/sibp/env/lib/python3.6/site-packages/django/db/transaction.py" in __enter__
  150.             if not connection.get_autocommit():
File "/home/pd/sibp/env/lib/python3.6/site-packages/django/db/backends/base/base.py" in get_autocommit
  286.         self.ensure_connection()
File "/home/pd/sibp/env/lib/python3.6/site-packages/django/db/backends/base/base.py" in ensure_connection
  130.                 self.connect()
File "/home/pd/sibp/env/lib/python3.6/site-packages/django/db/utils.py" in __exit__
  97.                 six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/home/pd/sibp/env/lib/python3.6/site-packages/django/utils/six.py" in reraise
  658.             raise value.with_traceback(tb)
File "/home/pd/sibp/env/lib/python3.6/site-packages/django/db/backends/base/base.py" in ensure_connection
  130.                 self.connect()
File "/home/pd/sibp/env/lib/python3.6/site-packages/django/db/backends/base/base.py" in connect
  118.         conn_params = self.get_connection_params()
File "/home/pd/sibp/env/lib/python3.6/site-packages/sqlany_django/base.py" in get_connection_params
  517.         root = Database.Root('PYTHON')
File "/home/pd/sibp/env/lib/python3.6/site-packages/sqlanydb.py" in __init__
  466.                                 'libdbcapi_r.dylib')
File "/home/pd/sibp/env/lib/python3.6/site-packages/sqlanydb.py" in load_library
  458.     raise InterfaceError("Could not load dbcapi.  Tried: " + ','.join(map(str, names)))

Exception Type: InterfaceError at /
Exception Value: Could not load dbcapi.  Tried: None,dbcapi.dll,libdbcapi_r.so,libdbcapi_r.dylib

我编辑了 /etc/apache2/envvars 并附加了一行 export LD_LIBRARY_PATH=/opt/sqlanywhere17/lib64:/opt/sqlanywhere17/lib32:$LD_LIBRARY_PATH

错误消息更改为:

Environment:


Request Method: GET
Request URL: http://localhost:8080/

Django Version: 1.8
Python Version: 3.6.9
Installed Applications:
('django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'blog',
 'sybase_app')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware',
 'django.middleware.security.SecurityMiddleware')


Traceback:
File "/home/pd/sibp/env/lib/python3.6/site-packages/django/core/handlers/base.py" in get_response
  132.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/usr/lib/python3.6/contextlib.py" in inner
  51.             with self._recreate_cm():
File "/home/pd/sibp/env/lib/python3.6/site-packages/django/db/transaction.py" in __enter__
  150.             if not connection.get_autocommit():
File "/home/pd/sibp/env/lib/python3.6/site-packages/django/db/backends/base/base.py" in get_autocommit
  286.         self.ensure_connection()
File "/home/pd/sibp/env/lib/python3.6/site-packages/django/db/backends/base/base.py" in ensure_connection
  130.                 self.connect()
File "/home/pd/sibp/env/lib/python3.6/site-packages/django/db/utils.py" in __exit__
  97.                 six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/home/pd/sibp/env/lib/python3.6/site-packages/django/utils/six.py" in reraise
  658.             raise value.with_traceback(tb)
File "/home/pd/sibp/env/lib/python3.6/site-packages/django/db/backends/base/base.py" in ensure_connection
  130.                 self.connect()
File "/home/pd/sibp/env/lib/python3.6/site-packages/django/db/backends/base/base.py" in connect
  118.         conn_params = self.get_connection_params()
File "/home/pd/sibp/env/lib/python3.6/site-packages/sqlany_django/base.py" in get_connection_params
  517.         root = Database.Root('PYTHON')
File "/home/pd/sibp/env/lib/python3.6/site-packages/sqlanydb.py" in __init__
  480.                         API_VERSION_EX)

Exception Type: InterfaceError at /
Exception Value: Failed to initalize dbcapi context, dbcapi version 2 required. Perhaps you are missing some sqlanywhere libaries?

我该如何解决?

我解决了,所以我将文件 /opt/sqlanywhere17/bin64/sa_config.sh 附加到 /etc/apache2/envvars 并重新启动 apache2