I want to get MySQL working with the system Python 2.7 in Mac OS X Lion.
I know there are a lot of questions very similar to this out there, and in fact my symptom is identical to mysql-python installation problems (on mac os x lion). However, that answer doesn't seem to apply to my case.
My Mac is a current MacBook Pro running the 64-bit kernel:
% uname -a
Darwin Leos-MacBook-Pro.local 11.2.0 Darwin Kernel Version 11.2.0: Tue Aug 9 20:54:00 PDT 2011; root:xnu-1699.24.8~1/RELEASE_X86_64 x86_64
The stock python on Lion is a fat binary:
% file /usr/bin/python
/usr/bin/python: Mach-O universal binary with 2 architectures
/usr/bin/python (for architecture x86_64): Mach-O 64-bit executable x86_64
/usr/bin/python (for architecture i386): Mach-O executable i386
I had used Migration Assistant so my system had an old installation of MySQL on it. I used the instructions at How to remove installation of MySQL on Mac OS X to remove the old MySQL installation.
MySQL 64-bit 5.5.19 was installed from the .dmg on the MySQL site. As usual, this placed the client library in /usr/local/mysql/lib. The client library appears to be exactly what we want:
% file /usr/local/mysql/lib/libmysqlclient.18.dylib
/usr/local/mysql/lib/libmysqlclient.18.dylib: Mach-O 64-bit dynamically linked shared library x86_64
However, that shared library can't be loaded into python (I'm using the arch command to make absolutely sure I'm running the 64-bit image although the result is the same with or without that):
% arch -x86_64 python
Python 2.7.1 (r271:86832, Jul 31 2011, 19:30:53)
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from ctypes import cdll
>>> cdll.LoadLibrary("/usr/local/mysql/lib/libmysqlclient.18.dylib")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ctypes/__init__.py", line 431, in LoadLibrary
return self._dlltype(name)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ctypes/__init__.py", line 353, in __init__
self._handle = _dlopen(self._name, mode)
OSError: dlopen(/usr/local/mysql/lib/libmysqlclient.18.dylib, 6): no suitable image found. Did find:
/usr/local/mysql/lib//libmysqlclient.18.dylib: mach-o, but wrong architecture
/usr/local/mysql/lib/libmysqlclient.18.dylib: mach-o, but wrong architecture
I can reproduce this problem many other ways, notably by using the standard import MySQLdb; I'm showing the ctypes way of reproducing the bug specifically because I was trying to figure out whether the problem was in mysql-python or in the MySQL client library. From the above, it seems to be the client library. However, I'm baffled as to why the loader thinks the client library is the wrong architecture.
In trying to see whether it's some dependent library that's the problem, I checked the dependencies in libmysqlclient.18.dylib:
% otool -L /usr/local/mysql/lib/libmysqlclient.18.dylib
/usr/local/mysql/lib/libmysqlclient.18.dylib:
libmysqlclient.18.dylib (compatibility version 18.0.0, current version 18.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 125.0.1)
And of course /usr/lib/libSystemB.dylib is a fat binary as expected:
% file /usr/lib/libSystem.B.dylib
/usr/lib/libSystem.B.dylib: Mach-O universal binary with 2 architectures
/usr/lib/libSystem.B.dylib (for architecture x86_64): Mach-O 64-bit dynamically linked shared library x86_64
/usr/lib/libSystem.B.dylib (for architecture i386): Mach-O dynamically linked shared library i386
So... Python is 64-bit, the mysqlclient library is 64-bit, and the dependent libraries are all 64-bit... Any guesses as to why the loader is refusing the import the library would be very welcome.
Just for the belt-and-suspenders checking that everything's 64-bit-y:
% python -c 'import platform; print platform.platform()'
Darwin-11.2.0-x86_64-i386-64bit
% ls -l /usr/local/mysql
lrwxr-xr-x 1 root wheel 27 Dec 10 16:52 /usr/local/mysql# -> mysql-5.5.19-osx10.6-x86_64
At this point, since I need to actually get some work done, I'm going to try switching to pymysql. This is mostly for use with Django, for which there's a convenient way to swap pymysql in documented at the bottom of this thread.
P.S. I understand macports and can't use it on this system.
Chances are you have set the default execution mode of the Apple-supplied Python to 32-bits, either by using defaults or by setting the VERSIONER_PYTHON_PREFER_32_BIT environment variable; see man python for details. In OS X 10.6 and 10.7 /usr/bin/python is an Apple-supplied wrapper program that determines which Python to run and in which mode. Using arch to execute /usr/bin/python will not influence the interpreter. For example:
$ unset VERSIONER_PYTHON_PREFER_32_BIT
$ arch -x86_64 /usr/bin/python -c "import sys;print(sys.maxsize)"
9223372036854775807
$ export VERSIONER_PYTHON_PREFER_32_BIT=yes
$ arch -x86_64 /usr/bin/python -c "import sys;print(sys.maxsize)"
2147483647
#
# But avoiding the wrapper program ....
#
$ arch -x86_64 /usr/bin/python2.7 -c "import sys;print(sys.maxsize)"
9223372036854775807
$ arch -i386 /usr/bin/python2.7 -c "import sys;print(sys.maxsize)"
2147483647
Related
I am importing another module in Jupyter.
Error message:
ImportError: dlopen(/Users/larrytsai/Repositories/payload-designer/.venv/lib/python3.10/site-packages/erfa/ufunc.cpython-310-darwin.so, 0x0002): tried: '/Users/larrytsai/Repositories/payload-designer/.venv/lib/python3.10/site-packages/erfa/ufunc.cpython-310-darwin.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e'))
You need to install the arm64e version of the library you're trying to open.
MacOS can run x86_64 binaries using Rosetta, but it can't mix an x86_64 version with the arm64e interpreter.
Edit: Trying it out on my M1 Mac, it properly built the pyerfa package, you probably just need to uninstall and reinstall it to coerce the rebuild.
It actually built both architectures:
$ file ufunc.cpython-310-darwin.so
ufunc.cpython-310-darwin.so: Mach-O universal binary with 2 architectures: [x86_64:Mach-O 64-bit bundle x86_64Mach-O 64-bit bundle x86_64] [arm64:Mach-O 64-bit bundle arm64Mach-O 64-bit bundle arm64]
ufunc.cpython-310-darwin.so (for architecture x86_64): Mach-O 64-bit bundle x86_64
ufunc.cpython-310-darwin.so (for architecture arm64): Mach-O 64-bit bundle arm64
Probably a silly question, I am coming from another language (perl/C) and I had to install python for a new project (v 3.6)
As I had this problem before in Perl to check which interpreter is doing what (not anymore with perlbrew),I checked with import sys and print (sys.version) and the system's one (2.7) is running. now I realized I did not brewed the python version I simply used the dmg from python.org and it seems that uninstalling is painful.
so long story short how do I find the interpreter path for the installed python?
tried with which--python and there is just the Library/Framework/../2.7
So have I done something wrong somewhere?
update
on macOS x yosemite v 10.10.5,
which -a python
/Library/Frameworks/Python.framework/Versions/2.7/bin/python
/usr/local/bin/python
/usr/bin/python
which -a python 3
/Library/Frameworks/Python.framework/Version/3.6/bin/python3
/usr/local/bin/python3
shebang tried
#!/usr/bin/ env python (python3 and python 3.6)
#!usr/local/bin/python (python3)
then I run the following using cd folder than python3 script name
#!/usr/bin env python3 (or any other shebang)
import sys, platform
print (sys.version)
print platform.python_version()
output is always
2.711 (v.2.7.11:6d1b6a68f775. Dec 5 2015. 12:54:16)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)]
2.7.11
Tried both in emacs / atom (my editors) and bash
I am getting the following error when trying to run make on mod_wsgi 3.3 compilation on CentOS x86_64:
/usr/local/include/python2.6/pyport.h:694:2: error: #error "LONG_BIT definition
appears wrong for platform (bad gcc/glibc config?)."
Setup Info:
My configure script:
./configure --prefix=/usr/local --with-python=/usr/local/bin/python2.6
--with-apxs=/usr/sbin/apxs
make:
LD_RUN_PATH=/usr/local/lib make
file /usr/local/bin/python2.6:
/usr/local/bin/python2.6: ELF 64-bit LSB executable, AMD x86-64, version 1 (SYSV), for GNU/Linux 2.6.9, dynamically linked (uses shared libs), not stripped
file /usr/sbin/httpd:
/usr/sbin/httpd: ELF 64-bit LSB shared object, AMD x86-64, version 1 (SYSV), for GNU/Linux 2.6.9, stripped
Any ideas?
Your Python installation appears to not have been installed properly for both 32 bit and 64 bit.
There are a ton of permutations of this question on StackOverflow and the web in general. I've tried a lot of things and nothing works for me.
Here's my setup. I'm running OS X 10.6. I've used Homebrew to install Python 2.7.1:
$ python
Python 2.7.1 (r271:86832, Mar 12 2011, 16:21:44)
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Note, in Activity Monitor this is reported as a 64-bit process.
First I tried installing libjpeg with Homebrew. Later I uninstalled it and have been installing it to /usr/local by downloading the source, like so:
export CC="/usr/bin/gcc -arch x86_64"
./configure --enable-shared --enable-static
make
sudo make install
Then, in my Django virtualenv, I reinstall PIL:
export CC="/usr/bin/gcc -arch x86_64"
pip uninstall PIL
pip install --no-install PIL
vi build/PIL/setup.py # change JPEG_ROOT to libinclude("/usr/local")
pip install PIL
And still, it doesn't work:
>>> import _imaging
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: dlopen(/Users/me/byp/lib/python2.7/site-packages/PIL/_imaging.so, 2): Symbol not found: _jpeg_resync_to_restart
Referenced from: /Users/me/byp/lib/python2.7/site-packages/PIL/_imaging.so
Expected in: dynamic lookup
byp is your virtualenv? I just did the same thing, though with the system Python 2.6 and had no problems. You can install libjpeg directly into the virtualenv if you want, then you won't have to hack the PIL build script. Here's what I did:
% mkvirtualenv foo
(foo)% cdvirtualenv
(foo)% lftpget http://www.ijg.org/files/jpegsrc.v8c.tar.gz
(foo)% tar zxf jpegsrc.v8c.tar.gz
(foo)% cd jpeg-8c
(foo)% CC="gcc -arch x86_64" ./configure --prefix=$VIRTUAL_ENV
(foo)% make install
(foo)% cd ..
(foo)% pip install PIL
(foo)% python
Python 2.6.1 (r261:67515, Jun 24 2010, 21:47:49)
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import _imaging
>>> _imaging
<module '_imaging' from '/Users/nicholas/LMI/foo/lib/python2.6/site-packages/PIL/_imaging.so'>
>>> ^D
While _imaging.so got built for i386, ppc and x86_64 (because that is how Apple's Python was compiled), libjpeg was compiled for x86_64 only because of the flags I gave gcc:
(foo)% file lib/libjpeg.8.dylib
lib/libjpeg.8.dylib: Mach-O 64-bit dynamically linked shared library x86_64
(foo)% file lib/python2.6/site-packages/PIL/_imaging.so
lib/python2.6/site-packages/PIL/_imaging.so: Mach-O universal binary with 3 architectures
lib/python2.6/site-packages/PIL/_imaging.so (for architecture i386): Mach-O bundle i386
lib/python2.6/site-packages/PIL/_imaging.so (for architecture ppc7400): Mach-O bundle ppc
lib/python2.6/site-packages/PIL/_imaging.so (for architecture x86_64): Mach-O 64-bit bundle x86_64
(foo)% otool -L lib/python2.6/site-packages/PIL/_imaging.so
lib/python2.6/site-packages/PIL/_imaging.so:
/Users/nicholas/LMI/foo/lib/libjpeg.8.dylib (compatibility version 12.0.0, current version 12.0.0)
/opt/local/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.5)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 125.2.1)
Because _imaging.so links to libjpeg dynamically, it fails at load time if a dylib is not available with the expected architecture. I was able to provoke something similar to what you saw by running Python as 32-bit:
(foo)% arch -i386 python
Python 2.6.1 (r261:67515, Jun 24 2010, 21:47:49)
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import _imaging
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: dlopen(/Users/nicholas/LMI/foo/lib/python2.6/site-packages/PIL/_imaging.so, 2): Symbol not found: _jpeg_resync_to_restart
Referenced from: /Users/nicholas/LMI/foo/lib/python2.6/site-packages/PIL/_imaging.so
Expected in: flat namespace
in /Users/nicholas/LMI/foo/lib/python2.6/site-packages/PIL/_imaging.so
So I'd check that the architectures of Python, PIL and libjpeg are compatible. It's rather annoying you don't get a better error message though!
I was trying to solve this issue for hours, the only way, was using this package:
http://ethan.tira-thompson.org/Mac_OS_X_Ports.html
to install libjpeg, then PIL will install and work properly from pip and i guess other sources as well.
mkvirtualenv project-env
workon project-env
brew install samueljohn/python/pillow
pip install --upgrade --no-install Pillow
sed -i '.bak' 's?JPEG_ROOT = None?JPEG_ROOT="\/usr\/local\/Cellar\/jpeg\/8c\/"?' $VIRTUAL_ENV/build/Pillow/setup.py
sed -i '.bak' 's/TIFF_ROOT = None/TIFF_ROOT="\/usr\/local\/Cellar\/libtiff\/4.0.3\/"/' $VIRTUAL_ENV/build/Pillow/setup.py
sed -i '.bak' 's/FREETYPE_ROOT = None/FREETYPE_ROOT="\/usr\/local\/Cellar\/freetype\/2.5.0.1\/"/' $VIRTUAL_ENV/build/Pillow/setup.py
sed -i '.bak' 's/LCMS_ROOT = None/LCMS_ROOT="\/usr\/local\/Cellar\/little-cms\/1.19\/"/' $VIRTUAL_ENV/build/Pillow/setup.py
cd $VIRTUAL_ENV/build/Pillow/ && python setup.py install
I'm having some trouble in using PyQt/SIP. I guess the SIP is compiled into 64bit, but Python has some problem with finding it.
File "qtdemo.py", line 46, in
import sip
ImportError: dlopen(/Library/Python/2.6/site-packages/sip.so, 2): no suitable image found. Did find:
/Library/Python/2.6/site-packages/sip.so: mach-o, but wrong architecture
How do I know if a library (so/dylib) is 32bit or 64bit?
How do I know if my Python is 32bit or 64bit?
The file tool can be used to identify executables.
Example:
> file /Applications/TextEdit.app/Contents/MacOS/TextEdit
/Applications/TextEdit.app/Contents/MacOS/TextEdit: Mach-O universal binary with 2 architectures
/Applications/TextEdit.app/Contents/MacOS/TextEdit (for architecture x86_64): Mach-O 64-bit executable x86_64
/Applications/TextEdit.app/Contents/MacOS/TextEdit (for architecture i386): Mach-O executable i386
lipo -info target/libexample-df07142d9bfd950a.a
input file target/libexample-df07142d9bfd950a.a is not a fat file
Non-fat file: target/libexample-df07142d9bfd950a.a is architecture: x86_64
or
lipo -info `which python`
Non-fat file: /usr/local/bin/python is architecture: x86_64
Don't use file.
To find the available architectures in the Python instance you are using:
$ file "$( "$(which python)" -c "import sys;print(sys.executable)" )"
/usr/bin/python: Mach-O universal binary with 3 architectures
/usr/bin/python (for architecture x86_64): Mach-O 64-bit executable x86_64
/usr/bin/python (for architecture i386): Mach-O executable i386
/usr/bin/python (for architecture ppc7400): Mach-O executable ppc
To find whether the Python is currently running 32-bit or 64-bit (10.6 examples):
$ /usr/bin/python2.6 -c "import sys;print('%x'%sys.maxint)"
7fffffffffffffff
$ arch -x86_64 /usr/bin/python2.6 -c "import sys;print('%x'%sys.maxint)"
7fffffffffffffff
$ arch -i386 /usr/bin/python2.6 -c "import sys;print('%x'%sys.maxint)"
7fffffff
$ arch -ppc /usr/bin/python2.6 -c "import sys;print('%x'%sys.maxint)"
7fffffff
For python3, substitute sys.maxsize for sys.maxint:
$ python3 -c "import sys;print('%x'%sys.maxsize)"
7fffffff