kivent icon indicating copy to clipboard operation
kivent copied to clipboard

Building cymunk module fails on OS X

Open MadWombat opened this issue 7 years ago • 16 comments

I installed chipmunk using Homebrew and now trying to run python3 setup.py build_ext install as the docs say. This is the result I get

[2/2] Cythonizing kivent_cymunk/physics.pyx
running build_ext
building 'kivent_cymunk.physics' extension
clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/usr/local/lib/python3.6/site-packages/cymunk/_
_init__.py -I/usr/local/include -I/usr/local/opt/openssl/include -I/usr/local/opt/sqlite/include -I/usr/local/Cellar/python3/3.6.0/Frameworks/Python.framework/Versions/3.6/include
/python3.6m -c kivent_cymunk/physics.c -o build/temp.macosx-10.12-x86_64-3.6/kivent_cymunk/physics.o -std=gnu99 -ffast-math -F/Applications/Xcode.app/Contents/Developer/Platforms/
MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/System/Library/Frameworks -arch x86_64
kivent_cymunk/physics.c:5401:278: warning: comparison of integers of different signs: 'unsigned int' and 'int' [-Wsign-compare]
  ...__pyx_v_entity_id, __pyx_v_zone_name); if (unlikely(__pyx_t_3 == -1)) __PYX_ERR(0, 289, __pyx_L1_error)
                                                         ~~~~~~~~~ ^  ~~
kivent_cymunk/physics.c:500:43: note: expanded from macro 'unlikely'
  #define unlikely(x) __builtin_expect(!!(x), 0)
                                          ^
kivent_cymunk/physics.c:7248:283: warning: comparison of integers of different signs: 'unsigned int' and 'int' [-Wsign-compare]
  ...__pyx_v_index, __pyx_v_entity_id, __pyx_v_body->_body, __pyx_v_zone_name); if (unlikely(__pyx_t_18 == -1)) __PYX_ERR(0, 456, __pyx_L1_error)
                                                                                             ~~~~~~~~~~ ^  ~~
kivent_cymunk/physics.c:500:43: note: expanded from macro 'unlikely'
  #define unlikely(x) __builtin_expect(!!(x), 0)
                                          ^
kivent_cymunk/physics.c:7861:28: error: incomplete definition of type 'struct cpBody'
  __pyx_t_10 = __pyx_v_body->a;
               ~~~~~~~~~~~~^
/usr/local/include/chipmunk/chipmunk.h:92:16: note: forward declaration of 'struct cpBody'
typedef struct cpBody cpBody;
               ^
kivent_cymunk/physics.c:7871:28: error: incomplete definition of type 'struct cpBody'
  __pyx_t_11 = __pyx_v_body->p;
               ~~~~~~~~~~~~^
/usr/local/include/chipmunk/chipmunk.h:92:16: note: forward declaration of 'struct cpBody'
typedef struct cpBody cpBody;
               ^
kivent_cymunk/physics.c:8462:29: error: incomplete definition of type 'struct cpBody'
    __pyx_t_9 = __pyx_v_body->a;
                ~~~~~~~~~~~~^
/usr/local/include/chipmunk/chipmunk.h:92:16: note: forward declaration of 'struct cpBody'
typedef struct cpBody cpBody;
               ^
kivent_cymunk/physics.c:8472:30: error: incomplete definition of type 'struct cpBody'
    __pyx_t_10 = __pyx_v_body->p;
                 ~~~~~~~~~~~~^
/usr/local/include/chipmunk/chipmunk.h:92:16: note: forward declaration of 'struct cpBody'
typedef struct cpBody cpBody;
               ^
2 warnings and 4 errors generated.
error: command 'clang' failed with exit status 1

MadWombat avatar Jan 11 '17 21:01 MadWombat

IIRC cymunk contains the necessary source code from chipmunk so you don't need to install it separately. Try the install once after removing chipmunk. @tito could help you better though.

udiboy1209 avatar Jan 12 '17 03:01 udiboy1209

Seems like that is not the case. I uninstalled chipmunk and started getting errors about missing header files for chipmunk.

MadWombat avatar Jan 12 '17 15:01 MadWombat

Have you installed the cymunk module? Not kivent_cymunk, just cymunk. That's where the chipmunk headers should come from

On Jan 12, 2017 7:52 AM, "Dmitriy Kropivnitskiy" [email protected] wrote:

Seems like that is not the case. I uninstalled chipmunk and started getting errors about missing header files for chipmunk.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/kivy/kivent/issues/182#issuecomment-272199129, or mute the thread https://github.com/notifications/unsubscribe-auth/AB2OUOsEEHg2wJUh0uX-MSweZVJCNBSdks5rRku9gaJpZM4LhFPv .

Kovak avatar Jan 12 '17 17:01 Kovak

Yes, I have. If I don't get actual chipmunk installed I get errors about missing headers. Here is what I get when I have cymunk installed and chipmunk uninstalled

Compiling kivent_cymunk/physics.pyx because it changed.
Compiling kivent_cymunk/interaction.pyx because it changed.
[1/2] Cythonizing kivent_cymunk/interaction.pyx
warning: kivent_cymunk/interaction.pyx:549:20: Non-trivial type declarators in shared declaration (e.g. mix of pointers and values). Each pointer declaration should be on its own line.
warning: kivent_cymunk/interaction.pyx:549:27: Non-trivial type declarators in shared declaration (e.g. mix of pointers and values). Each pointer declaration should be on its own line.
warning: kivent_cymunk/interaction.pyx:728:20: Non-trivial type declarators in shared declaration (e.g. mix of pointers and values). Each pointer declaration should be on its own line.
warning: kivent_cymunk/interaction.pyx:728:34: Non-trivial type declarators in shared declaration (e.g. mix of pointers and values). Each pointer declaration should be on its own line.
warning: kivent_cymunk/interaction.pyx:758:20: Non-trivial type declarators in shared declaration (e.g. mix of pointers and values). Each pointer declaration should be on its own line.
warning: kivent_cymunk/interaction.pyx:758:27: Non-trivial type declarators in shared declaration (e.g. mix of pointers and values). Each pointer declaration should be on its own line.
warning: kivent_cymunk/interaction.pyx:758:43: Non-trivial type declarators in shared declaration (e.g. mix of pointers and values). Each pointer declaration should be on its own line.
[2/2] Cythonizing kivent_cymunk/physics.pyx
running build_ext
building 'kivent_cymunk.physics' extension
clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/usr/local/lib/python3.6/site-packages/cymunk/__init__.py -I/usr/local/include -I/usr/local/opt/openssl/include -I/usr/local/opt/sqlite/include -I/usr/local/Cellar/python3/3.6.0/Frameworks/Python.framework/Versions/3.6/include/python3.6m -c kivent_cymunk/physics.c -o build/temp.macosx-10.12-x86_64-3.6/kivent_cymunk/physics.o -std=gnu99 -ffast-math -F/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/System/Library/Frameworks -arch x86_64
kivent_cymunk/physics.c:460:10: fatal error: 'chipmunk/chipmunk.h' file not found
#include "chipmunk/chipmunk.h"
         ^
1 error generated.
error: command 'clang' failed with exit status 1

MadWombat avatar Jan 12 '17 17:01 MadWombat

The chipmunk source is included in the cymunk module. You definitely do not need chipmunk and cymunk installed (and in fact they are probably not based on the same version etc)

If it can't find the headers even though cymunk is installed most likely there is a problem with your path. I just tested and I am able to compile on OSX here with cython 0.23.4 and cymunk and kivent master branches

Kovak avatar Jan 12 '17 19:01 Kovak

Not sure what to say. I don't have any python specific environment variables set. I just did it from scratch, made sure I don't have chipmunk anywhere, cloned kivent, installed requirements from the requirements file, installed kivent core and tried to install cymunk module and got the same exact error. One thing I find suspicious is the include flag in the compile command that says

-I/usr/local/lib/python3.6/site-packages/cymunk/__init__.py

It should probably just be the cymunk directory, not the init.py file, but I don't know where that include comes from

MadWombat avatar Jan 12 '17 19:01 MadWombat

The setup.py for each module is where such things are set:

https://github.com/kivy/kivent/blob/master/modules/cymunk/setup.py

It should indeed be something like:

-I/usr/local/lib/python2.7/site-packages/cymunk

Not certain why the difference on your machine? (although I have never tested with py3.6, only 3.4/3.5/2.7)

Kovak avatar Jan 12 '17 19:01 Kovak

This line in setup.py returns full path to init.py

cymunk_dirname = loader.path if hasattr(loader, 'path') else loader.filename

When I try this in python CLI, I get this

 In [1]   import pkgutil

 In [2]   pkgutil.get_loader('cymunk')
 Out[2]   <_frozen_importlib_external.SourceFileLoader at 0x10b75db00>

 In [3]  l = pkgutil.get_loader('cymunk')

 In [4]   l.path
 Out[4]  '/usr/local/lib/python3.6/site-packages/cymunk/__init__.py'

 In [5]   l.filename
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-5-5bd8c77f6af5> in <module>()
----> 1 l.filename

AttributeError: 'SourceFileLoader' object has no attribute 'filename'

MadWombat avatar Jan 12 '17 19:01 MadWombat

It appears this is a shift in the behavior of pkgutil

You should be able to fix it by getting the dirname of the loader.path

Will need to investigate the best solution across py versions

Kovak avatar Jan 12 '17 19:01 Kovak

Yeah, I changed it to os.path.dirname(loader.path) and it worked, but that would obviously break things for older versions

MadWombat avatar Jan 12 '17 20:01 MadWombat

Thanks for reporting this, I'll look into fixing it up this weekend.

Kovak avatar Jan 12 '17 20:01 Kovak

@Kovak @MadWombat Can you clarify what the workaround is? I tried:

import os
cymunk_dirname = os.path.dirname(loader.path)

But I then get this error:

Traceback (most recent call last):
  File "setup.py", line 104, in <module>
    cymunk_dirname = os.path.dirname(loader.path)
AttributeError: 'NoneType' object has no attribute 'path'

whattis avatar Feb 18 '17 07:02 whattis

I had this "AttributeError: 'NoneType' object has no attribute 'filename'" error today when trying to build kivent_cymunk module. The root cause was cymunk module was not found. It turned out when I built cymunk it was not install into the ...\Lib\site-packages folder but inplace with the source. I built cymunk again to make sure it end up in ..\Lib\site-packages\cymunk and then I was able to build kivent_cymunk successfully. Steps: git clone https://github.com/kivy/cymunk.git cd cymunk python setup.py build_ext install you should now see ..\Lib\site-packages\cymunk in your python folder.

zhaoyun95 avatar Aug 20 '17 09:08 zhaoyun95

On ubuntu

$ python3 setup.py build_ext --inplace
Using distutils
Traceback (most recent call last):
  File "setup.py", line 108, in <module>
    cymunk_dirname = loader.path if hasattr(loader, 'path') else loader.filename
AttributeError: 'NoneType' object has no attribute 'filename'

Meh

bitnom avatar Oct 01 '17 18:10 bitnom

Tried this cymunk_dirname = os.path.dirname(loader.path) if hasattr(loader, 'path') else loader.filename

Traceback (most recent call last):
  File "setup.py", line 108, in <module>
    cymunk_dirname = os.path.dirname(loader.path) if hasattr(loader, 'path') else loader.filename
AttributeError: 'NoneType' object has no attribute 'filename'

bitnom avatar Oct 01 '17 19:10 bitnom

the root cause of this error is that cymunk does not appear to be installed, i notice you also have an issue over in the kivy/cymunk . Have you successfully built and installed cymunk?

Kovak avatar Oct 01 '17 22:10 Kovak