Importing PyV8 Engine into Python 2.7, the easy way

PyV8 is a Python wrapper module to perform JavaScript emulation on the fly like the way we do in SpiderMonkey. But, if you are having a hard-time configuring/compiling PyV8 sources then its always recommended to use the compiled binaries. If you are able to compile the V8 sources successfully without any errors then you don’t have to follow the below steps. The below steps are for those who were unable to import the PyV8 module into their Python interactive console. Please follow the below steps accordingly.

Generally below is the location where the Python v2.x modules are stored:

/usr/lib/python2.7/dist-packages/

You can fetch the list of PyV8 sources from the below URL:

https://code.google.com/p/pyv8/downloads/list?can=1

Download the appropriate package which suits your OS flavor. Extract the files into your desktop and copy both the files i..e “PyV8.py” and “_PyV8.so” to the location from where Python looks for the presence of modules. You can follow the the below steps if it was confusing at the first place.

$ cd ~/tmp/
$ wget -c "https://raw.githubusercontent.com/emmetio/pyv8-binaries/master/pyv8-linux32.zip"
$ unzip pyv8-linux32.zip
$ sudo cp *PyV8* /usr/lib/python2.7/dist-packages/

Afterwards to verify if you can import the wrapper module successfully, fire your Python console and import PyV8 Module. If you are able to see the output like below then you are all set!

    testuser@xylux:~$ python
    Python 2.7.6 (default, Apr 10 2015, 08:20:38) 
    [GCC 4.8.2] on linux2
    ...
    >>> import PyV8
    >>> dir(PyV8)
    ['AST', 'DontDelete', 'DontEnum', 'HAS_UTF8', 'Internal', 'JSAllocationAction', 'JSArray', 'JSAttribute', 'JSClass', 'JSClassConstructor', 'JSClassPrototype', 'JSContext', 'JSDebugEvent', 'JSDebugProtocol', 'JSDebugger', 'JSEngine', 'JSError', 'JSExtension', 'JSFunction', 'JSIsolate', 'JSLocker', 'JSObject', 'JSObjectSpace', 'JSProfiler', 'JSScript', 'JSStackFrame', 'JSStackTrace', 'JSUnlocker', 'JS_ESCAPABLE', 'MAXYEAR', 'MINYEAR', 'ReadOnly', 'StringIO', 'TestAST', 'TestContext', 'TestDebug', 'TestEngine', 'TestMultithread', 'TestProfile', 'TestWrapper', '_PyV8', '__all__', '__author__', '__builtins__', '__doc__', '__file__', '__name__', '__package__', '__version__', '_js_escape_unicode_re_callack', 'collections', 'convert', 'date', 'datetime', 'datetime_CAPI', 'func_apply', 'is_py3k', 'js_escape_unicode', 'json', 'logging', 'os', 'print_function', 'profiler', 're', 'sys', 'thread', 'time', 'timedelta', 'toNativeString', 'toUnicodeString', 'traceback', 'tzinfo', 'unittest', 'with_statement']
Comments powered by Disqus