mysql-python installation problems (on mac os x lion) - python

I installed everything successfully, or so I thought:
MySQL 5.5 for x86_64.
Python 2.7, x86_64.
mysql-python 1.2.3, x86_64.
But when I try:
import MySQLdb
I get:
ImportError:
dlopen(/Users/aj/.python-eggs/MySQL_python-1.2.3-py2.7-macosx-10.6-ix86_64.egg-tmp/_mysql.so, 2):
no suitable image found.
Did find:
/Users/aj/.python-eggs/MySQL_python-1.2.3-py2.7-macosx-10.6-ix86_64.egg-tmp/_mysql.so: mach-o,
but wrong architecture
What else can I be missing?
My system is of course 64bit version as well, uname -a gives:
Darwin ajmacbook.local 11.1.0 Darwin Kernel Version 11.1.0: Tue Jul 26 16:07:11 PDT 2011; root:xnu-1699.22.81~1/RELEASE_X86_64 x86_64
I think I have read most SO answers and Google results on the subject, can't think of anything else to try. Any suggestion would be appreciated.

I think there might be slight quirks with doing this on Mac 64-bit (and if you google this problem shows up a lot too).
I've run into it, and there are a couple things you can do:
Override the environment
You can change the DYLD_LIBRARY_PATH environment variable, which tells the linker where to look for dynamic libraries (.so files and such). You said you also downloaded the 64-bit version of MySQL, so where ever it's installed, change the path you see here:
In a shell:
export DYLD_LIBRARY_PATH=/usr/local/mysql/lib/
And then run python and see if you can import MySQLdb.
If that works, you can make this permanent by altering your shell profile (.bash_profile, most likely).
Use homebrew
I don't really like mucking around with making sure MySQL and Python and all that are correct architectures and installing them separately. I run homebrew, which is a sort of package manager for Mac. If you install that, you can pretty easily take care of this issue:
brew install python
brew install mysql
/usr/local/share/python/easy_install mysql-python
Do note that homebrew installs into /usr/local, so you should add /usr/local/bin to your PATH, ahead of /usr/bin and /bin, otherwise you'll get really confused why python is different.
You can add /usr/local/share/python to your PATH as well, to make it permanent.

With the help of the comment from #birryree I found the problem. I would probably be better off following the procedure suggested by #birryree in his answer but I did try this before and it worked:
As suggested, I did:
file /Users/aj/.python-eggs/MySQL_python-1.2.3-py2.7-macosx-10.6-ix86_64.egg-tmp/_mysql.so
To get: [...]: Mach-O bundle i386
So, wrong architecture. From there I did the same with mysql and python just to be sure:
file $(which python) gave:
/Library/Frameworks/Python.framework/Versions/2.7/bin/python: Mach-O universal binary with 2 architectures
/Library/Frameworks/Python.framework/Versions/2.7/bin/python (for architecture i386): Mach-O executable i386
/Library/Frameworks/Python.framework/Versions/2.7/bin/python (for architecture x86_64): Mach-O 64-bit executable x86_64
And file $(which mysql):
/usr/local/mysql/bin/mysql: Mach-O 64-bit executable x86_64
So I uninstalled the mysql-python package: sudo pip uninstall mysql-python and installed it again. But doing this I realized my previous mistake while installing this package. First time I typed:
sudo ARCHFLAGS='-arch ix86_64' python setup.py build (and "install" afterwards)
The architecture name was wrong, should be '-arch x86_64', no "i", so it just ignored my flag and installed the 32bit.
The proper commands to install the downloaded mysql-python package for 64bit (from the source folder):
sudo ARCHFLAGS='-arch x86_64' python setup.py build
sudo ARCHFLAGS='-arch x86_64' python setup.py install

VERY IMPORTANT!
As mentioned above, please make sure you are running the 64-bit version of mysql. It's easy to overlook this detail especially if you've upgraded from Snow Leopard. (I certainly did).
if you're not sure about removing the older version of mysql on your system, refer to this post: http://johnmcostaiii.net/2011/removing-mysql-osx-lion/

I had the same problem, and a lot of headache with MySQLdb after fixing the 64bit issue (it was complaining also about where is libmysqlclient.18.dylib).
I think it's time to switch to the official MysQL Python Connector?
sudo pip install mysql-connector-python
Or download it from: http://dev.mysql.com/downloads/connector/python/
Documentation: http://dev.mysql.com/doc/refman/5.5/en/connector-python.htm
It's easy to use and also compatible with PEP 249 (Python DB API version 2.0).

Also make sure you are running Python 64-bit too. I was running mysql 64 bit and Python 32bit so got the 'but wrong architecture' error

Related

cannot call python3 on solaris 11

I am working on compiling Python package on Solaris 11.
I compiled Python 3.3.2 from source but when I call for Python3 in the terminal it says that the package is not found.
I used wget and ./configure, make, and altinstall for compiling.
I ls the /opt directory where I installed it and the Python 3.3.2 is there.
I have search the answer but could not find anything relevant.
thank you for your help.
I was not correct with my output,
here is what I type and the output I get
root#T2000-1:opt#Python3
bash: Python3: command not found
when I type
cd Python-3.3.2
I can get into Python directory and ls all the files there are.
While compiling, it didn't give me any errors.
I installed the same packages in Debian 7.1 - no problem.
I need to compile from source scipy, numpy, and matplotlib which would work with Python3.
In some of the comments on this very website I read that before you compile python X.X you need to install build-dep Python3 using apt-get, but in Solaris apt-get does not work.
I am kind of stuck and don't know what I need to do.

How can I install C compiler properly for Python package installation for Windows?

I believe I don't have my C compiler properly installed. I'm trying to install some Python 2.7 packages on my Windows 8 machine. I keep receiving the following error:
RuntimeError: Broken toolchain: cannot link a simple C program.
Python is installed properly and has been working well regularly. I've been using the virutalenv package and working in a virtual environment. I've then tried installing Cygwin, MinGW, and MS Visual Studios 2012, none of which seem to work in the virtualenv. I'm not sure what I am doing wrong, any help would be great.
Thank you,
Jimmy
I'm having the same problem, despite installing gcc and mingw-gcc under CygWin, per scipy recommendations. But this might get you further down the track:
setup-x86_64.exe -q -n -N -d -R 'C:\cygwin64' -s 'http://www.gtlib.gatech.edu/x86_64/release/' -l 'C:\Users\$USER\Downloads' -P git,wget,curl,python,gcc-core,mingw-gcc
Eventually I just had to mousily install all the Cygwin packages that came up in the search for "gcc". I only selected those under the "dev" category rather than "debug" and pip install numpy (which compiles and links a lot of C packages) worked fine. Here's my list of Cygwin packages.
I'm on Windows 7 (when I can't avoid it), but not Win 8.
I have installed the following packages and it seems to work:
gcc-core
make
python-devel
Hope this would work for you as well.
P.S.: Used apt-cyg to do the install. https://github.com/transcode-open/apt-cyg

Installing VTK for Python

I'm trying to install VTK module for python, I am however unsuccesful in doing so. I have downloaded a VTK tar-file, but I'm unable to extract it. I'm capable of extracting other tar-files, so there must be something specific with this file I suppose.
This is my error:
gzip: stdin: invalid compressed data--format violated
tar: Child returned status 1
tar: Error is not recoverable: exiting now
I hope somebody can help me with this.
The answer depends on the operating system you are using. This will be a lot easier if you can find a package or installer for your specific operating system and/or distribution.
Linux
If you are using Linux then look for the corresponding package in the distribution's package manager. For example, on Ubuntu Linux you should be able to install it using the following command:
sudo apt-get install python-vtk
Microsoft Windows
If you are using Microsoft Windows, the easiest way would be to install Python(x,y). It comes with VTK support.
Additionally, Anaconda also includes VTK package as well as support for virtual environments. It might be a good option for some folks.
Mac OS X
If you are using Mac OS X, try installing everything via MacPorts.
As #Nil mentioned in comments below, a standalone python interface to VTK is now provided by VTK developers. You may download it for Windows, Darwin, and Linux from here.
As mentioned by #Nil, VTK used to offer vtkpython binaries on their download page. However, they've dropped this since VTK-8.x.x as mentioned here:
Sorry, about that. We decided to drop the vtkpython binaries for 8. I want to focus our energies on supporting python wheel installs instead. There’s no timeline yet for a complete solution but we’ve made some good progress toward that recently here: https://github.com/jcfr/VTKPythonPackage.
Thus, the recommended way of installing vtkpython now is (see this page):
$ python -m pip install --upgrade pip
$ python -m pip install vtk
on Ubuntu, maybe this post will be helpful:
http://kazenotaiyo.blogspot.jp/2010/06/installing-vtk-in-ubuntu-and-making.html
The easiest way
The first and easiest is to just install the packages with the Aptitude Package Manager:
sudo apt-get install libvtk5-dev python-vtk
If you want the newest version
If you want the newest version VTK, you can also build it yourself:
Make sure CMake is installed:
sudo apt-get install cmake
Download the VTK source from the Downloads page.
Untar it:
tar xvzf vtk-5.6.0.tar.gz
Create an Out-Of-Source build and configure with CMake:
mkdir VTK_BUILD
cd VTK_BUILD
ccmake ../VTK
Make sure you enable python wrapping and set your install prefix to where you want the package to go. The default /usr/local works fine.
sudo make -j 8 install
(the -j 8 for make just makes the build process parallel assuming you've got the processors for it)
You now have VTK installed. Congrats! if you try to run vtkpython though, you'll get an error:
vtkpython: error while loading shared libraries: libvtksys.so.5.6: cannot open shared object file: No such file or directory
To fix this, append these lines to your .bash_profile, .bashrc, or .profile file in your home directory:
# add vtk paths
LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/lib/vtk-5.6"
PYTHONPATH="$PYTHONPATH:/usr/local/lib/vtk-5.6"
You'll need to reset your terminal now.
That sets up your library and python paths for the vtkpython executable.
http://www.lfd.uci.edu/~gohlke/pythonlibs/#vtk Try this! Works for windows !
I have installed vtk without a problem under win7 via pip:
> pip install vtk
Collecting vtk
Downloading vtk-8.1.0-cp36-cp36m-win_amd64.whl (24.4MB)
100% |████████████████████████████████| 24.4MB 56kB/s
Installing collected packages: vtk
Successfully installed vtk-8.1.0
With Anacond python:
> python
Python 3.6.1 |Continuum Analytics, Inc.| (default, May 11 2017, 13:25:24) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
MacOS only:
See How to Install Mayavi on MacOS
An abridged version of this for MacOS is the following: (but I recommend the full procedure based on above link, but note that it installs Mayavi too)
The following steps seem to work on MacOS:
brew install vtk
pip install vtk
This installs vtk#9.1. You may want to install brew install vtk#8.2 instead.
Tested on:
Python: 3.9.13, MacOS: 12.4 Monterey
PS. As mentioned before, this answer may be incomplete (you may need QT too, bu tI am not sure). For a complete one including Mayavi, see My answer here . I suggest following the steps there.
I didn't update all content s here because I am not sure which steps are required if you only need VTK (not Mayavi). For example, I don't know whether you need QT or not.

Why does the pip installer expect gcc-4.2 to be the name of the gcc compiler in OS X Lion?

When installing packages in Python using pip, I came across the following error:
unable to execute gcc-4.2: No such file or directory
Clearly, pip is trying to use gcc-4.2 which is not in any of the binary directories, namely /usr/bin. After looking around this site and others, I have found that many others are suffering from the same issue. However, gcc is updated to version 4.2 in OS X Lion and this is not a version problem, rather, gcc is just called gcc, not gcc-4.2, under /usr/bin, and is symlinked to llvm-gcc. After adding gcc-4.2 in /usr/bin as a symlink to gcc, pip was able to install everything successfully. Why is it then, that pip is looking for gcc-4.2 and not gcc? Is this the fault of pip, OS X Lion, or the packages within pip that are trying to install themselves with gcc-4.2?
Finally, is my symlink hack the right thing to do in this situation, or should I have fixed this some other way?
Your simlink hack is the right solution for now. Ultimately the people who support pip for the platform need to stop using explicit versions of the compiler that way. It was a bad idea to begin with and will only be worse as compilers on the platform change.
Contrary to Milad's answer there are other solutions to determining version in the host compiler and your solution will work until the people who support pip on the platform fix their code.
You symlink hack is the right solution for you. pip is just trying to ensure that it is being installed using the right version of GCC. Since your computer is equipped with that version, it is safe for you to point it to your available gcc as the one it is looking for. But if, say, you had gcc-4.1 your installation might have gone places it shouldn't have.

MySQL-Python Installation Error: Possible Architecture Incompatibility?

I am attempting to set up my Django virtualenv production environment on a Linux shared host server. Installing python packages using pip goes fine until I try to install Mysql-Python, which crashes. Does anyone know why this is failing? Looking through the error log, I think it's an architecture incompatibility between the package and my python installation because of these lines:
/usr/bin/ld: skipping incompatible /usr/lib/libc.a when searching for -lc
/usr/bin/ld: warning: i386 architecture of input file build/temp.linux-x86_64-2.4/_mysql.o' is > incompatible with i386:x86-64 output build/temp.linux-x86_64-2.4/_mysql.o: In function _mysql_field_to_python':
I was told the server is 64-bit and is running Python 2.4, although I'm not sure how to double-check the former. Ive been googling this issue for several hours but I've only found references to install/import errors on macs. I'm thinking perhaps I need to compile a different version of MySQLdb instead of just doing pip install -E myvirtualenv MySQL-python but I'm unsure. Any help is greatly appreciated.
If you can't get the same architecture through pip or your package manager, you will probably need to either recompile Python (which you might consider anyway -- Python 2.4 is old), or MySQLdb.
Unfortunately, a lot of Python libraries are not cross-compatible between i386 and x86_64 -- I've actually had exactly the same issue with HGSubversion (the actual issue was with subvertpy, but I needed that for hgsubversion) and cx_Oracle. My solution was to downgrade Python to 2.6 for i386. Stunk.

Categories

Resources