My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
BuildingfromSource  
Building from source for all platforms
Phase-Deploy, Featured
Updated Mar 30, 2011 by sir...@gmail.com

Building from Source

Linux

To compile the latest SVN version, follow these steps:

  1. Download and install the latest version of SWIG (preferably 2.0.0+) with your package manager.
  2. If you are using Ubuntu, you can install it via Synaptic Package Manager (package name 'swig'). You will also need to install the python-dev package, and build-essential (and python-pygame if you want to run the testbed).
    sudo apt-get install build-essential python-dev swig python-pygame subversion
  3. Check out the SVN
  4. svn checkout http://pybox2d.googlecode.com/svn/trunk/ pybox2d
  5. Build and install the pybox2d library
  6. python setup.py build
    # Assuming everything goes well...
    sudo python setup.py install --force

Errors

Old versions of setuptools

If you see an error like this:

  File "/usr/lib/python2.6/distutils/command/build_ext.py", line 460, in
build_extension
    ext_path = self.get_ext_fullpath(ext.name)
  File "/usr/lib/python2.6/distutils/command/build_ext.py", line 633, in
get_ext_fullpath
    filename = self.get_ext_filename(modpath[-1])
  File "build/bdist.linux-i686/egg/setuptools/command/build_ext.py", line
85, in get_ext_filename
KeyError: '_Box2D'

Upgrade your setuptools version. 'setup.py' has been patched in the pybox2d branch for the upcoming 2.1.0 release, but not for the trunk (2.0.2 series).

64-bit Linux

Building from the 2.0.2b1 source release, there will be errors like:

Box2D/Box2D_wrap.cpp:3528: error: cast from b2Joint* to int32* loses precision

This issue was fixed soon after the release, but it was never repackaged for another release. If you update the individual

files found in this SVN version and recompile, you'll have a mostly identical copy to 2.0.2b1,

just with a few additional setters. If you don't care about having perfect 2.0.2b1 compatibility, try building from the latest SVN instead.

Windows

  1. Install MinGW and then MSYS so that you can compile Box2D and pybox2d.
  2. Install SWIG for making the Python wrapper. Install it in a location in your PATH, or add the SWIG directory to your PATH.
  3. Create Python\Lib\distutils\distutils.cfg, if it doesn't exist, and add:
  4. [build]
    compiler=mingw32
    [build_ext]
    compiler=mingw32
  5. If you want to build from the SVN, install the Subversion client. Check out the project by doing
  6. svn checkout http://pybox2d.googlecode.com/svn/trunk/ pybox2d
  7. Run MSYS and locate your pybox2d directory
  8. cd /c/path/to/pybox2d/Box2D
  9. Build and install pybox2d
  10. setup.py build
    setup.py install --force

OS X

Dependencies

To build pybox2d, you will need:

  • Apple Developer Tools (see below)
  • SWIG (see below)
  • Python (of course)

Install Apple Developer Tools

  1. This step is only required if the Apple Developer tools have not already been installed.
  2. Download the Apple Developer Tools or install them from the System Installer CD provided with your Mac.
  3. Download from: http://developer.apple.com/tools/
  4. This will give your system all the tools it needs for software development.
  5. These tools are required for you to proceed to the next step.

SWIG Installation

  1. Download the latest source release of SWIG here
  2. Place the file onto your Desktop
  3. Open Terminal.app located in the Applications/Utilities folder
  4. Then enter the following into the terminal window:
  5. cd ~/Desktop
    tar -zxf swig-*.tar.gz
    cd swig-*
    ./configure
    make
    sudo make install
    <ENTER THE ADMINISTRATOR/ROOT PASSWORD>
  6. Hopefully all went well and no errors occurred.
  7. Close the Terminal.app window
  8. SWIG is now installed onto the system and we can now move to the next step.

pybox2d Installation

  1. Download the latest source distribution of pybox2d here
  2. Place the file onto your Desktop
  3. Open Terminal.app located in the Applications/Utilities folder
  4. Then enter the following into the terminal window:
  5. cd ~/Desktop
    unzip Box2D-*.zip
    cd Box2D-*/
    python setup.py build
If all went well,
sudo python setup.py install --force
<ENTER THE ADMINISTRATOR/ROOT PASSWORD>
Close the Terminal.app window and see the links on the project home page for the testbed and documentation.

OS X Snow Leopard / 64-bit Installations

Building from the 2.0.2b1 source release, there will be errors like:

Box2D/Box2D_wrap.cpp:3528: error: cast from b2Joint* to int32* loses precision

This issue was fixed soon after the release, but it was never repackaged for another release. If you update the individual files found in this SVN version and recompile, you'll have a mostly identical copy to 2.0.2b1, just with a few additional setters. If you don't care about having perfect 2.0.2b1 compatibility, try building from the latest SVN instead (see the next section).

Building pybox2d from the SVN

This is only necessary if you want the latest features that pybox2d has to offer. Follow the above headings Install Apple Developer Tools and SWIG Installation. Now follow the steps 2 and beyond for Linux.

Comment by ntzape...@gmail.com, Feb 22, 2009
running build
running build_py
copying ./Box2D.py -> build/lib.linux-i686-2.5/Box2D
running build_ext
building 'Box2D._Box2D' extension
swigging Box2D/Box2D.i to Box2D/Box2D_wrap.cpp
swig -python -c++ -IBox2D -O -includeall -ignoremissing -w201 -outdir . -o Box2D/Box2D_wrap.cpp Box2D/Box2D.i
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.5 -c Box2D/Box2D_wrap.cpp -o build/temp.linux-i686-2.5/Box2D/Box2D_wrap.o -I.
cc1plus: warning: command line option "-Wstrict-prototypes" is valid for Ada/C/ObjC but not for C++
Box2D/Box2D_wrap.cpp:140:20: error: Python.h: No such file or directory
Box2D/Box2D_wrap.cpp:3092:4: error: #error "This python version requires swig to be run with the '-classic' option"
Box2D/Box2D_wrap.cpp:3096:3: error: #error "This python version requires swig to be run with the '-nomodern' option"
Box2D/Box2D_wrap.cpp:3099:3: error: #error "This python version requires swig to be run with the '-nomodernargs' option"
Box2D/Box2D_wrap.cpp:3102:3: error: #error "This python version requires swig to be run with the '-nofastunpack' option"
Box2D/Box2D_wrap.cpp:746: error: expected initializer before ‘*’ token
Box2D/Box2D_wrap.cpp:801: error: expected initializer before ‘*’ token
Box2D/Box2D_wrap.cpp:822: error: expected initializer before ‘*’ token
In file included from /usr/include/c++/4.3/new:45,
                 from /usr/include/c++/4.3/ext/new_allocator.h:37,
                 from /usr/include/c++/4.3/i486-linux-gnu/bits/c++allocator.h:39,
                 from /usr/include/c++/4.3/bits/allocator.h:53,
                 from /usr/include/c++/4.3/string:48,
                 from Box2D/Box2D_wrap.cpp:2511:
/usr/include/c++/4.3/exception:40: error: expected declaration before end of line
error: command 'gcc' failed with exit status 1

Python 2.5.2
SWIG Version 1.3.35
gcc (Ubuntu 4.3.2-1ubuntu12) 4.3.2
Comment by project member sir...@gmail.com, Feb 22, 2009

ntzaperas, do you have the python-dev package installed? It doesn't look like gcc is able to find it -- see the first error:

Box2D/Box2D_wrap.cpp:140:20: error: Python.h: No such file or directory
Comment by pirat...@gmail.com, Mar 31, 2009

Hi!.. awesome job with this wrapper!.. but I found a blocking error when trying to install it on a 64bit linux:

Box2D/Box2D_wrap.cpp: In function ‘int32 b2Jointhash(b2Joint)’: 
  Box2D/Box2D_wrap.cpp:3548: error: cast from ‘b2Joint*’ to ‘int32’ loses precision 

I managed to work around this by replacing int32 with unsigned long.. but I'm not 100% sure whether it causes undesired side effects.

Comment by project member sir...@gmail.com, Apr 1, 2009

Hi piratiss, Thanks for the comment. The 64bit error you mentioned should have been already fixed in the latest SVN.

Comment by paolovic...@gmail.com, Jul 23, 2009

Hello,

I had the same problem as piratiss. I just want to confirm that it has been fixed at the latest SVN build.

Comment by kersp...@gmail.com, Jul 29, 2009

I had the same problems as ntzaperas, which was fixed when I installed the python-dev package.

There is still a lot of warnings, mostly this one

warning: command line option "-Wstrict-prototypes" is valid for Ada/C/ObjC but not for C++
Comment by akirossp...@gmail.com, Jan 3, 2010

Compiled successfully, but

$ python
Python 2.6.2 (r262:71600, Aug 21 2009, 12:23:57) 
[GCC 4.4.1 20090818 (Red Hat 4.4.1-6)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import Box2D
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "Box2D.py", line 28, in <module>
    _Box2D = swig_import_helper()
  File "Box2D.py", line 20, in swig_import_helper
    import _Box2D
ImportError: No module named _Box2D
>>>
Comment by project member sir...@gmail.com, Jan 3, 2010

akirosspower,

Have you tried changing directories outside of the pybox2d source's? For example, try to load it up when running Python in your home directory.

Comment by akirossp...@gmail.com, Jan 3, 2010

Oh gosh, you were right! I didn't notice my working directory was the same :S Thanks :) Sorry


Sign in to add a comment
Powered by Google Project Hosting