Forum Archive

JS2PY install fails

ihf

I was just trying to see if the Javascript to Python code would run under Pythonista but I wasn't able to install it using Stash v0.6.18.

[~/Documents]$ pip install js2py
Querying PyPI ...
Downloading package ...
Opening: https://pypi.python.org/packages/5e/57/8502ea8f875e81fe0262f7322bd7e44f086eb2d7e5cc4aae3926fd955e99/Js2Py-0.41.tar.gz
Save as: /private/var/mobile/Containers/Data/Application/AC330A84-B44A-41B7-9DC2-B02FEB732BF0/tmp/Js2Py-0.41.tar.gz (506783 bytes)
506783 [100.00%]
Extracting archive file ...
Archive extracted.
Running setup file ...
stash: : invalid interpolation syntax in 'JavaScript to Python Translator & JavaScript interpreter written in 100% pure Python.' at position 71

Anyone know how to install this? It is pure python so (in theory) it should work.

ccc

Python is interpreting the % as an old style string format. Try changing 100% to 100%% and install again.

ihf

Sorry, but I'm merely entering "pip install js2py' in Stash. Where should I make the change?

ccc

That text should be in the setup.py file inside the archive file: Js2Py-0.41.tar.gz

ihf

I don't think that is the problem. The '100%' is just part of the literal definition:

'description='JavaScript to Python Translator & JavaScript interpreter written in 100% pure Python.' in the setup.py module.

If I ignore the setup failure and enter import js2py in the console, and I get "No module name pyjsparser"

ccc

Try typing your error message into Google and see what comes back... Based on your error message, I believe that Python is trying to interpolate the string in question.

You could try opening and issue on https://github.com/PiotrDabkowski/Js2Py and see if those folks have advice.

ihf

I tried the pip install on OSX and it worked fined. Perhaps pip install on Stash can't do this?

ihf$ pip install js2py
Collecting js2py
Downloading Js2Py-0.41.tar.gz (506kB)
100% |################################| 512kB 1.6MB/s
Collecting tzlocal>=1.2 (from js2py)
Downloading tzlocal-1.3.tar.gz
Collecting six>=1.10 (from js2py)
Downloading six-1.10.0-py2.py3-none-any.whl
Collecting pyjsparser>=2.4.5 (from js2py)
Downloading pyjsparser-2.4.5.tar.gz
Requirement already satisfied: pytz in /anaconda/lib/python2.7/site-packages (from tzlocal>=1.2->js2py)
Building wheels for collected packages: js2py, tzlocal, pyjsparser
Running setup.py bdist_wheel for js2py ... done
Stored in directory: /Users/ihf/Library/Caches/pip/wheels/24/50/10/50f3fc4c1c77e4f1bda05d28b1979259a357f5c06bd28e99af
Running setup.py bdist_wheel for tzlocal ... done
Stored in directory: /Users/ihf/Library/Caches/pip/wheels/80/19/a8/635ad9f4ad8a63b49d073c55cbca31fb5898ce2560ed145a69
Running setup.py bdist_wheel for pyjsparser ... done
Stored in directory: /Users/ihf/Library/Caches/pip/wheels/34/83/7d/0bdaeb6cf9b13ae9cd9aacd1dd0b59b91df81eb7a68938a035
Successfully built js2py tzlocal pyjsparser
Installing collected packages: tzlocal, six, pyjsparser, js2py
Found existing installation: six 1.8.0
Uninstalling six-1.8.0:
Successfully uninstalled six-1.8.0
Successfully installed js2py-0.41 pyjsparser-2.4.5 six-1.10.0 tzlocal-1.3

ccc

Try to install tzlocal and pyjsparser first. This is what happened on your Mac install.

ihf

Thanks, that helped (import js2py works) but if I try a simple test:

import js2py
>>> js2py.eval_js('console.log( "Hello World!" )')

I get a long Traceback.

ihf

Here is the Traceback in case anyone can make sense of it:

import js2py
js2py.eval_js('console.log("hello worlds")')
/private/var/mobile/Containers/Shared/AppGroup/637EEB4B-60E1-4F48-A8E5-66F2C7D9FCA2/Pythonista3/Documents/site-packages/js2py/constructors/time_helpers.py:10: UserWarning: Please install or fix tzlocal library (pip install tzlocal) in order to make Date object work better. Otherwise I will assume DST is in effect all the time
warnings.warn('Please install or fix tzlocal library (pip install tzlocal) in order to make Date object work better. Otherwise I will assume DST is in effect all the time')
Traceback (most recent call last):
File "", line 1, in
File "/private/var/mobile/Containers/Shared/AppGroup/637EEB4B-60E1-4F48-A8E5-66F2C7D9FCA2/Pythonista3/Documents/site-packages/js2py/evaljs.py", line 111, in eval_js
return e.eval(js)
File "/private/var/mobile/Containers/Shared/AppGroup/637EEB4B-60E1-4F48-A8E5-66F2C7D9FCA2/Pythonista3/Documents/site-packages/js2py/evaljs.py", line 180, in eval
self.execute(code, use_compilation_plan=use_compilation_plan)
File "/private/var/mobile/Containers/Shared/AppGroup/637EEB4B-60E1-4F48-A8E5-66F2C7D9FCA2/Pythonista3/Documents/site-packages/js2py/evaljs.py", line 175, in execute
exec(compiled, self._context)
File "", line 2, in
File "/private/var/mobile/Containers/Shared/AppGroup/637EEB4B-60E1-4F48-A8E5-66F2C7D9FCA2/Pythonista3/Documents/site-packages/js2py/base.py", line 834, in call
return self.call(self.GlobalObject, args)
File "/private/var/mobile/Containers/Shared/AppGroup/637EEB4B-60E1-4F48-A8E5-66F2C7D9FCA2/Pythonista3/Documents/site-packages/js2py/base.py", line 1280, in call
return Js(self.code(*args))
File "/private/var/mobile/Containers/Shared/AppGroup/637EEB4B-60E1-4F48-A8E5-66F2C7D9FCA2/Pythonista3/Documents/site-packages/js2py/host/jseval.py", line 10, in Eval
local_scope = inspect.stack()[3][0].f_locals['var']
File "/var/containers/Bundle/Application/1950D74B-DAE2-43A7-8ACE-EC2021668793/Pythonista3.app/Frameworks/Py2Kit.framework/pylib/inspect.py", line 1061, in stack
return getouterframes(sys._getframe(1), context)
File "/var/containers/Bundle/Application/1950D74B-DAE2-43A7-8ACE-EC2021668793/Pythonista3.app/Frameworks/Py2Kit.framework/pylib/inspect.py", line 1039, in getouterframes
framelist.append((frame,) + getframeinfo(frame, context))
File "/var/containers/Bundle/Application/1950D74B-DAE2-43A7-8ACE-EC2021668793/Pythonista3.app/Frameworks/Py2Kit.framework/pylib/inspect.py", line 1014, in getframeinfo
lines, lnum = findsource(frame)
File "/var/containers/Bundle/Application/1950D74B-DAE2-43A7-8ACE-EC2021668793/Pythonista3.app/Frameworks/Py2Kit.framework/pylib/inspect.py", line 533, in findsource
module = getmodule(object, file)
File "/var/containers/Bundle/Application/1950D74B-DAE2-43A7-8ACE-EC2021668793/Pythonista3.app/Frameworks/Py2Kit.framework/pylib/inspect.py", line 498, in getmodule
f = getabsfile(module)
File "/var/containers/Bundle/Application/1950D74B-DAE2-43A7-8ACE-EC2021668793/Pythonista3.app/Frameworks/Py2Kit.framework/pylib/inspect.py", line 467, in getabsfile
_filename = getsourcefile(object) or getfile(object)
File "/var/containers/Bundle/Application/1950D74B-DAE2-43A7-8ACE-EC2021668793/Pythonista3.app/Frameworks/Py2Kit.framework/pylib/inspect.py", line 452, in getsourcefile
if os.path.exists(filename):
File "/var/containers/Bundle/Application/1950D74B-DAE2-43A7-8ACE-EC2021668793/Pythonista3.app/Frameworks/Py2Kit.framework/pylib/genericpath.py", line 28, in exists
os.stat(path)
TypeError: coercing to Unicode: need string or buffer, OmniClass found

ihf

I restarted Pythonista and the errors above disappeared. The only warning message I get now is something about the Date object and the assumption of DST and the need to install or fix tzlocal though that was installed as per @ccc suggestion.

ywangd

This was caused by a bug in pip when it registers installed package, which is backed by RawConfigParser. The RawConfigParser has its own string interpolation rule which relies on the percentage sign.

The bug has now been fixed and you can get it by selfupdate -f.