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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4337849/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 22:05:54  来源:igfitidea点击:

Cannot connect to Oracle database with Django on Ubuntu

djangooracleubuntu

提问by damon

Whenever I try to run a command like python manage.py syncdb, I get the following error:

每当我尝试运行类似的命令时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

Is this resolvable on Ubuntu?

这可以在 Ubuntu 上解决吗?

回答by Jon

You need to install both cx_Oracle and an Oracle Client.

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

cx_Oracle can be found here.

可以在此处找到cx_Oracle 。

An appropriate Oracle Client can be found here.

可以在此处找到合适的 Oracle 客户端。

You will also need to set the LD_LIBRARY_PATH variable before you start your application. This can usually be done (for example):

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

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

Now you should be able to get past the cx_Oracle error message.

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

回答by pfctdayelise

First things first - is this actually a Django problem, or just a cx_Oracle problem? Is cx_Oracle installed correctly? Can you connect to your Oracle database in a Python shell session?

首先,这实际上是 Django 问题,还是只是 cx_Oracle 问题?cx_Oracle 是否正确安装?您可以在 Python shell 会话中连接到您的 Oracle 数据库吗?

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

If this doesn't raise an exception, you have connected successfully.

如果这没有引发异常,则您已成功连接。

回答by damir

try easy_install cx_Oracle, it will compile cx_Oracle module from source

尝试easy_install cx_Oracle,它将从源代码编译cx_Oracle模块