无法在Ubuntu上使用Django连接到Oracle数据库

时间:2010-12-02 17:23:14

标签: django oracle ubuntu

每当我尝试运行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上解析吗?

3 个答案:

答案 0 :(得分:7)

您需要同时安装cx_Oracle和Oracle客户端。

cx_Oracle可以是found here

适当的Oracle客户端可以是found here

在启动应用程序之前,还需要设置LD_LIBRARY_PATH变量。通常可以这样做(例如):

export LD_LIBRARY_PATH=/usr/lib/oracle/11.2/client64/lib

现在您应该能够通过cx_Oracle错误消息。

答案 1 :(得分:0)

首先要做的事情 - 这实际上是一个Django问题,还是只是一个cx_Oracle问题?是否正确安装了cx_Oracle?你能在Python shell会话中连接到Oracle数据库吗?

import cx_Oracle
conn = cx_Oracle.connect('/') # user/password@dsn
cursor = conn.cursor()

如果这不会引发异常,则表示您已成功连接。

答案 2 :(得分:-1)

尝试easy_install cx_Oracle,它将从源代码

编译cx_Oracle模块