Installing MySQLdb Python Architecture Error - mysql

I am trying to install MySQLdb python and am having trouble getting it to work because I get an architecture error.
>>> import MySQLdb
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "build/bdist.macosx-10.6-x86_64/egg/MySQLdb/__init__.py", line 19, in <module>
File "build/bdist.macosx-10.6-x86_64/egg/_mysql.py", line 7, in <module>
File "build/bdist.macosx-10.6-x86_64/egg/_mysql.py", line 6, in __bootstrap__
ImportError: dlopen(/Users/jkeesh/.python-eggs/MySQL_python-1.2.3-py2.6-macosx-10.6-x86_64.egg-tmp/_mysql.so, 2): no suitable image found. Did find:
/Users/jkeesh/.python-eggs/MySQL_python-1.2.3-py2.6-macosx-10.6-x86_64.egg-tmp/_mysql.so: mach-o, but wrong architecture
This has been a common question, and I have read many, many sources including:
Python MySQL wrong architecture error
http://www.mechanicalgirl.com/view/installing-django-with-mysql-on-mac-os-x/
Django + MySQL on Mac OS 10.6.2 Snow Leopard
Installing MySQLdb on Mac OS X
and many other links.
It appears that the problem is a 32-bit 64-bit mismatch, but I'm not sure what the right combination is, or what exactly the mismatch is.
I have installed from pip, from Mac ports, and built from the source. I have tried setting the ARCHFLAGS to both i386 and and x86_64.
I have tried setting VERSIONER_PYTHON_PREFER_32_BIT and VERSIONER_PYTHON_PREFER_64_BIT preferences.
I am running Mac OS X 10.6.6
I have mysql installed in /usr/local/mysql
$ file $(which ./mysql)
./mysql: Mach-O executable i386
I have mysql version 5.5.12
I have 64 bit Python 2.6.6.
My system architecture is:
>>> platform.platform()
'Darwin-10.6.0-i386-64bit'
$ file $(which python)
/opt/local/bin/python: Mach-O 64-bit executable x86_64
If there are any links you can point me to or suggestions to try I would really appreciate it. I'm kind of at a dead end and getting the same "wrong architecture" error no matter what I try.

Try to add this in your .bashrc or .bash_profile:
PATH="/usr/local/mysql/bin:${PATH}"
export PATH
export DYLD_LIBRARY_PATH=/usr/local/mysql/lib/
export VERSIONER_PYTHON_PREFER_64_BIT=no
export VERSIONER_PYTHON_PREFER_32_BIT=yes

I've solved my own question, so hopefully this can be of help to people with similar issues.
I believe I had a 32-bit mysql installation.
I uninstalled all versions of mysql that I had
I went back and installed mysql 5.1 from the source, but I think a mysql 5.1 x86_64 bit dmg or binary would work also.
I used this make command from this post http://hivelogic.com/articles/compiling-mysql-on-snow-leopard/
I had permission issues and finally got it working using
sudo mysqld_safe --skip-grant-tables &
I installed MySQL-python 1.2.3c1 from here
http://pypi.python.org/pypi/MySQL-python/1.2.3c1

Related

Django MySQL throws an error, Library not loaded: /usr/local/opt/mysql#5.6/lib/libmysqlclient.18.dylib When I upgraded from 5.6 to 5.7 mysql

Yes, this seems like a common error. But something else is wrong with my environment. I have upgraded from MySQL 5.6 version to 5.7.
I can access mysql5.7 by typing mysql into the console.
I have updated the DYLD_LIBRARY_PATH to reflect new 5.7 location
git:(parent-child) ✗ echo $DYLD_LIBRARY_PATH
/usr/local/opt/mysql#5.7/lib/:
But the error for reason still says it is trying to load from 5.6 version.
Exception in thread django-main-thread:
Traceback (most recent call last):
File "/Users/vineeth/envs/automize2.0/lib/python3.7/site-packages/django/db/backends/mysql/base.py", line 16, in <module>
import MySQLdb as Database
File "/Users/vineeth/envs/automize2.0/lib/python3.7/site-packages/MySQLdb/__init__.py", line 18, in <module>
from . import _mysql
ImportError: dlopen(/Users/vineeth/envs/automize2.0/lib/python3.7/site-packages/MySQLdb/_mysql.cpython-37m-darwin.so, 2): Library not loaded: /usr/local/opt/mysql#5.6/lib/libmysqlclient.18.dylib
Referenced from: /Users/vineeth/envs/automize2.0/lib/python3.7/site-packages/MySQLdb/_mysql.cpython-37m-darwin.so
Reason: image not found
Notice the error says it still is trying locate /usr/local/opt/mysql#5.6/lib/libmysqlclient.18.dylib
I have reinstalled almost everything since this error came.
Tried several solutions
Python mysqldb: Library not loaded: libmysqlclient.18.dylib
rails + MySQL on OSX: Library not loaded: libmysqlclient.18.dylib
Nothing seems to change its reference.
How do I make it refer to the newer one which is in /usr/local/opt/mysql#5.7/lib/
Also reinstalled mysqlclient with pip but still no luck.
Help is welcome. Been struggling since a day.
To expand my comment as an answer:
Pip compiles source packages into wheels that get cached into your local Pip cache. However, it has no knowledge of the "ambient" dependencies that may affect how the binary package gets compiled, in this case the MySQL shared library.
Recreating the virtualenv won't directly help, since Pip will use the cached binary wheel (to save you from a recompilation).
You could:
use pip install --no-cache-dir to have Pip not use the cache at all (though the "tainted" wheel will remain in your cache)
nuke the whole Pip cache from orbit
see what comes out of https://github.com/pypa/pip/issues/2882 / https://github.com/pypa/pip/issues/4685 ...

ImportError: No module named fabric when run mysqlfabric command

My VM is using Ubuntu 14.04.
I followed the official manual to install MySql Fabric:
First, install Connector/Python GA
Next, install MySQL Utilities 1.5.6
However, when I tried to test the mysqlfabric help command, it threw error like:
Traceback (most recent call last):
File "/usr/bin/mysqlfabric", line 33, in <module>
from mysql.fabric import (
ImportError: No module named fabric
Based on this SO question, after upgrading Ubuntu from 15.04, the problem can be resolved, but I want to run fabric on Ubuntu 14.04.
I tried to re-installed Connector/Python, MySQL Utilities, also checked compatibility with Ubuntu version 14.04, searched on the Internet & SO for similar problems. But still cannot resolve the issue.
Thanks a lot for your help!
Not quite sure what is the problem with installing using .deb file.
But after many (painful) tries, I figured out that re-installing MySQL Utilities from source code can resolve the issue.

Installing Cairo and PyCairo Mac OsX

I am playing around with using python iGraph for network visualization. I got his error message when I tried to plot a graph:
>>> layout = g.layout("kk")
>>> plot(g, layout = layout)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "build/bdist.macosx-10.5-x86_64/egg/igraph/drawing/__init__.py", line 446, in plot
File "build/bdist.macosx-10.5-x86_64/egg/igraph/drawing/__init__.py", line 117, in __init__
File "build/bdist.macosx-10.5-x86_64/egg/igraph/drawing/utils.py", line 396, in __getattr__
TypeError: plotting not available
I don't think I installed Cairo or PyCairo correctly.
I am not familiar using Fink or MacPorts, since I commonly use Homebrew.
Any help you be greatly appreciated.
You need to manually compile the library. I used the solution here and just updated the version.
curl -L https://www.cairographics.org/releases/cairo-1.14.6.tar.xz -o cairo.tar.xz
tar -xf cairo.tar.xz && cd cairo-1.14.6
./configure --prefix=/usr/local --disable-dependency-tracking
make install
If while running configure, you get an error about pkg_config, you can install that with brew:
brew install pkg-config
I had the same problem on my MacBook so I wanted to share my solution.
I tried to install pycairo, py2cairo. The installation seemed to be okay but then:
I could not import pycairo
igraph's plot would not work.
The following solved the igraph plotting issue:
sudo pip install cairocffi
or just
pip install cairocffi
So instead of pycairo I used cairocffi and this did the trick.
As Mads said in a comment, brew install cairo works, it solved a related problem for me, so I'm posting here for people who end up here why troubleshooting cairo on OS X.
Accepted answer lead to an error of libpng missing, homebrew on the other hand installed all dependencies correctly.

Can't import MySQLdb module in Python

I'm trying to use MySQL in Python. I have installed the MySQL adapter (MySQL-python-1.2.4b4.win32-py2.7) for Python, but when I try to import the MySQLdb module (import MySQLdb) with command prompt I receive the following output:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\site-packages\MySQLdb\__init__.py", line 19, in <module>
import _mysql
ImportError: DLL load failed: %1 is not a valid Win32 application.
Would anybody know, what could be wrong?
You need to have a 32bit version of Python to use this adapter. Which version are you actually using ?
I had problems installing the 64-bit version of MySQLdb on Windows via Pip, but if you want to continue using a 64-bit version of Python, rather than reverting to a 32-bit version, then you can install the compiled MySQLdb from the .whl file available from http://www.lfd.uci.edu/~gohlke/pythonlibs/
You will then want to install the .whl file as document in https://pip.pypa.io/en/latest/user_guide/#installing-from-wheels
when you setup the module ,be careful the version ,MySQL-python-1.2.3.win32-py2.7.exe and MySQL-python-1.2.4.win32-py2.7.exe ,only one of the 2 version is you need,try 2 times

Running mysqltuner on Mac OSX

I use Zend Server CE on my Mac running OSX Snow Leopard for my development environment. I need to tune up MySQL and have used mysqltuner.pl in the past on Linux servers to do pre- and post-testing.
I downloaded the script and get the following errors when I run it:
couldn't find diagnostic data in /System/Library/Perl/5.10.0/pods/perldiag.pod /Library/Perl/Updates/5.10.0 /System/Library/Perl/5.10.0/darwin-thread-multi-2level /System/Library/Perl/5.10.0 /Library/Perl/5.10.0/darwin-thread-multi-2level /Library/Perl/5.10.0 /Network/Library/Perl/5.10.0/darwin-thread-multi-2level /Network/Library/Perl/5.10.0 /Network/Library/Perl /System/Library/Perl/Extras/5.10.0/darwin-thread-multi-2level /System/Library/Perl/Extras/5.10.0 . ./mysqltuuner.pl at /System/Library/Perl/5.10.0/diagnostics.pm line 268, <POD_DIAG> line 647.
Compilation failed in require at ./mysqltuuner.pl line 42, <POD_DIAG> line 647.
BEGIN failed--compilation aborted at ./mysqltuuner.pl line 42, <POD_DIAG> line 647.
Snow Leopard has perl and I have the XCode Development Tools installed.
It looks like I am missing some Perl modules. I have tried to CPAN the files, but I'm not a Perl wonk and I think I might have screwed up my Perl install now.
Any ideas???
Looks like something in there is using the diagnostics module, which requires the perl documentation to function correctly. I'm guessing the perl documentation is a separately installable component from perl itself in OS X.