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?
问题:
回答1:
Honestly it is a hell of a lot easier to install cx_Oracle from one of the binary installers they have, than from source.
HOWTO for *nix:
Browse to Instant Client for Linux x86 download page.
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/
Fix oracle's includes:
$ 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
.
HOWTO Install cx_Oracle
Assuming we have installed Oracle Instant Client 10, you have different alternatives to install cx_Oracle:
- Install with pip:
$ pip install cx_oracle
(linux only) - Download the installer/.tar.gz file from the cx_oracle PyPI site
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'
should return the modules with its version.
回答2:
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)
- download the oracle client from http://www.oracle.com/technetwork/database/enterprise-edition/downloads/112010-win32soft-098987.html(link for32 bit version) download and extract the zip files in one folder
- the zip files are extracted to 'installation' in this case
the directory will appear like this
click on install and set the path to 'base' and 'software' directories
- software directory should be inside base directory(recommended)
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'
- in cmd check 'echo %ORACLE_HOME%' to see if the path is set properly
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
- set an environment variable with the name ' VS100COMNTOOLS' with value as 'C:\Users\Administrator\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0'
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
回答3:
- Download oracle instant client (for 32bit or 64bit archtitect and appropriate version of Oracle (10g,11g,12g)). http://www.oracle.com/technetwork/topics/winx64soft-089540.html
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 e.g. 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 e.g. 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