I try to write a script in .py for oracle connectivity:
我尝试用.py为oracle连接性编写一个脚本:
#!/usr/bin/python
import cx_Oracle
connstr='username/pwd@database'
conn = cx_Oracle.connect(connstr)
curs = conn.cursor()
curs.execute('select * from table1;')
print curs.description
for row in curs:
print row
conn.close()
I get the following error:
我得到以下错误:
Traceback (most recent call last):
File "test_SQLPython.py", line 3, in ?
import cx_Oracle
ImportError: No module named cx_Oracle
Any help would be appreciated? Thanks.
需要帮忙吗?谢谢。
8 个解决方案
#1
2
I had a similar problem, you gotta make sure you have:
我也有类似的问题,你要确保你有:
- oracle instant client
- oracle即时客户端
- cx_Oracle binary( from SourceForge )
- cx_Oracle二进制(来自SourceForge)
- Python IMPORTANT: Make sure they are ALL either 64-bit or 32-bit, mixing is gonna cause problems
- Python的重要性:确保它们都是64位或32位的,混合将导致问题
#2
2
Windows help:
Windows帮助:
- Get the instant client. It has no install exe. Just copy it somewhere.
- 获得即时的客户。它没有安装exe。复制它。
- Put the directory into your PATH variable.
- 将目录放入路径变量中。
-
Go to the command prompt and set 2 variables - for example:
转到命令提示符并设置2个变量——例如:
TNS_ADMIN=C:\instant_client\instantclient_11_2
ORACLE_HOME=C:\instant_client\instantclient_11_2
TNS_ADMIN = C:\ instant_client \ instantclient_11_2 ORACLE_HOME = C:\ instant_client \ instantclient_11_2
Then install the cx_Oracle module from an exe. If you use pip or easy_install, ...good luck.
然后从exe中安装cx_Oracle模块。如果您使用pip或easy_install,…祝你好运。
You can get the installer here: https://pypi.python.org/pypi/cx_Oracle/5.1.3
您可以在这里获得安装程序:https://pypi.python.org/pypi/cx_Oracle/5.1.3
#3
1
To access Oracle from python you need (additionally) the cx_Oracle module. The module must be located either in the system python path or you have to set the PYTHONPATH appropriate.
要从python访问Oracle,您需要(另外)cx_Oracle模块。模块必须位于系统python路径中,或者必须设置适合的PYTHONPATH。
#4
1
I have just faced the same problem. First, you need to install the appropriate Oracle client for your OS. In my case, to install it on Ubuntu x64 I have followed this instructions https://help.ubuntu.com/community/Oracle%20Instant%20Client#Install_RPMs
我刚刚遇到了同样的问题。首先,需要为操作系统安装适当的Oracle客户端。在我的例子中,要在Ubuntu x64上安装它,我遵循了以下指令:https://help.ubuntu.com/community/Oracle%20Instant%20Client#Install_RPMs
Then, you need to install cx_Oracle, a Python module to connect to the Oracle client. Again, assuming you are running Ubuntu in a 64bit machine, you should type in a shell:
然后,您需要安装cx_Oracle,这是一个连接到Oracle客户端的Python模块。同样,假设你在一个64位的机器上运行Ubuntu,你应该输入一个shell:
wget -c http://prdownloads.sourceforge.net/cx-oracle/cx_Oracle-5.0.4-11g-unicode-py27-1.x86_64.rpm
sudo alien -i cx_Oracle-5.0.4-11g-unicode-py27-1.x86_64.rpm
This will work for Oracle 11g if you have installed Python 2.7.x, but you can download a different cx_Oracle version in http://cx-oracle.sourceforge.net/ To check which Python version do you have, type in a terminal:
如果您已经安装了Python 2.7,这将适用于Oracle 11g。但是你可以在http://cx-oracle.sourceforge.net/下载一个不同的cx_Oracle版本来检查你有哪个Python版本,输入一个终端:
python -V
I hope it helps
我希望这有助于
#5
1
Unknown92 answer helped me (on windows). Note that all versions must fit.
答案在windows上帮助了我。注意,所有版本都必须适合。
I've downloaded cx_Oracle here, for me the file cx_Oracle-5.2.1-12c.win-amd64-py3.5.exe worked with:
我在这里下载了cx_Oracle,为我的文件cx_orac -5.2.1-12c.win-amd64-py3.5。exe共事:
- Python 3.5.1 64bit. for some reason the default download link from the main page is for the 32bit version.
- Python 3.5.1 64位。出于某种原因,主页上的默认下载链接用于32位版本。
- And oracle instance client 12.1.0.2.0 (the file named instantclient-basic-windows.x64-12.1.0.2.0.zip) here.
- 这里还有oracle实例客户机12.1.0.2.0(名为instantclient-basic-windows.x64- 12.1.0.2.0.0 .zip)。
#6
1
Tried installing it via rpm posted in above answers, but it didn't worked. What worked instead is plain pip install
.
尝试在上面的答案中安装它,但是没有成功。取而代之的是简单的pip安装。
pip install cx_oracle
The above command installed cx_oracle=6.1
Please note that I'm using python 2.7.14 Anaconda release
and oracle 12c
.
上面的命令安装了cx_oracle=6.1请注意,我使用的是python 2.7.14 Anaconda发行版和oracle 12c。
#7
0
For me the problem was that I had installed cx_Oracle via DOS pip which changed it to lower case. Installing it through Git Bash instead kept the mixed case.
对我来说,问题是我已经通过DOS pip安装了cx_Oracle,它将其更改为小写。通过Git Bash安装它,反而保持了混合情况。
#8
0
Windows and Anaconda help
Windows和蟒蛇帮助
Anaconda 4.3.0 comes with Python 3.6 as the root. Currently cx_Oracle only supports up to 3.5. I tried creating 3.5 environment in envs, but when running cx_Oracle-5.2.1-11g.win-amd64-py3.5.exe it installs in root only against 3.6
Anaconda 4.3.0以Python 3.6为根。目前cx_Oracle只支持3.5。我尝试在envs中创建3.5环境,但是在运行cx_Oracle-5.2.1-11g.win-amd64-py3.5时。exe它只在3.6的基础上安装
Only workaround I could find was to change the root environment from 3.6 to 3.5:
我能找到的唯一解决办法是将根环境从3.6改为3.5:
activate root
conda update --all python=3.5
When that completes run cx_Oracle-5.2.1-11g.win-amd64-py3.5.exe.
完成后运行cx_oracle - 5.1 -11g.win-amd64-py3.5.exe。
Tested it with import and worked fine.
用进口测试,效果良好。
import CX_Oracle
#1
2
I had a similar problem, you gotta make sure you have:
我也有类似的问题,你要确保你有:
- oracle instant client
- oracle即时客户端
- cx_Oracle binary( from SourceForge )
- cx_Oracle二进制(来自SourceForge)
- Python IMPORTANT: Make sure they are ALL either 64-bit or 32-bit, mixing is gonna cause problems
- Python的重要性:确保它们都是64位或32位的,混合将导致问题
#2
2
Windows help:
Windows帮助:
- Get the instant client. It has no install exe. Just copy it somewhere.
- 获得即时的客户。它没有安装exe。复制它。
- Put the directory into your PATH variable.
- 将目录放入路径变量中。
-
Go to the command prompt and set 2 variables - for example:
转到命令提示符并设置2个变量——例如:
TNS_ADMIN=C:\instant_client\instantclient_11_2
ORACLE_HOME=C:\instant_client\instantclient_11_2
TNS_ADMIN = C:\ instant_client \ instantclient_11_2 ORACLE_HOME = C:\ instant_client \ instantclient_11_2
Then install the cx_Oracle module from an exe. If you use pip or easy_install, ...good luck.
然后从exe中安装cx_Oracle模块。如果您使用pip或easy_install,…祝你好运。
You can get the installer here: https://pypi.python.org/pypi/cx_Oracle/5.1.3
您可以在这里获得安装程序:https://pypi.python.org/pypi/cx_Oracle/5.1.3
#3
1
To access Oracle from python you need (additionally) the cx_Oracle module. The module must be located either in the system python path or you have to set the PYTHONPATH appropriate.
要从python访问Oracle,您需要(另外)cx_Oracle模块。模块必须位于系统python路径中,或者必须设置适合的PYTHONPATH。
#4
1
I have just faced the same problem. First, you need to install the appropriate Oracle client for your OS. In my case, to install it on Ubuntu x64 I have followed this instructions https://help.ubuntu.com/community/Oracle%20Instant%20Client#Install_RPMs
我刚刚遇到了同样的问题。首先,需要为操作系统安装适当的Oracle客户端。在我的例子中,要在Ubuntu x64上安装它,我遵循了以下指令:https://help.ubuntu.com/community/Oracle%20Instant%20Client#Install_RPMs
Then, you need to install cx_Oracle, a Python module to connect to the Oracle client. Again, assuming you are running Ubuntu in a 64bit machine, you should type in a shell:
然后,您需要安装cx_Oracle,这是一个连接到Oracle客户端的Python模块。同样,假设你在一个64位的机器上运行Ubuntu,你应该输入一个shell:
wget -c http://prdownloads.sourceforge.net/cx-oracle/cx_Oracle-5.0.4-11g-unicode-py27-1.x86_64.rpm
sudo alien -i cx_Oracle-5.0.4-11g-unicode-py27-1.x86_64.rpm
This will work for Oracle 11g if you have installed Python 2.7.x, but you can download a different cx_Oracle version in http://cx-oracle.sourceforge.net/ To check which Python version do you have, type in a terminal:
如果您已经安装了Python 2.7,这将适用于Oracle 11g。但是你可以在http://cx-oracle.sourceforge.net/下载一个不同的cx_Oracle版本来检查你有哪个Python版本,输入一个终端:
python -V
I hope it helps
我希望这有助于
#5
1
Unknown92 answer helped me (on windows). Note that all versions must fit.
答案在windows上帮助了我。注意,所有版本都必须适合。
I've downloaded cx_Oracle here, for me the file cx_Oracle-5.2.1-12c.win-amd64-py3.5.exe worked with:
我在这里下载了cx_Oracle,为我的文件cx_orac -5.2.1-12c.win-amd64-py3.5。exe共事:
- Python 3.5.1 64bit. for some reason the default download link from the main page is for the 32bit version.
- Python 3.5.1 64位。出于某种原因,主页上的默认下载链接用于32位版本。
- And oracle instance client 12.1.0.2.0 (the file named instantclient-basic-windows.x64-12.1.0.2.0.zip) here.
- 这里还有oracle实例客户机12.1.0.2.0(名为instantclient-basic-windows.x64- 12.1.0.2.0.0 .zip)。
#6
1
Tried installing it via rpm posted in above answers, but it didn't worked. What worked instead is plain pip install
.
尝试在上面的答案中安装它,但是没有成功。取而代之的是简单的pip安装。
pip install cx_oracle
The above command installed cx_oracle=6.1
Please note that I'm using python 2.7.14 Anaconda release
and oracle 12c
.
上面的命令安装了cx_oracle=6.1请注意,我使用的是python 2.7.14 Anaconda发行版和oracle 12c。
#7
0
For me the problem was that I had installed cx_Oracle via DOS pip which changed it to lower case. Installing it through Git Bash instead kept the mixed case.
对我来说,问题是我已经通过DOS pip安装了cx_Oracle,它将其更改为小写。通过Git Bash安装它,反而保持了混合情况。
#8
0
Windows and Anaconda help
Windows和蟒蛇帮助
Anaconda 4.3.0 comes with Python 3.6 as the root. Currently cx_Oracle only supports up to 3.5. I tried creating 3.5 environment in envs, but when running cx_Oracle-5.2.1-11g.win-amd64-py3.5.exe it installs in root only against 3.6
Anaconda 4.3.0以Python 3.6为根。目前cx_Oracle只支持3.5。我尝试在envs中创建3.5环境,但是在运行cx_Oracle-5.2.1-11g.win-amd64-py3.5时。exe它只在3.6的基础上安装
Only workaround I could find was to change the root environment from 3.6 to 3.5:
我能找到的唯一解决办法是将根环境从3.6改为3.5:
activate root
conda update --all python=3.5
When that completes run cx_Oracle-5.2.1-11g.win-amd64-py3.5.exe.
完成后运行cx_oracle - 5.1 -11g.win-amd64-py3.5.exe。
Tested it with import and worked fine.
用进口测试,效果良好。
import CX_Oracle