My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
HowToBuild  
How to build the module from source
Phase-Implementation, Phase-Deploy, Featured
Updated Aug 10, 2011 by flier...@gmail.com

Build Steps

Precompiled Packages

If you want to try pyv8 ASAP, we suggest you use precompiled package for your platform.

Please downloads the precompiled packages for Windows and Linux/Debian.

tocer also provide packages (1) (2) for ArchLinux

Build the module

Just run the setup.py with install or build command

setup.py install

Build the distribution

Just run the setup.py with bdist or bdist_wininst command

setup.py bdist_wininst

Third Party Library

Python

As the runtime and libraries, download and install Python 2.5 or later first.

set environment variable PYTHON_HOME to the python root folder

Boost

PyV8 use boost::python for interoperability, so, download the latest boost version and build the library.

set environment variable BOOST_HOME to the boost root folder

Google V8

Follow the document to download and build v8 engine as static library

set environment variable V8_HOME to the v8 root folder

If you want to build v8 with GCC 4.x at x64 platform, you should compile v8 with PIC (Position-Independent Code) mode, and set the arch to x64 for scons.

export CCFLAGS=-fPIC
scons arch=x64

You may also need build Boost with '-fPIC' argument.

./bjam --clean
./bjam cxxflags=-fPIC

Runtime Type Information and C++ Exception in v8 3.0

From the v8 engine 3.0, the build script of v8 engine has disabled RTTI and Exception by default. It may save some bits of memory, but will broke the boost::python library and pyv8.

So, we must enable it before build pyv8.

For the Visual Studio, you could apply the patch or modify it by manual.

Index: common.vsprops
===================================================================
--- common.vsprops	(Version 5952)
+++ common.vsprops	(Working Copy)
@@ -8,12 +8,12 @@
 	<Tool
 		Name="VCCLCompilerTool"
 		AdditionalIncludeDirectories="$(ProjectDir)\..\..\src;$(IntDir)\DerivedSources"
-		PreprocessorDefinitions="WIN32;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;_HAS_EXCEPTIONS=0;ENABLE_VMSTATE_TRACKING;ENABLE_LOGGING_AND_PROFILING;ENABLE_DEBUGGER_SUPPORT"
+		PreprocessorDefinitions="WIN32;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;_HAS_EXCEPTIONS=1;ENABLE_VMSTATE_TRACKING;ENABLE_LOGGING_AND_PROFILING;ENABLE_DEBUGGER_SUPPORT"
 		MinimalRebuild="false"
-		ExceptionHandling="0"
-		RuntimeTypeInfo="false"
+		ExceptionHandling="1"
+		RuntimeTypeInfo="yes"
 		WarningLevel="3"
-		WarnAsError="true"
+		WarnAsError="false"
 		Detect64BitPortabilityProblems="false"
 		DebugInformationFormat="3"
 		DisableSpecificWarnings="4355;4800"

For the GCC and other environment base on the SCons, please remove the -fno-rtti and -fno-exceptions from SConstruct

Index: SConstruct
===================================================================
--- SConstruct  (revision 6041)
+++ SConstruct  (working copy)
@@ -126,7 +126,7 @@
   'gcc': {
     'all': {
       'CCFLAGS':      ['$DIALECTFLAGS', '$WARNINGFLAGS'],
-      'CXXFLAGS':     ['$CCFLAGS', '-fno-rtti', '-fno-exceptions'],
+      'CXXFLAGS':     ['$CCFLAGS'],
     },
     'visibility:hidden': {
       # Use visibility=default to disable this.
@@ -455,7 +455,6 @@
   'gcc': {
     'all': {
       'LIBPATH': ['.'],
-      'CCFLAGS': ['-fno-rtti', '-fno-exceptions']
     },
     'os:linux': {
       'LIBS':         ['pthread'],

Debug Mode

You could build Google v8 and PyV8 with debug mode, for more detail debug information.

  • Build v8 with debug mode
  • scons mode=debug # x86
    scons mode=debug arch=x64 #64
  • Set or export DEBUG=1
  • set DEBUG=1 # Windows
    export DEBUG=1 # Unix
  • Build pyv8 with setup.py
  • python setup.py build

contribute by gaussgss

FAQ

1. Fail to load PyV8.so with AttributeError exception

If you got the exception "AttributeError: 'Boost.Python.StaticProperty' object attribute 'doc' is read-only", please check your Python version. The Python 2.6.4 introduce a known issue which will break boost 1.40 or earlier version. Please use Python 2.5.x/2.6.3, or upgrade your boost to 1.41 or later.
Comment by samuraib...@gmail.com, Jun 8, 2009

The documentation doesn't mention whether or not to build v8 shared or static.

Comment by cas...@gmail.com, Nov 28, 2009

on os x 10.5 with macports managed python:

  • install boost with your python version variant "port install boost +python25"
  • check the linking of libboost_python-mt in /opt/local/lib with otool. If it is linked to the system python use install_name_tool to link it to your python
  • build v8
  • build pyv8 - you need to change the libraries in setup py to remove 'rt' and link to 'boost_python-mt'
Comment by progr...@gmail.com, Dec 6, 2009

the issue brought up on this thread was solved for me on snow leopard by removing all shared libv8 files and compiling v8 as static (and arch=x64) and copying the libv8.a file into /usr/lib (and /opt/local/lib for good measure).

Comment by progr...@gmail.com, Jan 10, 2010

also worth mentioning that on OS X you need to run setup.py with sudo, you need to set V8_HOME in the root environment. so instead of setting V8_HOME as your user, then running "sudo python setup.py install", you might want to use "sudo V8_HOME=/path/to/v8 python setup.py install".

Comment by SemigodK...@gmail.com, Apr 3, 2010

It is better to build v8 static.

BTW: Does anyone have idea on how to compile it on FreeBSD? I have difficult on solving problem below:

%python setup.py build running build running build_py running build_ext building 'PyV8?' extension cc -fno-strict-aliasing -DNDEBUG -O2 -fno-strict-aliasing -pipe -Dwchar_t=wchar_t -DTHREAD_STACK_SIZE=0x20000 -fPIC -DBOOST_PYTHON_STATIC_LIB -DV8_NATIVE_REGEXP -DENABLE_DISASSEMBLER -DENABLE_LOGGING_AND_PROFILING -DENABLE_DEBUGGER_SUPPORT -DV8_TARGET_ARCH_IA32 -I../v8/include -I../v8 -I../v8/src -I/usr/include -I/usr/local/include -I/usr/local/include/python2.6 -c src/Exception.cpp -o build/temp.freebsd-7.2-RELEASE-p4-i386-2.6/src/Exception.o In file included from /usr/include/c++/4.2/ios:47,

from /usr/include/c++/4.2/ostream:45, from /usr/include/c++/4.2/iterator:70, from /usr/local/include/boost/next_prior.hpp:15, from /usr/local/include/boost/utility.hpp:17, from /usr/local/include/boost/python/instance_holder.hpp:10, from /usr/local/include/boost/python/object/pointer_holder.hpp:14, from /usr/local/include/boost/python/to_python_indirect.hpp:10, from /usr/local/include/boost/python/converter/arg_to_python.hpp:10, from /usr/local/include/boost/python/call.hpp:15, from /usr/local/include/boost/python/object_core.hpp:12, from /usr/local/include/boost/python/args.hpp:25, from /usr/local/include/boost/python.hpp:11, from src/Exception.h:23, from src/Exception.cpp:1:
/usr/include/c++/4.2/bits/localefwd.h:58:34: error: macro "isspace" passed 2 arguments, but takes just 1 /usr/include/c++/4.2/bits/localefwd.h:70:34: error: macro "isupper" passed 2 arguments, but takes just 1 /usr/include/c++/4.2/bits/localefwd.h:74:34: error: macro "islower" passed 2 arguments, but takes just 1 /usr/include/c++/4.2/bits/localefwd.h:78:34: error: macro "isalpha" passed 2 arguments, but takes just 1 /usr/include/c++/4.2/bits/localefwd.h:94:34: error: macro "isalnum" passed 2 arguments, but takes just 1 /usr/include/c++/4.2/bits/localefwd.h:102:34: error: macro "toupper" passed 2 arguments, but takes just 1 /usr/include/c++/4.2/bits/localefwd.h:106:34: error: macro "tolower" passed 2 arguments, but takes just 1

Comment by project member flier...@gmail.com, Apr 4, 2010

Hi SemigodKing?,

It seems you should define some macro to wrap those macro, such as isspace, isupper, islower, isalpha, isalnum, toupper and tolower. I guess your FreeBSD use different definition to Linux/Windows.
Comment by SemigodK...@gmail.com, Apr 11, 2010

flier.lu,

I managed to have it compiled successfully by modifying /usr/include/c++/4.2/bits/localefwd.h. Unfortunately, the .so failed to be load.

Comment by project member flier...@gmail.com, Apr 12, 2010

Hi SemigodKing?,

Could you use ldd _pyv8.pyd to check its dependency?
Comment by SemigodK...@gmail.com, Apr 13, 2010

Here is the result. It looks like the output is not a shared object for python.

%ls -al total 3962 drwxr-xr-x 2 kitty wheel 512 Apr 4 01:43 . drwxr-xr-x 4 kitty wheel 512 Apr 4 00:44 .. -rw-r--r-- 1 kitty wheel 48142 Jan 31 07:55 PyV8?.py -rw-r--r-- 1 kitty wheel 54262 Apr 4 01:43 PyV8?.pyc -rwxr-xr-x 1 kitty wheel 3924374 Apr 4 01:42 PyV8?.so %ldd -v PyV8?.so ldd: PyV8?.so: this is an ELF program; use objdump to examine

%objdump -i PyV8?.so BFD header file version 2.15 FreeBSD? 2004-05-23 elf32-i386-freebsd

(header little endian, data little endian)
i386
elf32-i386
(header little endian, data little endian)
i386
srec
(header endianness unknown, data endianness unknown)
i386
symbolsrec
(header endianness unknown, data endianness unknown)
i386
tekhex
(header endianness unknown, data endianness unknown)
i386
binary
(header endianness unknown, data endianness unknown)
i386
ihex
(header endianness unknown, data endianness unknown)
i386

elf32-i386-freebsd elf32-i386 srec symbolsrec tekhex binary
i386 elf32-i386-freebsd elf32-i386 srec symbolsrec tekhex binary
ihex
i386 ihex

Comment by SnowYu....@gmail.com, Aug 13, 2010

build on ubuntu, no boost installed:

u should add the BOOST_HOME in setup.py: elif os.name == "posix" and sys.platform == "linux2":

library_dirs += [
V8_HOME, os.path.join(BOOST_HOME, 'stage/lib'), #<----------------here
]

Comment by norman.k...@gmail.com, Oct 12, 2010

i am having issues building this on OSX with this error:

src/Exception.cpp: In static member function ‘static void ExceptionTranslator::Construct(PyObject*, boost::python::converter::rvalue_from_python_stage1_data*)’:
src/Exception.cpp:262: warning: unused variable ‘cpp_err’
error: command '/usr/bin/gcc-4.2' failed with exit status 1

full output here: http://pastie.org/1215681

what am i missing here?

thanks

Comment by theo...@gmail.com, Nov 17, 2010

Hi SnowYu?.LEE and all,

I am experiencing the same error on ubuntu 10.10 and your solution doesnt work. Any other ideas? What exactly do i need to build in Boost? - I just built the libraries. Does this suffice?

thanks,

Comment by project member flier...@gmail.com, Nov 17, 2010

Hi theohar,

Could you try to checkout and compile pyv8 from SVN trunk? The public API of v8 project has changed after pyv8 0.9 released, I'm working on the pyv8 1.0 which may solve your issue.

Thanks

Comment by theo...@gmail.com, Nov 18, 2010

Hello all,

I built py-v8 successfully from SVN and when i try to run a simple example I am getting this error:

import PyV8? ImportError?: libv8.so: cannot open shared object file: No such file or directory

I can see this file under v8 dir and I have V8_HOME pointing to this dir. I also tried to copy it under /usr/lib but still no luck.

Any ideas please?

Comment by project member flier...@gmail.com, Nov 18, 2010

Hi theohar,

Could you submit a issue to follow up your problem?

http://code.google.com/p/pyv8/issues/list

I think you must build and link v8 with the static mode


Sign in to add a comment
Powered by Google Project Hosting