cython-book icon indicating copy to clipboard operation
cython-book copied to clipboard

Chapter1 Helloworld for Mac and Python installed with homebrew

Open thilaire opened this issue 8 years ago • 1 comments

Hi I was trying your 1st example (Chapter 1, Helloworld), and I get the following message

Python 2.7.11 (default, Jan 22 2016, 16:30:50)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import helloworld
Fatal Python error: PyThreadState_Get: no current thread
fish: 'python' terminated by signal SIGABRT (Abort)

After some googling, I've discovered that the error comes from the fact that I am using, on my mac, several Python versions (one from Apple, and the others installed with the homebrew system, as described here for example)

The command otool -L helloworld.so returns

helloworld.so (compatibility version 0.0.0, current version 0.0.0)
/System/Library/Frameworks/Python.framework/Versions/2.7/Python (compatibility version 2.7.0, current version 2.7.5)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1197.1.1)
/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 855.17.0)

indicating that the helloworld.so was linked with the Python 2.7.5 (the original apple version), that is not the active version (Python 2.7.11, installed with homebrew).

So, I changed a little bit the Makefile to

all:
    cython -2 -o helloworld.c helloworld.pyx
    gcc -g -O2 -fpic -c helloworld.c -o helloworld.o `python-config --cflags`
    gcc -g -O2 -shared -o helloworld.so helloworld.o `python-config --ldflags`

(--ldflagsinstead of --libs) and everything is fine, now.

thilaire avatar Apr 06 '16 21:04 thilaire

Nice find! You can submit a pull request if you like and i will merge in :).

Thanks.

On 6 April 2016 at 22:32, thilaire [email protected] wrote:

Hi I was trying your 1st example (Chapter 1, Helloworld), and I get the following message

Python 2.7.11 (default, Jan 22 2016, 16:30:50) [GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin Type "help", "copyright", "credits" or "license" for more information.

import helloworld Fatal Python error: PyThreadState_Get: no current thread fish: 'python' terminated by signal SIGABRT (Abort)

After some googling, I've discovered that the error comes from the fact that I am using, on my mac, several Python versions (one from Apple, and the others installed with the homebrew system, as described here http://docs.python-guide.org/en/latest/starting/install/osx/ for example)

The command otool -L helloworld.so returns

helloworld.so (compatibility version 0.0.0, current version 0.0.0) /System/Library/Frameworks/Python.framework/Versions/2.7/Python (compatibility version 2.7.0, current version 2.7.5) /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1197.1.1) /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 855.17.0)

indicating that the helloworld.so was linked with the Python 2.7.5 (the original apple version), that is not the active version (Python 2.7.11, installed with homebrew).

So, I changed a little bit the Makefile to

all: cython -2 -o helloworld.c helloworld.pyx gcc -g -O2 -fpic -c helloworld.c -o helloworld.o python-config --cflags gcc -g -O2 -shared -o helloworld.so helloworld.o python-config --ldflags

(--ldflagsinstead of --libs) and everything is fine, now.

— You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub https://github.com/redbrain/cython-book/issues/5

philberty avatar Apr 07 '16 09:04 philberty