首页 > 解决方案 > 在 Jupyter 笔记本中导入 cx_Oracle 会出现 ModuleNotFoundError

问题描述

我正在使用 jupyter notebook,我正在尝试在 jupyter book 中进行 sql 查询,但出现错误 在此处输入图像描述

标签: sqldatabasepandasoraclecx-oracle

解决方案


要在您自己的笔记本电脑上安装cx_Oracle最新版本 8.0.0,您需要已安装以下组件:

  • 蟒蛇 3x
  • Oracle Instant Client 11g 或更高版本。参考下载即时客户端版本到这个链接

https://www.oracle.com/database/technologies/instant-client/downloads.html

在 Windows 上下载和安装适用于 Python 的 cx_Oracle 包的步骤。就我而言,我更喜欢 GitHub 中提供的版本

https://github.com/oracle/python-cx_Oracle

1.点击下载 cx_Oracle 链接从 Github 下载包。它将一个 zip 文件下载到您的笔记本电脑中。

2.将 zip 文件解压缩到 Windows 上的文件夹中。例如,C:\cx_oracle。

3.现在打开命令提示符,将当前目录更改为 C:\cx_oracle 目录以安装 cx_Oracle 包。

4.然后运行以下命令。

python -m pip install cx_Oracle --upgrade pip

它将在 Windows 上安装适用于 Python 的 cx_Oracle 包,您将收到如下所示的消息。

Collecting pip
Downloading https://files.pythonhosted.org/packages/5f/25/e52d3f31441505a5f3af41213346e5b6c221c9e086a166f3703d2ddaf940/pip-18.0-py2.py3-none-any.whl (1.3MB)
100% |¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦| 1.3MB 2.5MB/s
Installing collected packages: pip
Found existing installation: pip 10.0.1
Uninstalling pip-10.0.1:
Successfully uninstalled pip-10.0.1
Successfully installed pip-18.0

重要的是,如果您有多个版本的 Python,请使用与 Jupyter 笔记本关联的版本。


推荐阅读