So I found Help installing cx_Oracle but am still stuck. I downloaded the latest instantclient from oracle, and set ORACLE_HOME to the location of the extracted files (both direct and with a bin folder between the ORACLE_HOME value and the files), but easy_install is popping an error when running setup.py saying it can't locate the Oracle include files. I did notice that only the 11g dll is in the folder, do I need all 3 drivers present for setup to complete? If so, where do I even get them?
Honestly it is a hell of a lot easier to install cx_Oracle from one of the binary installers they have, than from source.
Download the latest version of basic, sqlplus and sdk packages that fit your architecture (32 or 64bits):
oracle-instantclient<version>-basic-<version_full>.<arch>.rpm
oracle-instantclient<version>-sqlplus-<version_full>.<arch>.rpm
oracle-instantclient<version>-devel-<version_full>.<arch>.rpm
. Install the RPMs using alien. For example, at the time of this writing:
$ sudo alien -i oracle-instantclient12.1-basic-12.1.0.2.0-1.x86_64.rpm
Add necessary environment variables (I personally did put it in /etc/environment
then logoff/back in to reload the env):
ORACLE_HOME=/usr/lib/oracle/<version>/client64/lib/ LD_LIBRARY_PATH=/usr/lib/oracle/<version>/client64/lib/
$ sudo ln -s /usr/include/oracle/<version>/client $ORACLE_HOME/include # for 32bits arch, OR $ sudo ln -s /usr/include/oracle/<version>/client64 $ORACLE_HOME/include # for 64bits arch
Create /etc/ld.so.conf.d/oracle-instantclient<version>-basic.conf
and /etc/ld.so.conf.d/oracle.conf
(for more recent versions, at least since 12.1) containing:
/lib /usr/lib/oracle/<version>/client/lib; for 32bits arch, OR /usr/lib/oracle/<version>/client64/lib; for 64bits arch
Reload ldconfig cache (use -v
flag if you want some verbose):
$ sudo ldconfig
You might need to install libaio1
.
Assuming we have installed Oracle Instant Client 10, you have different alternatives to install cx_Oracle :
$ pip install cx_oracle
(linux only)Older versions (version less than 5.1.2 are.msi and.rpm files) can be downloaded from here . Install the RPMs using alien. For example, at the time of this writing: $ sudo alien -i cx_Oracle-5.0-10g-py25-1.x86.rpm
To test, python -c 'import cx_Oracle; print cx_Oracle'
python -c 'import cx_Oracle; print cx_Oracle'
should return the modules with its version.
step 1 check python is 32 bit or 64
import platform
platform.architecture()[0]#'32bit'
or step 2 install oracle client (32 bit or 64 bit depends on python version from step1)
the directory will appear like this
click on install and set the path to 'base' and 'software' directories
in this case 'installed' directory is base and 'software' directory is for software path
set ORACLE_HOME path:
set the oracle home path to the 'software' directory as 'F:\softwares\oracle11g32\installed\software'
step 3 install vcforpython27 or visual c++ 2008 express edition for python 2.7
download it from here https://www.microsoft.com/en-sa/download/details.aspx?id=44266 (used this in this case to avoid installation of whole visual c++ 2008 as mentioned in below)
it is a small package that contains c++ compilers for python 2.7
(Or)
visual c++ 2008 express edition ( https://www.microsoft.com/en-sa/download/details.aspx?id=5582 ) [it will around a 1 GB installation]
vcforpython27 will installed at 'C:\Users\Administrator\AppData\Local\Programs\Common\Microsoft'
enable show hidden folder in windows to this these directories
it should point to the point to the directory containing 'vcvarsall' batch file
echo %VS100COMNTOOL% to see if is pointing to the right directory in cmd
And do the steps below:(from: error: Unable to find vcvarsall.bat )
go to C:/Python27/lib/distutils the file msvc9compiler.py. Find in it the function find_vcvarsall and do following modification. Replace the line: productdir = os.path.join(toolsdir, os.pardir, os.pardir, "VC") with productdir = os.path.join(toolsdir) This is where vcvarsall.bat resides in this case (check, where vcvarsall.bat is in your installation).
install cx_Oracle
the easy step: pip install cx_oracle
if all the above steps are followed properly, then it should work. It took lot of pain to figure this out. I hope it will be useful.
recommended to run:
pip install --upgrade setuptools
from : https://stackoverflow.com/questions/2667069/cannot-find-vcvarsall-bat-when-running-a-python-script
Note: Requires an user to authenticate with an OTN (oracle tech network account).
1.1. Download and unzip "Instant Client Package - Basic" to C:\Python27\Scripts\instantclient_11_2 eg instantclient-basic-windows.x64-11.2.0.4.0.zip
1.2. Download and unzip "Instant Client Package - SDK" to C:\Python27\Scripts\instantclient_11_2 eg instantclient-sdk-windows.x64-11.2.0.4.0.zip
set ORACLE_HOME=C:\Python27\Scripts\instantclient_11_2
python -m pip install cx_Oracle
Output on success: Collecting cx_Oracle Using cached cx_Oracle-5.2.1.tar.gz Building wheels for collected packages: cx-Oracle Running setup.py bdist_wheel for cx-Oracle... done Stored in directory: C:\Users\m315468\AppData\Local\pip\Cache\wheels\7c\5f\96\ cd273c9b675bc7c28ae249b74d1f7df5d3eacba9e918715225 Successfully built cx-Oracle Installing collected packages: cx-Oracle Successfully installed cx-Oracle-5.2.1
After struggling I found below method. I am using Windows and have separate environment for django.
run all below command one by one to test connection, mind the indentation at the last for loop.
import cx_Oracle connection = cx_Oracle.connect("your_username", "your_psw", "localhost/orcl") cursor = connection.cursor() cursor.execute("""select to_char(sysdate, 'dd-mon-yyyy') from dual""") for cdate in cursor: print("Today the date is ", cdate)
Output:
Today the date is ('08-nov-2019',)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.