How to install both MySQLdb and cx_Oracle on Mountain Lion? - osx-mountain-lion

I've been trying for days to get both MySQLdb and cx_Oracle running successfully together on Mountain Lion to no avail. It appears that I can only get one or the other to run but not both. Here are my specs...
Mac OS X 10.8.2 running with (64-bit) Intel Core i7 processor
PYTHON:
~: python --version
Python 2.7.2
~: file which python
/usr/bin/python: Mach-O universal binary with 2 architectures
/usr/bin/python (for architecture i386): Mach-O executable i386
/usr/bin/python (for architecture x86_64): Mach-O 64-bit executable x86_64
In .bashrc, I have set the following...
export VERSIONER_PYTHON_PREFER_32_BIT=yes
MySQL:
~: mysql --version
mysql Ver 14.14 Distrib 5.1.63, for apple-darwin10.3.0 (i386) using readline 5.1
~: file which mysql
/usr/local/mysql/bin/mysql: Mach-O 64-bit executable x86_64
MySQLdb:
~: file /Library/Python/2.7/site-packages/_mysql.so
/Library/Python/2.7/site-packages/_mysql.so: Mach-O 64-bit bundle x86_64
Oracle:
Version 10.2.0.4 (32-bit) Instant Client and SDK
I used pip to install both cx_Oracle and mysql-python (MySQLdb). Currently, I can interactively import cx_Oracle successfully, however, I get the following error when attempting to interactively import MySQLdb:
Traceback (most recent call last):
File "", line 1, in
File "/Library/Python/2.7/site-packages/MySQLdb/init.py", line 19, in
import _mysql
ImportError: dlopen(/Library/Python/2.7/site-packages/_mysql.so, 2): no suitable image found. Did find:
/Library/Python/2.7/site-packages/_mysql.so: mach-o, but wrong architecture
After all the reading and troubleshooting I've done, I have learned that this error surfaces when Python and MySQL are not running on the same architecture. Since I have the 64-bit version of MySQL, I can remove the environment variable I put in .bashrc that sets the preference to the 32-bit version of Python (export VERSIONER_PYTHON_PREFER_32_BIT=yes) and the MySQLdb import works. However, I then get the following error when importing cx_Oracle:
Traceback (most recent call last):
File "", line 1, in
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
When diving into this rabbit hole I find conflicting information about what I have set-up for cx_Oracle, what needs 32-bit architecture and what needs 64-bit tracing all the way back to my Oracle installation. I've encountered the segmentation fault error, the libclntsh.dylib error and the clang error etc. Perhaps, at this point, the information overload has sent me in circles so long that I can't clearly see the solution? But I know there has to be a way...
I thank you in advance for any assistance at all with this.
Cheers!

you wrote:
/usr/local/mysql/bin/mysql: Mach-O 64-bit executable x86_64
You have to install MySql 32 bits as you did for cx_Oracle and keep
export VERSIONER_PYTHON_PREFER_32_BIT=yes

Related

Switching GCC version to use on macbook M1

I received this error when I tried to compile by gcc 11.x and run some code on my Macbook Pro M1
E ImportError: dlopen(/Users/giangpham/VSCode/rpxdock/rpxdock/bvh/bvh.cpython-37m-darwin.so, 0x0006): tried: ‘/Users/giangpham/VSCode/rpxdock/rpxdock/bvh/bvh.cpython-37m-darwin.so’ (mach-o file, but is an incompatible architecture (have ‘arm64’, need ‘x86_64’))
I tried to install another homebrew for x86_64 architecture and install the old gcc ver 9 (which is the version recorded to have worked with the code before) following this article
I have done axbrew info gcc and it would still give out information of the 11.x gcc (axbrew info gcc#9 works and gives me info of the package. But I tried switch`` as the article suggested and it saids unknown command```). How do I switch gcc to use the older version I just installed?
Thank you!

Library not loaded: /usr/local/opt/libpng/lib/libpng16.16.dylib

Main error
Process failed:
dyld[29269]: Library not loaded: /usr/local/opt/libpng/lib/libpng16.16.dylib
Referenced from: /Users/hanbing/opt/anaconda3/envs/brainreg/lib/python3.9/site-packages/brainreg/bin/nifty_reg/osX/reg_aladin
Reason: tried: '/usr/local/opt/libpng/lib/libpng16.16.dylib' (mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64')), '/usr/local/lib/libpng16.16.dylib' (no such file), '/usr/lib/libpng16.16.dylib' (no such file), '/opt/homebrew/Cellar/libpng/1.6.37/lib/libpng16.16.dylib' (mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64')), '/usr/local/lib/libpng16.16.dylib' (no such file), '/usr/lib/libpng16.16.dylib' (no such file)
Tried brew install libpng $ brew update $ brew upgrade libpng . None of them work.
Laptop information:
OS: macOS, M1 CPU
Version: 12.0.1
Hardware specs: 1 TB flash storage and external
2TB USB DISK
Python version: 3.9
Thanks!
I guess you migrate from an Intel Mac to M1 Mac. After upgrade Mac version also can meet some libs error.
This is because brew install some libs maybe using compile source code as binary file, this file only works to specific platform.
Maybe you can reinstall it, brew reinstall libpng.

Cannot execute Linux binary file on MacBook Air M1

I have a third party library file compiled for Linux, when I tried to execute using terminal I get the error:
cannot execute binary file:
File details are as follows:
ELF 64-bit LSB pie executable, x86-64, version 1 (GNU/Linux),
dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for
GNU/Linux 3.2.0, BuildID[sha1]=820d7e089c6c3cdc19fa3e759ccae22fbc672652,
with debug_info, not stripped
I tried installing Rosetta, tried running with the command with a prefix arch -x86_64
but it resulted in the same error.
If I try to execute them on the terminal application directly, it shows the error:
zsh: exec format error:

Linking against XCode dylibs with Python ctypes

I am installing Pyglet as a dependency for VisPy but am seeing the following error after installation
File "/Library/Python/2.7/site-packages/pyglet/lib.py", line 160, in load_library
raise ImportError('Library "%s" not found.' % names[0])
ImportError: Library "c" not found.
Digging through the source code, I realized that Pyglet is attempting to load the standard C library using the ctypes framework.
Further digging reveals the actual (un-swallowed) error:
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ctypes/__init__.py", line 365, in __init__
self._handle = _dlopen(self._name, mode)
OSError: dlopen(/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/lib/libc.dylib, 6): no suitable image found. Did find:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/lib/libc.dylib: mach-o, but wrong filetype
The issue, I think, is similar to this question where there is an architecture mismatch. The Python C binding framework 'ctypes' is attempting to load a .dylib with the wrong architecture.
Since I have set $LD_LIBRARY_PATH to
/Applications.../MacOSX10.10.sdk/usr/lib/
the loader is favoring this directory. However, if I try to load 'libc.dylib' from the standard location /usr/lib everything works perfectly.
The obvious potential problem is that the XCode version of 'libc' is for the 32-bit architecture but the /usr/lib is for the 64-bit architecture.
Not true!
Here is the output of file for both libraries:
XCode version
libc.dylib: Mach-O universal binary with 2 architectures
libc.dylib (for architecture x86_64): Mach-O 64-bit dynamically linked shared library stub x86_64
libc.dylib (for architecture i386): Mach-O dynamically linked shared library stub i386
and the standard in /usr/lib
/usr/lib/libc.dylib: Mach-O universal binary with 2 architectures
/usr/lib/libc.dylib (for architecture x86_64): Mach-O 64-bit dynamically linked shared library x86_64
/usr/lib/libc.dylib (for architecture i386): Mach-O dynamically linked shared library i386
The only difference is that the XCode version is a "stub". Despite some googling, the difference is not entirely clear, though it appears that the difference between a "stub" dylib and a "non-stub" is what is causing the problem.
A bit more information about my setup:
/usr/bin/python : Python 2.7.10 and appears to be running as a 64-bit app
uname -a: Darwin x-10-104-106-204.uofm-secure.wireless.umn.edu 14.5.0 Darwin Kernel Version 14.5.0: Wed Jul 29 02:26:53 PDT 2015; root:xnu-2782.40.9~1/RELEASE_X86_64 x86_64
My question is thus how does one properly link against the dylibs installed by XCode?
Thanks in advance for all ideas and suggestions.

Install Ruby 1.9.2 on Snow Leopard

I'm trying to install Ruby 1.9.2 on Snow Leopard and the infamous problem arose. I'm saying famous because I found lot of similar problems on the web, but no solution worked for me yet.
Upon trying to install from RVM or compiling directly, I get lot of warnings like this
tcltklib.c:8143: warning: implicit conversion shortens 64-bit value into a 32-bit value
and at the end this error
/usr/local/lib/libsqlite3.dylib, file was built for unsupported file format which is not the architecture being linked (x86_64) for architecture x86_64
collect2: ld returned 1 exit status
I tried setting the ARCHFLAGS="-arch x86_64" in the .bash_profile file, and reinstalling sqlite3.
Any idea?
Try installing sqlite3 as 64-bit as mentioned here:
http://www.markhneedham.com/blog/2010/07/08/installing-ruby-1-9-2-with-rvm-on-snow-leopard/

Resources