Mac OS - Failed to install python-spidermonkey because nspr not found

1.4k views Asked by At

Trying to install python-spidermonkey using pip on my Mac OS, failed to do so because it's missing nspr:

$ pip install python-spidermonkey
Downloading/unpacking python-spidermonkey
  Running setup.py egg_info for package python-spidermonkey
    Traceback (most recent call last):
      File "<string>", line 16, in <module>
      File "/Users/smin/ENV/build/python-spidermonkey/setup.py", line 186, in <module>
        **platform_config()
      File "/Users/smin/ENV/build/python-spidermonkey/setup.py", line 143, in platform_config
        return nspr_config(config=config)
      File "/Users/smin/ENV/build/python-spidermonkey/setup.py", line 87, in nspr_config
        return pkg_config("nspr", config)
      File "/Users/smin/ENV/build/python-spidermonkey/setup.py", line 59, in pkg_config
        raise RuntimeError("No package configuration found for: %s" % pkg_name)
    RuntimeError: No package configuration found for: nspr
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):

  File "<string>", line 16, in <module>

  File "/Users/shengjiemin/work/Ceilo-ENV/build/python-spidermonkey/setup.py", line 186, in <module>

    **platform_config()

  File "/Users/smin/rmonkey/setup.py", line 143, in platform_config

    return nspr_config(config=config)

  File "/Users/smin/ENV/build/python-spidermonkey/setup.py", line 87, in nspr_config

    return pkg_config("nspr", config)

  File "/Users/smin/ENV/build/python-spidermonkey/setup.py", line 59, in pkg_config

    raise RuntimeError("No package configuration found for: %s" % pkg_name)

RuntimeError: No package configuration found for: nspr

----------------------------------------
Command python setup.py egg_info failed with error code 1 in /Users/smin/ENV/build/python-spidermonkey

I then tried to install nspr:

sudo port install nspr

but it didn't make any difference, still the same error. Any ideas?

3

There are 3 answers

0
Shengjie On BEST ANSWER

Finally I got this fixed by myself by following the thread here :

http://davisp.lighthouseapp.com/projects/26898/tickets/38-trouble-installing-on-mac-os-x-107

Two steps:

1.move the files from the Darwin-XXX folder inside spidermonkey to spider monkey/libjs to get through this error.

cd /home/smin/virt-ENV/build/python-spidermonkey/spidermonkey
mv Darwin-i386/* libjs/

2.Make the change below in the file: libjs/jsutil

from:

typedef int js_static_assert_line##line[(condition) ? 1 : -1]

to:

typedef int js_static_assert_line##line[(condition) ? 1 : 0]
0
d_anchakov On

First install nspr and set system variables:

$ brew install pkg-config
$ brew install nspr
$ export ARCHFLAGS="-arch x86_64" 
$ export PKG_CONFIG_PATH=/path/to/pkgconfig ## e.g. /usr/local/lib/pkgconfig

Now get the latest version of the code:

$ git clone git://github.com/davisp/python-spidermonkey.git

Now run update js libs and remove tmp dir:

$ update-libjs.sh
$ rm -r /path/to/tmp/in/spidermonkey/dir ## e.g. ./tmp

The file libjs/jsutil.h replace line 76 from

typedef int js_static_assert_line_##line[(condition) ? 1 : -1]

to

typedef int js_static_assert_line_##line[(condition) ? 1 : 0]

The file libjs/jsprf.c comment line 644

//VARARGS_ASSIGN(nas[cn].ap, ap);

Now install the lib

$ python setup.py build
$ python setup.py test
$ python setup.py install 
0
ronnefeldt On

I found a workaround (the third line below) for installing on MacOS 10.9.

$ brew install pkg-config
$ brew install nspr
$ cd /usr/local/lib/pkgconfig/  # IMPORTANT
$ ln -s nspr.pc ../../Cellar/nspr/4.10.8_1/lib/pkgconfig/nspr.pc

$ git clone git://github.com/davisp/python-spidermonkey.git
$ cd python-spidermonkey
$ cp spidermonkey/Linux-x86_64/* spidermonkey/libjs/
$ python setup.py build
$ python setup.py test  # test failed, but it's okay to ignore

$ sudo python setup.py install

This works fine with my python code that uses spidermonkey module like below. Hope this helps.

rt = spidermonkey.Runtime()
cx = rt.new_context()
cx.execute(js)
cx.execute("...")