mod_wsgi on Snow Leopard python version mismatch - python

I'm trying to run mod_wsgi 3.1 under Apache 2.2.14 using a non-default python installation on Mac OS X 10.6.
After downloading the mod_wsgi source I run:
sudo apachectl -k stop
then
./configure --with-python=/usr/local/Cellar/python/2.6.4/bin/python
make
sudo make install
I then start up apache again
sudo apachectl -k start
When I cat /var/log/httpd/error_log I see:
[Mon Dec 21 12:27:26 2009] [warn] mod_wsgi: Compiled for Python/2.6.4.
[Mon Dec 21 12:27:26 2009] [warn] mod_wsgi: Runtime using Python/2.6.1.
[Mon Dec 21 12:27:26 2009] [notice] Apache/2.2.14 (Unix) DAV/2 mod_wsgi/3.1 Python/2.6.1 configured -- resuming normal operations
When I run otool -L mod_wsgi.so is see:
mod_wsgi.so:
/System/Library/Frameworks/Python.framework/Versions/2.6/Python (compatibility version 2.6.0, current version 2.6.1)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 125.0.0)
What gives? Why is it linking with the system framework?
Here is the output from my mod_wsgi configure and build commands:
Archimedes:mod_wsgi-3.1 awolf$ ./configure --with-python=/usr/local/Cellar/python/2.6.4/bin/python
checking for apxs2... no
checking for apxs... /opt/apache2/bin/apxs
checking Apache version... 2.2.14
configure: creating ./config.status
config.status: creating Makefile
Archimedes:mod_wsgi-3.1 awolf$ make
/opt/apache2/bin/apxs -c -I/usr/local/Cellar/python/2.6.4/include/python2.6 -DNDEBUG -Wc,'-arch x86_64' mod_wsgi.c -L/usr/local/Cellar/python/2.6.4/lib -L/usr/local/Cellar/python/2.6.4/lib/python2.6/config -arch x86_64 -lpython2.6 -ldl
/Library/Webserver/build/libtool --silent --mode=compile gcc -prefer-pic -DDARWIN -DSIGPROCMASK_SETS_THREAD_MASK -no-cpp-precomp -g -O2 -I/opt/apache2/include -I/opt/apache2/include -I/opt/apache2/include -arch x86_64 -I/usr/local/Cellar/python/2.6.4/include/python2.6 -DNDEBUG -c -o mod_wsgi.lo mod_wsgi.c && touch mod_wsgi.slo
In file included from /usr/local/Cellar/python/2.6.4/include/python2.6/Python.h:125,
from mod_wsgi.c:135:
/usr/local/Cellar/python/2.6.4/include/python2.6/modsupport.h:27: warning: 'PyArg_ParseTuple' is an unrecognized format function type
/Library/Webserver/build/libtool --silent --mode=link gcc -o mod_wsgi.la -rpath /opt/apache2/modules -module -avoid-version mod_wsgi.lo -L/usr/local/Cellar/python/2.6.4/lib -L/usr/local/Cellar/python/2.6.4/lib/python2.6/config -arch x86_64 -lpython2.6 -ldl
Archimedes:mod_wsgi-3.1 awolf$ sudo make install
Password:
/opt/apache2/bin/apxs -i -S LIBEXECDIR=/opt/apache2/modules -n 'mod_wsgi' mod_wsgi.la
/Library/Webserver/build/instdso.sh SH_LIBTOOL='/Library/Webserver/build/libtool' mod_wsgi.la /opt/apache2/modules
/Library/Webserver/build/libtool --mode=install cp mod_wsgi.la /opt/apache2/modules/
cp .libs/mod_wsgi.so /opt/apache2/modules/mod_wsgi.so
cp .libs/mod_wsgi.lai /opt/apache2/modules/mod_wsgi.la
cp .libs/mod_wsgi.a /opt/apache2/modules/mod_wsgi.a
chmod 644 /opt/apache2/modules/mod_wsgi.a
ranlib /opt/apache2/modules/mod_wsgi.a

This post is old, but still turns up in searches about mac + homebrew + python, so I thought I'd add some useful information. I was having the problem as the OP, just with a different module (uwsgi). I learned that you don't have to abandon homebrew. Homebrew can, in fact, install python as a framework; you just have to tell it to do so:
% brew uninstall python
Uninstalling /usr/local/Cellar/python/2.7.2...
% brew install python --universal --framework
... and all's well.

Because for some reason some Python framework installs from source code, usually MacPorts, have something wrong with the information embedded in the Python framework and the run time look up path of the executable isn't set correctly. As a result it ends up using the Python framework from /System/Library instead.
When you run 'configure' for mod_wsgi add the additional option '--disable-framework'. Eg:
./configure --with-python=/usr/local/Cellar/python/2.6.4/bin/python --disable-framework
This will change how Python library/framework is linked and may resolve the problem.
For more details see bug fixes (1) and (2) in:
http://code.google.com/p/modwsgi/wiki/ChangesInVersion0206

Graham helped me solve this over on the mod_wsgi mailing list.
http://groups.google.com/group/modwsgi/browse_thread/thread/4046eaf290a49b1e/ae14888450de39f5#ae14888450de39f5
Here's a summary:
The problem was my installation of python was done via Homebrew. Homebrew’s python is not installed as a framework OR dylib install so it could not be used for embedding (such as in Apache/mod_wsgi).
Instead I installed python 2.6.4 from source:
./configure --prefix=/usr/local/python-2.6.4 --enable-framework=/usr/local/python-2.6.4/frameworks --enable-universalsdk=/ MACOSX_DEPLOYMENT_TARGET=10.5 --with-universal-archs=3-way
make
sudo make install
I was able to build a version of python 2.6.4 that I could then build
mod_wsgi with:
./configure --with-python=/usr/local/python-2.6.4/bin/python
make
sudo make install
To confirm:
otool -L /opt/apache2/modules/ mod_wsgi.so
/opt/apache2/modules/mod_wsgi.so:
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current
version 125.0.0)
/usr/local/python-2.6.4/frameworks/Python.framework/Versions/2.6/Python (compatibility version 2.6.0, current version 2.6.0)
shows that python is now using the 2.6.4 framework and not the system one. When I start apache, I no longer get the version mismatch warnings.
I re-installed django, psycopg2, and so on into my new python installation and everything is working like a charm.
Thanks again for your help!

Related

how to succesfully compile python 3.x

Upon attempting to compile python 3.7 I hit Could not import runpy module:
jeremyr#b88:$ wget https://www.python.org/ftp/python/3.7.3/Python-3.7.3.tar.xz
....
jeremyr#b88:~/Python-3.7.3$ ./configure --enable-optimizations
jeremyr#b88:~/Python-3.7.3$ make clean
jeremyr#b88:~/Python-3.7.3$ make -j32
....
gcc -pthread -Xlinker -export-dynamic -o Programs/_testembed Programs/_testembed.o libpython3.7m.a -lcrypt -lpthread -ldl -lutil -lm
./python -E -S -m sysconfig --generate-posix-vars ;\
if test $? -ne 0 ; then \
echo "generate-posix-vars failed" ; \
rm -f ./pybuilddir.txt ; \
exit 1 ; \
fi
Could not import runpy module
Traceback (most recent call last):
File "/home/jeremyr/Python-3.7.3/Lib/runpy.py", line 15, in <module>
import importlib.util
File "/home/jeremyr/Python-3.7.3/Lib/importlib/util.py", line 14, in <module>
from contextlib import contextmanager
File "/home/jeremyr/Python-3.7.3/Lib/contextlib.py", line 4, in <module>
import _collections_abc
SystemError: <built-in function compile> returned NULL without setting an error
generate-posix-vars failed
Makefile:603: recipe for target 'pybuilddir.txt' failed
make[1]: *** [pybuilddir.txt] Error 1
make[1]: Leaving directory '/home/jeremyr/Python-3.7.3'
Makefile:531: recipe for target 'profile-opt' failed
make: *** [profile-opt] Error 2
jeremyr#88:~/Python-3.7.3$ lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description: Debian GNU/Linux 8.11 (jessie)
Release: 8.11
Codename: jessie
jeremyr#88:~/Python-3.7.3$ gcc --version
gcc (Debian 4.9.2-10+deb8u2) 4.9.2
Copyright (C) 2014 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
jeremyr#88:~/Python-3.7.3$ sudo apt upgrade gcc
Reading package lists... Done
Building dependency tree
Reading state information... Done
Calculating upgrade... gcc is already the newest version.
jeremyr#b88:~/Python-3.7.3$ echo $PYTHONPATH
Any advice on how to overcome this and install python3.7 appreciated.
Edit - the solution listed below seems to work for various other python versions, so I changed title to python 3.x from 3.7
It seems the enable-optimizations was the problem,
jeremyr#b88:~/Python-3.7.3$ ./configure
jeremyr#b88:~/Python-3.7.3$ make clean
takes care of it in my case.
In case others come across this question: I encountered the same problem on Centos 7. I also had --enable-optimizations but didn't want to remove that flag. Updating my build dependencies and then re-running solved the problem. To do that I ran:
sudo yum groupinstall "Development Tools" -y
In case the yum group is not available, you can also install the pacakges individually using:
sudo yum install bison byacc cscope ctags cvs diffstat doxygen flex gcc gcc-c++ gcc-gfortran gettext git indent intltool libtool patch patchutils rcs redhat-rpm-config rpm-build subversion swig systemtap
For whomever MicGer's answer didn't work and would like to retain --enable-optimizations, check your gcc version. The error was solved for me on gcc 8.3.0.
For me, CentOS 7, compiling Python3.9, the fix was updating the gcc and related packages.
Removing --enable-optimizations didn't solved the issue here, neither upgrading GCC from gcc-7.5.0 to gcc-8.2.1 trying building Python 3.6.13 on opensuse-15.2.
Here for some reason the build is picking a local python installation, so before calling make I have updated the PATH env to include the build directory (were python file is generated), for instance: export PATH=$(pwd):$PATH

How to link python 2.7 with latest openssl version in MAC OS?

When I run:
$ openssl version -a
I get 1.0.2k as version:
OpenSSL 1.0.2k 26 Jan 2017
built on: reproducible build, date unspecified
platform: darwin64-x86_64-cc
options: bn(64,64) rc4(ptr,int) des(idx,cisc,16,int) idea(int) blowfish(idx)
compiler: cc -I. -I.. -I../include -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -arch x86_64 -O3 -DL_ENDIAN -Wall -DOPENSSL_IA32_SSE2 -DOPENSSL_BN_ASM_MONT -DOPENSSL_BN_ASM_MONT5 -DOPENSSL_BN_ASM_GF2m -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM -DMD5_ASM -DAES_ASM -DVPAES_ASM -DBSAES_ASM -DWHIRLPOOL_ASM -DGHASH_ASM -DECP_NISTZ256_ASM
OPENSSLDIR: "/usr/local/php5/ssl"
But when I check the version with python:
$ python -c 'import ssl; print(ssl.OPENSSL_VERSION)'
I get: OpenSSL 0.9.8zg 14 July 2015
How can I link the latest openssl version?
My pip version is ;
pip 10.0.1 from /Library/Python/2.7/site-packages/pip (python 2.7)
When I try to install some modules using PIP I get [SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version (_ssl.c:590) error. So trying to upgrade my ssl version in python
And How to make my system Openssl version is same as virtualenv version?
You really do not want to muck with the system Python. It's built as its built to work with your OS when it needs to do so.
If you need a more up to date OpenSSL build with Python, use something like brew or macports or the python.org packages to install more recent builds of Python 2 or 3 and use those.
(For reference, my brew Python 3.6 Python was built against OpenSSL 1.0.2o, as an example)
How can I link the latest openssl version?
This is only possible when compiling Python from source; the location of OpenSSL headers and libraries to compile with/link against is set via CPPFLAGS/LDFLAGS/LD_LIBRARY_PATH environment variables, as described here. You can't "relink" the code once it's compiled, though.
Another issue is that you won't be able to alter the system Python in MacOS without some dangerous system modification. Python preinstalled by MacOS is located under /System/Library/Frameworks/Python.framework, and you can't modify or delete anything under /System without turning off the System Integrity Protection (I would strongly advise not to do that anyway).
The suggested solution is thus to leave the system Python as-is and install another copy for own use. On MacOS, you usually have two choices: either use Homebrew that offers the latest Python 2 and 3 versions, or use the official .pkg installers from https://www.python.org/downloads/. Both were built against OpenSSL of a recent version. What to choose depends on your use case; personally, I don't use the brewed Python because it doesn't offer multiple versions of Python 3 package (for example, I need 3.5/3.6/3.7 to be installed simultaneously to run the tests against). The major downside with the .pkg installers is that the installed Python is installed outside of any package manager and won't be updated automatically, so you are responsible of updating it yourself. Worst case, this means downloading a new installer and reinstalling even on a minor version bump.
Once installed, adjust the PATH variable for your user so the newly installed Python precedes the system one. For brewed Python, open ~/.bash_profile and append
BREW_PREFIX=$(brew --prefix)
PATH="$BREW_PREFIX/bin:$BREW_PREFIX/sbin:$PATH"
export PATH
For Python installed via the official .pkg installer: the profile should be modified automatically in the installation; nevertheless, it doesn't hurt to double-check. Open ~/.bash_profile and check whether the lines similar to
# Setting PATH for Python 3.6
# The original version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.6/bin:${PATH}"
export PATH
are present; if not, append them for your installed Python version.

Building graph-tool on OSX with Python 3.4

I tried to install graph-tool on Mac OSX 10.10 using homebrew. The brew build process works fine, but when I try to import graph-tool I get the error described in this question.
Another problem with homebrew is that I always builds graph-tool for python2.7 and it installs the packages in the Python 2.7 sit-packages folder. But I want to use it with Python 3.4. These are the reasons why I tried to build graph-tool from source.
The ./configure command automatically uses Python 2.7, too. So I passed it the desired Python version with ./configure PYTHON=python3.4
It then detects the correct version as well as the related paths but crash with the following error:
configure: error:
Could not link test program to Python. Maybe the
main Python library has been installed in some non-standard library
path. If so, pass it to configure, via the LDFLAGS environment
variable.
Example: ./configure LDFLAGS="-L/usr/non-standard-path/python/lib"
======================================================================
ERROR!
You probably have to install the development version of the
Python package for your distribution. The exact name of this package varies
among them.
======================================================================
The error occurs with and without PYTHON variable set.
From the output of ./configure I can see that everything works fine except for the last line, which says:
checking consistency of all components of python development
environment... no
Whats does the above line mean and how do I properly install graph-tool on my maschine?
The error message is explaining exactly what needs to be done. Since python was installed in a non-standard path, you need to pass the flag LDFLAGS="-L/usr/non-standard-path/python/lib" pointing to the directory where the python libraries are located. This is most likely "/usr/local/lib", if you are using homebrew.
I was getting this error when I was trying to install graph-tool using outdated an autoconf / automake / pkg-config combination (installed using yum in CentOS 5.10). Installing those packages from source fixed the problem... although I'm not sure how this related to my python installation....
It worked for me by passing the variable PYTHON_EXTRA_LDFLAGS="-Wl,-stack_size,1000000 -F/usr/local/Cellar/python3/3.6.3/Frameworks -framework CoreFoundation".
In your case, it would be the path to the homebrew installation of python3.4.
The way I found out is that in the config.log, the error message shows the following:
configure:19023: checking python extra libraries
configure:19030: result: -ldl -framework CoreFoundation
configure:19037: checking python extra linking flags
configure:19044: result: -Wl,-stack_size,1000000 -framework CoreFoundation Python.framework/Versions/3.6/Python
configure:19051: checking consistency of all components of python development environment
configure:19079: gcc -o conftest -g -O2 -DNDEBUG -I/usr/local/Cellar/python3/3.6.3/Frameworks/Python.framework/Versions/3.6/include/python3.6m -F/usr/local/Cellar/python3/3.6.3/Frameworks/ -Wl,-stack_size,1000000 -framework CoreFoundation Python.framework/Versions/3.6/Python conftest.c -L/usr/local/opt/python3/Frameworks/Python.framework/Versions/3.6/lib -lpython3.6m -ldl -framework CoreFoundation -ldl -framework CoreFoundation >&5
clang: error: no such file or directory: 'Python.framework/Versions/3.6/Python'
The error seems to be path 'Python.framework/Versions/3.6/Python', that in a homebrew installation does not exist. I search for the same path in the config.log and I found this line:
PYTHON_EXTRA_LDFLAGS="-Wl,-stack_size,1000000 -framework CoreFoundation Python.framework/Versions/3.6/Python"
So, the solution for me was to pass this variable with the right path.

matplotlib.pyplot issue python

I'm experiencing a problem with matplotlib, to be more precise with pyplot.
Just after installing, doing
import matplotlib.pyplot
gives me this error:
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/_png.so, 2): Symbol not found: _png_create_info_struct
Referenced from: /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/_png.so
Expected in: flat namespace
in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/_png.so
So I have no idea what is going on. I'm on Mac OS X 10.6, I have installed python2.7 from disk image and matplotlib from the terminal by using the tar.gz and doing the usual
python setup.py build
python setup.py install
When the installation starts I see:
BUILDING MATPLOTLIB
matplotlib: 1.1.0
python: 2.7 (r27:82508, Jul 3 2010, 21:12:11) [GCC 4.0.1
(Apple Inc. build 5493)]
platform: darwin
REQUIRED DEPENDENCIES
numpy: 1.6.1
freetype2: 10.0.4
OPTIONAL BACKEND DEPENDENCIES
libpng: 1.2.44
Tkinter: no
* TKAgg requires Tkinter
Gtk+: no
* Building for Gtk+ requires pygtk; you must be able
* to "import gtk" in your build/install environment
Mac OS X native: yes
Qt: no
Qt4: no
Cairo: no
OPTIONAL DATE/TIMEZONE DEPENDENCIES
datetime: present, version unknown
dateutil: matplotlib will provide
pytz: matplotlib will provide
adding pytz
OPTIONAL USETEX DEPENDENCIES
dvipng: 1.13
ghostscript: 8.61
latex: 3.1415926
Any help guys please!
Cheers
http://fonnesbeck.github.io/ScipySuperpack/
I've been fighting this same problem and the answer was to install the ScipySuperpack. The problem (at least for me) was that I have a 64 bit version of Python, and the version of matplotlib I was pulling from github was 32 bit. I cloned the ScipySuperpack repository and ran the setup script and it worked.
No amount of fighting with brew or ports was getting me anywhere.
In case anyone has the same problem as me and finds this thread, here is how I solved it.
First, I follow the current matplotlib README.osx, along with this guy's advice (not sure if that's necessary)...
brew install freetype --universal
brew install libpng --universal
export CPPFLAGS="-I/usr/local/opt/libpng/include -I/usr/local/opt/freetype/include"
export LDFLAGS=" -L/usr/local/opt/libpng/lib -L/usr/local/opt/freetype/lib"
I also set those variables as recommended by brew.
Then, I did the following
(running from matplotlib build directory, after having built and installed)
drigz#mbp matplotlib 0$ find . -name _png.so
./build/lib.macosx-10.6-intel-2.7/matplotlib/_png.so
drigz#mbp matplotlib 0$ otool -L ./build/lib.macosx-10.6-intel-2.7/matplotlib/_png.so
./build/lib.macosx-10.6-intel-2.7/matplotlib/_png.so:
/usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.3)
/usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 7.9.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 125.2.0)
/usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 830.0.0)
No libpng! A bad sign... let's see the build output again...
drigz#mbp matplotlib 0$ rm ./build/lib.macosx-10.6-intel-2.7/matplotlib/_png.so
drigz#mbp matplotlib 0$ python setup.py build
[SNIP]
c++ -bundle -undefined dynamic_lookup -arch i386 -arch x86_64 -isysroot /Developer/SDKs/MacOSX10.6.sdk -isysroot /Developer/SDKs/MacOSX10.6.sdk -g -L/usr/local/opt/libpng/lib -L/usr/local/opt/freetype/lib -I/usr/local/opt/libpng/include -I/usr/local/opt/freetype/include build/temp.macosx-10.6-intel-2.7/src/_png.o build/temp.macosx-10.6-intel-2.7/src/mplutils.o build/temp.macosx-10.6-intel-2.7/CXX/cxx_extensions.o build/temp.macosx-10.6-intel-2.7/CXX/cxxsupport.o build/temp.macosx-10.6-intel-2.7/CXX/IndirectPythonInterface.o build/temp.macosx-10.6-intel-2.7/CXX/cxxextensions.o -L/sw/lib -L/usr/local/lib -L/usr/lib -L/usr/X11/lib -lpng14 -lz -lstdc++ -lm -o build/lib.macosx-10.6-intel-2.7/matplotlib/_png.so
ld: warning: in /sw/lib/libpng14.dylib, file was built for i386 which is not the architecture being linked (x86_64)
It's not using the right libpng: what does brew provide?
drigz#mbp matplotlib 0$ echo $LDFLAGS
-L/usr/local/opt/libpng/lib -L/usr/local/opt/freetype/lib
drigz#mbp matplotlib 0$ ls /usr/local/opt/libpng/lib
libpng.a libpng.la libpng15.a pkgconfig
libpng.dylib libpng15.15.dylib libpng15.dylib
Let's try to fix that by copy-pasting the command but changing -lpng14 to -lpng15... (there's probably a better way to stop it from using the wrong one, but this worked)
drigz#mbp matplotlib 0$ c++ -bundle -undefined dynamic_lookup -arch i386 -arch x86_64 -isysroot /Developer/SDKs/MacOSX10.6.sdk -isysroot /Developer/SDKs/MacOSX10.6.sdk -g -L/usr/local/opt/libpng/lib -L/usr/local/opt/freetype/lib -I/usr/local/opt/libpng/include -I/usr/local/opt/freetype/include build/temp.macosx-10.6-intel-2.7/src/_png.o build/temp.macosx-10.6-intel-2.7/src/mplutils.o build/temp.macosx-10.6-intel-2.7/CXX/cxx_extensions.o build/temp.macosx-10.6-intel-2.7/CXX/cxxsupport.o build/temp.macosx-10.6-intel-2.7/CXX/IndirectPythonInterface.o build/temp.macosx-10.6-intel-2.7/CXX/cxxextensions.o -L/sw/lib -L/usr/local/lib -L/usr/lib -L/usr/X11/lib -lpng15 -lz -lstdc++ -lm -o build/lib.macosx-10.6-intel-2.7/matplotlib/_png.so
drigz#mbp matplotlib 0$ python setup.py install
[SNIP]
drigz#mbp matplotlib 0$ otool -L /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/_png.so
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/_png.so:
/usr/local/opt/libpng/lib/libpng15.15.dylib (compatibility version 29.0.0, current version 29.0.0)
/usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.3)
/usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 7.9.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 125.2.0)
/usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 830.0.0)
I just wanted to add a few suggestions for people who might still be having trouble. I've been searching around for a while and trying lots of different things. Ultimately, it was one of the following that allowed me to import matplotlib.pyplot on Python 2.7.6 on OSX 10.6 (with X11 and XQuartz installed previously, perhaps outdated):
Installing pkg-info
brew install pkg-info
Installing libpng from source to /usr/local/lib (configure --libdir=/usr/local)
Installing XQuartz for Mac
Deleting matplotlib folders from site-packages (probably old, failed attempts).
Running
ln -s /usr/local/opt/freetype/include/freetype2 /usr/local/include/freetype
Finally,
port install py27-matplotlib
installed it, and I was able to import. The original error I had was
ImportError: dlopen(/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib-1.4.x-py2.7-macosx-10.6-x86_64.egg/matplotlib/_png.so, 2): Library not loaded: /opt/local/lib/libpng15.15.dylib
Referenced from: /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib-1.4.x-py2.7-macosx-10.6-x86_64.egg/matplotlib/_png.so Reason: image not found
Though some attempts ran into this error:
In file included from src/ft2font.cpp:3:
In file included from src/ft2font.h:16:
/usr/X11/include/ft2build.h:56:10: fatal error: 'freetype/config/ftheader.h' file not found
#include <freetype/config/ftheader.h>
I'm sorry I can't be more specific.
You should follow these directions for installing Matplotlib from source on OSX: https://github.com/matplotlib/matplotlib/blob/master/README.osx
OSX is a bit messy with the lib files, but following the directions from the link should resolve any issues you're having as it automatically installs the dependencies in a self-contained manner.
I had same problem as OP. I git cloned the repo and "python setup install" instead of pre-compiled version. Took about 20 minutes to compile and seems to work now.

problems with easy_install pycrypto

I'm trying install pycrypto on osx with easy_install and I'm getting the following error:
easy_install pycrypto
Searching for pycrypto
Reading http://pypi.python.org/simple/pycrypto/
Reading http://pycrypto.sourceforge.net
Reading http://www.pycrypto.org/
Reading http://www.amk.ca/python/code/crypto
Best match: pycrypto 2.3
Downloading http://ftp.dlitz.net/pub/dlitz/crypto/pycrypto/pycrypto-2.3.tar.gz
Processing pycrypto-2.3.tar.gz
Running pycrypto-2.3/setup.py -q bdist_egg --dist-dir /var/folders/3D/3D07iptvHZuzuYaeQDMFIU+++TI/-Tmp-/easy_install-00HgRU/pycrypto-2.3/egg-dist-tmp-BWGYsg
warning: GMP library not found; Not building Crypto.PublicKey._fastmath.
/usr/libexec/gcc/powerpc-apple-darwin10/4.2.1/as: assembler (/usr/bin/../libexec/gcc/darwin/ppc/as or /usr/bin/../local/libexec/gcc/darwin/ppc/as) for architecture ppc not installed
Installed assemblers are:
/usr/bin/../libexec/gcc/darwin/x86_64/as for architecture x86_64
/usr/bin/../libexec/gcc/darwin/i386/as for architecture i386
src/MD2.c:134: fatal error: error writing to -: Broken pipe
compilation terminated.
lipo: can't open input file: /var/folders/3D/3D07iptvHZuzuYaeQDMFIU+++TI/-Tmp-//ccoXuPRo.out (No such file or directory)
error: Setup script exited with error: command 'gcc-4.2' failed with exit status 1
I have this in my ~/.bash_profile to address this very issue:
# Set compile flags to not try to compile for PPC (no longer supported by xcode 4)
# (this is required for eg building pycrypto)
export ARCHFLAGS="-arch i386 -arch x86_64"
Yes, it's a result of installing Xcode 4. It tries to build for ppc, although Xcode 4 no longer has the relevant bits for that. See this question for ways round it: https://superuser.com/questions/259278/python-2-6-1-pycrypto-2-3-pypi-package-broken-pipe-during-build
xCode 5.1
ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future pip install pycrypto
Looks like this got a little more difficult with OSX 10.9. Here's the additional stuff I did:
brew install libffi
If you see the warning about how it's installed "keg-only", that means homebrew did not link it, so you'll need to provide some more info with export PKG_CONFIG_PATH=/usr/local/opt/libffi/lib/pkgconfig. At that point the install blows up because by default OSX now dies on warning flags, so suppress that behavior as well:
export CFLAGS=-Qunused-arguments
export CPPFLAGS=-Qunused-arguments
Then you should be able to install with pip.

Categories