尽管已添加,但Pycharm无法看到Oracle客户端。 Sqlalchemy,Python

问题描述 投票:0回答:1

我试图在pycharmie中运行我的python代码,它连接到数据库,虽然它从命令行成功,PyCharm返回以下错误。

在我看来,我在pycharma设置中添加了所有必要的更改来运行Oracle客户端。

enter image description here

my_file.朋友

import sqlalchemy as db
engine = db.create_engine('dialect+driver://user:pass@host:port/db')
connection = enigne.connect()

来自PyCharm的错误

/home/tymoteusz/Desktop/test/venv/bin/python /home/tymoteusz/Desktop/my_task_sqlalchemy/test_document.py
Traceback (most recent call last):
  File "/home/tymoteusz/.local/lib/python3.6/site-packages/sqlalchemy/engine/base.py", line 2221, in _wrap_pool_connect
    return fn()
  File "/home/tymoteusz/.local/lib/python3.6/site-packages/sqlalchemy/pool.py", line 356, in unique_connection
    return _ConnectionFairy._checkout(self)
  File "/home/tymoteusz/.local/lib/python3.6/site-packages/sqlalchemy/pool.py", line 811, in _checkout
    fairy = _ConnectionRecord.checkout(pool)
  File "/home/tymoteusz/.local/lib/python3.6/site-packages/sqlalchemy/pool.py", line 543, in checkout
    rec = pool._do_get()
  File "/home/tymoteusz/.local/lib/python3.6/site-packages/sqlalchemy/pool.py", line 1239, in _do_get
    self._dec_overflow()
  File "/home/tymoteusz/.local/lib/python3.6/site-packages/sqlalchemy/util/langhelpers.py", line 67, in __exit__
    compat.reraise(exc_type, exc_value, exc_tb)
  File "/home/tymoteusz/.local/lib/python3.6/site-packages/sqlalchemy/util/compat.py", line 277, in reraise
    raise value
  File "/home/tymoteusz/.local/lib/python3.6/site-packages/sqlalchemy/pool.py", line 1236, in _do_get
    return self._create_connection()
  File "/home/tymoteusz/.local/lib/python3.6/site-packages/sqlalchemy/pool.py", line 361, in _create_connection
    return _ConnectionRecord(self)
  File "/home/tymoteusz/.local/lib/python3.6/site-packages/sqlalchemy/pool.py", line 488, in __init__
    self.__connect(first_connect_check=True)
  File "/home/tymoteusz/.local/lib/python3.6/site-packages/sqlalchemy/pool.py", line 690, in __connect
    connection = pool._invoke_creator(self)
  File "/home/tymoteusz/.local/lib/python3.6/site-packages/sqlalchemy/engine/strategies.py", line 114, in connect
    return dialect.connect(*cargs, **cparams)
  File "/home/tymoteusz/.local/lib/python3.6/site-packages/sqlalchemy/engine/default.py", line 437, in connect
    return self.dbapi.connect(*cargs, **cparams)
cx_Oracle.DatabaseError: DPI-1047: 64-bit Oracle Client library cannot be loaded: "libclntsh.so: cannot open shared object file: No such file or directory". See https://oracle.github.io/odpi/doc/installation.html#linux for help

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/tymoteusz/Desktop/my_task_sqlalchemy/test_document.py", line 6, in <module>
    connection = engine.connect()
  File "/home/tymoteusz/.local/lib/python3.6/site-packages/sqlalchemy/engine/base.py", line 2164, in connect
    return self._connection_cls(self, **kwargs)
  File "/home/tymoteusz/.local/lib/python3.6/site-packages/sqlalchemy/engine/base.py", line 103, in __init__
    else engine.raw_connection()
  File "/home/tymoteusz/.local/lib/python3.6/site-packages/sqlalchemy/engine/base.py", line 2252, in raw_connection
    self.pool.unique_connection, _connection
  File "/home/tymoteusz/.local/lib/python3.6/site-packages/sqlalchemy/engine/base.py", line 2225, in _wrap_pool_connect
    e, dialect, self
  File "/home/tymoteusz/.local/lib/python3.6/site-packages/sqlalchemy/engine/base.py", line 1522, in _handle_dbapi_exception_noconnection
    util.raise_from_cause(sqlalchemy_exception, exc_info)
  File "/home/tymoteusz/.local/lib/python3.6/site-packages/sqlalchemy/util/compat.py", line 296, in raise_from_cause
    reraise(type(exception), exception, tb=exc_tb, cause=cause)
  File "/home/tymoteusz/.local/lib/python3.6/site-packages/sqlalchemy/util/compat.py", line 276, in reraise
    raise value.with_traceback(tb)
  File "/home/tymoteusz/.local/lib/python3.6/site-packages/sqlalchemy/engine/base.py", line 2221, in _wrap_pool_connect
    return fn()
  File "/home/tymoteusz/.local/lib/python3.6/site-packages/sqlalchemy/pool.py", line 356, in unique_connection
    return _ConnectionFairy._checkout(self)
  File "/home/tymoteusz/.local/lib/python3.6/site-packages/sqlalchemy/pool.py", line 811, in _checkout
    fairy = _ConnectionRecord.checkout(pool)
  File "/home/tymoteusz/.local/lib/python3.6/site-packages/sqlalchemy/pool.py", line 543, in checkout
    rec = pool._do_get()
  File "/home/tymoteusz/.local/lib/python3.6/site-packages/sqlalchemy/pool.py", line 1239, in _do_get
    self._dec_overflow()
  File "/home/tymoteusz/.local/lib/python3.6/site-packages/sqlalchemy/util/langhelpers.py", line 67, in __exit__
    compat.reraise(exc_type, exc_value, exc_tb)
  File "/home/tymoteusz/.local/lib/python3.6/site-packages/sqlalchemy/util/compat.py", line 277, in reraise
    raise value
  File "/home/tymoteusz/.local/lib/python3.6/site-packages/sqlalchemy/pool.py", line 1236, in _do_get
    return self._create_connection()
  File "/home/tymoteusz/.local/lib/python3.6/site-packages/sqlalchemy/pool.py", line 361, in _create_connection
    return _ConnectionRecord(self)
  File "/home/tymoteusz/.local/lib/python3.6/site-packages/sqlalchemy/pool.py", line 488, in __init__
    self.__connect(first_connect_check=True)
  File "/home/tymoteusz/.local/lib/python3.6/site-packages/sqlalchemy/pool.py", line 690, in __connect
    connection = pool._invoke_creator(self)
  File "/home/tymoteusz/.local/lib/python3.6/site-packages/sqlalchemy/engine/strategies.py", line 114, in connect
    return dialect.connect(*cargs, **cparams)
  File "/home/tymoteusz/.local/lib/python3.6/site-packages/sqlalchemy/engine/default.py", line 437, in connect
    return self.dbapi.connect(*cargs, **cparams)
sqlalchemy.exc.DatabaseError: (cx_Oracle.DatabaseError) DPI-1047: 64-bit Oracle Client library cannot be loaded: "libclntsh.so: cannot open shared object file: No such file or directory". See https://oracle.github.io/odpi/doc/installation.html#linux for help (Background on this error at: http://sqlalche.me/e/4xp6)

Process finished with exit code 1

我怎样才能解决我的问题?为什么终端在没有返回错误的情况下启动代码,而PyCharm返回与Oracle客户端库相关的错误。

任何帮助将不胜感激。

python sqlalchemy pycharm oracleclient
1个回答
1
投票

如果您在macOS上执行此操作(我从您设置DYLD_LIBRARY_PATH的方式猜测),那么您需要将Oracle Instant Client放在〜/ lib中,或者如cx_Oracle安装说明https://cx-oracle.readthedocs.io/en/latest/installation.html#install-oracle-instant-client中所述,因为现在macOS上的SIP安全性停止在子shell中工作的DYLD_LIBRARY_PATH。

我还建议使用Instant Client 12.2,除非您确实需要连接到非常旧的数据库版本。使用12.2客户端,您可以连接到Oracle DB 10.2或更高版本。

© www.soinside.com 2019 - 2024. All rights reserved.