无法使用Ubuntu上的Django连接到Oracle数据库
每当我尝试运行像python manage.py syncdb
这样的命令时,出现以下错误:
Traceback (most recent call last): File "manage.py", line 11, in execute_manager(settings) File "/home/damon/Workspace/django-projects/acm-cie/env/lib/python2.6/site-packages/django/core/management/__init__.py", line 438, in execute_manager utility.execute() File "/home/damon/Workspace/django-projects/acm-cie/env/lib/python2.6/site-packages/django/core/management/__init__.py", line 379, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/home/damon/Workspace/django-projects/acm-cie/env/lib/python2.6/site-packages/django/core/management/__init__.py", line 261, in fetch_command klass = load_command_class(app_name, subcommand) File "/home/damon/Workspace/django-projects/acm-cie/env/lib/python2.6/site-packages/django/core/management/__init__.py", line 67, in load_command_class module = import_module('%s.management.commands.%s' % (app_name, name)) File "/home/damon/Workspace/django-projects/acm-cie/env/lib/python2.6/site-packages/django/utils/importlib.py", line 35, in import_module __import__(name) File "/home/damon/Workspace/django-projects/acm-cie/env/lib/python2.6/site-packages/south/management/commands/__init__.py", line 10, in import django.template.loaders.app_directories File "/home/damon/Workspace/django-projects/acm-cie/env/lib/python2.6/site-packages/django/template/loaders/app_directories.py", line 21, in mod = import_module(app) File "/home/damon/Workspace/django-projects/acm-cie/env/lib/python2.6/site-packages/django/utils/importlib.py", line 35, in import_module __import__(name) File "/home/damon/Workspace/django-projects/acm-cie/env/lib/python2.6/site-packages/django/contrib/admin/__init__.py", line 1, in from django.contrib.admin.helpers import ACTION_CHECKBOX_NAME File "/home/damon/Workspace/django-projects/acm-cie/env/lib/python2.6/site-packages/django/contrib/admin/helpers.py", line 1, in from django import forms File "/home/damon/Workspace/django-projects/acm-cie/env/lib/python2.6/site-packages/django/forms/__init__.py", line 17, in from models import * File "/home/damon/Workspace/django-projects/acm-cie/env/lib/python2.6/site-packages/django/forms/models.py", line 6, in from django.db import connections File "/home/damon/Workspace/django-projects/acm-cie/env/lib/python2.6/site-packages/django/db/__init__.py", line 77, in connection = connections[DEFAULT_DB_ALIAS] File "/home/damon/Workspace/django-projects/acm-cie/env/lib/python2.6/site-packages/django/db/utils.py", line 91, in __getitem__ backend = load_backend(db['ENGINE']) File "/home/damon/Workspace/django-projects/acm-cie/env/lib/python2.6/site-packages/django/db/utils.py", line 32, in load_backend return import_module('.base', backend_name) File "/home/damon/Workspace/django-projects/acm-cie/env/lib/python2.6/site-packages/django/utils/importlib.py", line 35, in import_module __import__(name) File "/home/damon/Workspace/django-projects/acm-cie/env/lib/python2.6/site-packages/django/db/backends/oracle/base.py", line 24, in raise ImproperlyConfigured("Error loading cx_Oracle module: %s" % e) django.core.exceptions.ImproperlyConfigured: Error loading cx_Oracle module: libclntsh.so.11.1: cannot open shared object file: No such file or directory
这在Ubuntu上可以解决吗?
您需要安装cx_Oracle和Oracle客户端。
cx_Oracle可以在这里找到。
一个合适的Oracle客户端可以在这里找到。
在启动应用程序之前,您还需要设置LD_LIBRARY_PATH变量。 这通常可以完成(例如):
export LD_LIBRARY_PATH=/usr/lib/oracle/11.2/client64/lib
现在您应该能够通过cx_Oracle错误消息。
首先要做的是 - 这实际上是Django问题还是cx_Oracle问题? cx_Oracle是否正确安装? 你能在Python shell会话中连接到你的Oracle数据库吗?
import cx_Oracle
conn = cx_Oracle.connect('/') # user/password@dsn
cursor = conn.cursor()
如果这不会引发异常,则说明您已成功连接。
尝试easy_install cx_Oracle,它会从源代码编译cx_Oracle模块
链接地址: http://www.djcxy.com/p/40567.html上一篇: Cannot connect to Oracle database with Django on Ubuntu