Build and Install cx_Oracle on Mac Leopard Intel
来源:互联网 发布:大麦盒子怎么装软件 编辑:程序博客网 时间:2024/05/16 18:29
Build and Install cx_Oracle on Mac Leopard Intel
I finally succeeded in building and installing cx_Oracle on a Mac. I will outline the steps that I took. There are many redundant steps that I may later take out. But there are checks that I made on the way that really helped.
The first Mac that I installed cx_Oracle was a 2.4 GHz Intel Core 2 Duo running Mac OSX 10.6.6. It had 4 GB of Memory. Most of my work was done on a terminal window.
Check Python Installation
The OSX comes with a Python interpreter. I ran a check to find the version number.
$ python -VPython 2.6.1This was sufficient for my needs. I decided not to upgrade to Python version 2.7.1
Xcode from Apple
The Xcode package is available from Apple Developer. You will need a login account but that is free. Now you do not need Xcode 4. Xcode 3 is sufficient because all we are interested in is the gcc compiler. After you login look for a link that says Looking for Xcode 3? I downloaded X code 3.2.6 and iOS SDK 4.3. It was 4.1 GB in size and is best done when you know you will not be using your Mac.
After the download, the installation went off smoothly. I restarted the Mac and on a terminal window checked that the gcc compiler was installed correctly.
$ which gcc/usr/bin/gcc$ gcc -vgcc version 4.2.1You can also do man gcc to get the online manual for gcc.
Install Oracle Instant Client
The cx_Oracle has a dependency. It needs Oracle Instant Client from Oracle. Click on the link Instant Client for Mac OS X (Intel x86). Accept the license agreement and download Version 10.2.0.4 (64-bit). I tried the 32-bit and it does NOT work. You will need your Oracle account to download the following packages:
- instantclient-basic-10.2.0.4.0-macosx-x64.zip
- instantclient-sdk-10.2.0.4.0-macosx-x64.zip
I created a directory called oracle to unpack the packages. The pathname on my machine was /Users/utcs/oracle. On your machine, it will be your user name instead of utcs. I moved both the basic and sdk packages into theoracle directory and unzipped them. After unzipping the basic package I got a folder instantclient_10_2.
After unzipping the sdk package, I got a folder called instantclient_10_2-1. Inside that folder was another folder called sdk. I moved the folder named sdk inside the folder instantclient_10_2.
From a terminal window I changed directory to sdk. On my machine, the full path name was /Users/utcs/oracle/instantclient_10_2/sdk. There is another .zip file called ottclasses.zip. I unzipped that as follows:
$ unzip ottclasses.zipIt produced a folder called oracle. I changed directory to /Users/utcs/oracle/instantclient_10_2. I ran the following command to copy all the files in the sdk folder.
$ cp -R ./sdk/* .$ cp -R ./sdk/include/* .The last two commands may not have been necessary. But it makes it easier to locate the header files.
Setting up the Environment Variables
In my home directory /Users/utcs I created a .profile file. Its content was as follows:
export ORACLE_HOME=/Users/utcs/oracle/instantclient_10_2export DYLD_LIBRARY_PATH=$ORACLE_HOMEexport LD_LIBRARY_PATH=$ORACLE_HOMERestart the machine. Open another terminal window and run the following commands to check that the environment variables have been set properly:
$ source .profile$ echo $ORACLE_HOME$ echo $DYLD_LIBRARY_PATH$ echo $LD_LIBRARY_PATHYou should see the path names printed out correctly. I created two symbolic links in the $ORACLE_HOME directory (/Users/utcs/oracle/instantclient_10_2) as follows:
ln -s libclntsh.dylib.10.1 libclntsh.dylibln -s libocci.dylib.10.1 libocci.dylibIf you run the command ls -l in that directory you should see the symbolic links.
Building and Installing cx_Oracle
Download from SourceForge cx_Oracle version 5.0.4. You need to get the package that says Source Code only. In your Download folder you will find cx_Oracle-5.0.4.tar. I moved it to /Users/utcs/oracle. To untar, I used the following command:
tar -xvf cx_Oracle-5.0.4.tar
After untarring I had a subdirectory called cx_Oracle-5.0.4. In a terminal window I changed directory to /Users/utcs/oracle/cx_Oracle-5.0.4. I checked in that window that all the environment variables were set properly by doing
echo $ORACLE_HOMEecho $LD_LIBRARY_PATHecho $DYLD_LIBRARY_PATHwhich pythonwhich gccI did not have administrative privileges on this Mac so to build I did
python setup.py buildI checked to output. There were many warning messages that I ignored. Even a single error message would have indicated that the build process did not succeed. I next installed cx_Oracle by
python setup.py installThe install also finished without any error messages.
Test the cx_Oracle installation
On a terminal window type python. It should bring up Python in interactive mode. Then type import cx_Oracle. It should add the package to your path without any errors. Get out of the interactive mode using Control-D.
Now copy and paste this script into a file called Check.py. Change the user name and run it on the command line.
import cx_Oracle, string, getpassdef main(): # Get password pswd = getpass.getpass() # Build connection string user = "CS327E_jdoe" host = "rising-sun.microlab.cs.utexas.edu" port = "1521" sid = "orcl" dsn = cx_Oracle.makedsn (host, port, sid) # Connect to Oracle and test con = cx_Oracle.connect (user, pswd, dsn) if (con): print "Connection successful" print con.version else: print "Connection not successful" con.close()main()
You should see Connection successful if all the other tests were successful.
I followed the instructions listed here (using the 32-bit downloads from Oracle):http://www.xairon.net/2011/05/guide-installing-cx_oracle-on-mac-os-x/
I then had the same error you listed:
ImportError: dlopen(/Library/Python/2.7/site-packages/cx_Oracle.so, 2): Symbol not found: _OCIAttrGet Referenced from: /Library/Python/2.7/site-packages/cx_Oracle.so Expected in: flat namespace in /Library/Python/2.7/site-packages/cx_Oracle.so
The problem was from Apple's Python distribution running in 64-bit mode by default.
Once I forced the Apple supplied Python to use 32-bit (from Ned's recommendation), it worked!
To do that:
$export VERSIONER_PYTHON_PREFER_32_BIT=Yes
To make it permanent:
$defaults write com.apple.versioner.python Prefer-32-Bit -bool yes
- Build and Install cx_Oracle on Mac Leopard Intel
- Build and Install cx_Oracle on Mac Leopard Intel
- install Oracle and cx_oracle on Mac
- Install Apache/PHP/MySQL on Mac Snow Leopard
- install ipython and readline on mac
- Install Apache/PHP/MySQL on Mac Snow Leopard--为了方便以后配置
- install snow leopard on thinkpad x201
- How to build and install Open vSwitch on a linux
- Build and install gcc on FEDORA 14 X84_64
- Install “build-essential” on RHEL/CentOS and OpenSolaris
- IE on mac os x(snow leopard)
- build and install tmux
- install and use junit on MAC without IDE
- How to Install VirtualBox and Windows on your Mac
- How to install and config X11 on Mac
- Install and Run Scapy on Mac OS X 10.10 (Yosemite)
- Install PEAR and PECL on Mac OS X
- Install and config Redis on Mac OS X via Homebrew
- MAC mysql安装及设置
- WinAPI: WinExec - 运行外部程序
- C 数组
- 作为软件工程师,你必须知道的20个常识
- 用多媒体库 Bass.dll 播放 mp3 : 如何从内存流播放
- Build and Install cx_Oracle on Mac Leopard Intel
- 开发者必知:提升Android应用开发性能的十大要点
- opencv形状分析
- hibernate 多对多关系
- Guide to Setup Gmail IMAP in Outlook 2010
- 高效程序员的40个好习惯和行为方式
- 正则表达式,30分钟教程
- QTP_QTP论坛
- POJ1050