Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jinja2: no filter named to json #649

Closed
LovelyBuggies opened this issue May 24, 2020 · 8 comments
Closed

jinja2: no filter named to json #649

LovelyBuggies opened this issue May 24, 2020 · 8 comments

Comments

@LovelyBuggies
Copy link
Contributor

Before you open an issue, please make sure you have tried the following steps:

  1. Make sure your environment is the same with (https://mace.readthedocs.io/en/latest/installation/env_requirement.html).
  2. Have you ever read the document for your usage?
  3. Check if your issue appears in HOW-TO-DEBUG or FAQ.
  4. The form below must be filled.

System information

  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Linux Ubuntu 16.04
  • NDK version(e.g., 15c): r15c
  • GCC version(if compiling for host, e.g., 5.4.0): 5.4.0
  • MACE version (Use the command: git describe --long --tags): v0.13.0-0-g9a06864
  • Python version(2.7):
  • Bazel version (e.g., 0.13.0):

Describe the problem

no filter named to json when building standalone. I tried the method in #620's #620 (comment). But apt-get install python3-jinja2==2.8.1 automatically, which will generate the problem jinja2.exceptions.TemplateAssertionError: no filter named 'tojson'.

P.S. A possible solution would be to upgrade jinja2 simonw/datasette#100 (comment), but not sure how to do it (apt-get upgrade python-jinja2 would always give me a 2.8.0). PyPI can get jinja2 2.11.0, but is of no use as mentioned above. Btw, aptitude gives me 2.8.0, too.😣

To Reproduce

Steps to reproduce the problem:

bash tools/bazel-build-standalone-lib.sh [-abi=abi][-runtimes=rt1,rt2,...][-static]

Error information / logs

Please include the full log and/or traceback here.

build shared lib for armeabi-v7a + cpu_gpu_dsp
Starting local Bazel server and connecting to it...
............
write version v0.13.0-0-g9a06864 to /home/parallels/.cache/bazel/_bazel_parallels/5ff1ff2df121917af4fe9fa25c7709ef/external/local_version_config/gen/version
Traceback (most recent call last):
  File "/home/parallels/.cache/bazel/_bazel_parallels/5ff1ff2df121917af4fe9fa25c7709ef/external/mace//mace/python/tools/encrypt_opencl_codegen.py", line 130, in <module>
    encrypt_opencl_codegen(FLAGS.cl_kernel_dir, FLAGS.output_path)
  File "/home/parallels/.cache/bazel/_bazel_parallels/5ff1ff2df121917af4fe9fa25c7709ef/external/mace//mace/python/tools/encrypt_opencl_codegen.py", line 104, in encrypt_opencl_codegen
    encrypted_code_maps, 'str2vec_maps.cc.jinja2', output_path)
  File "/home/parallels/.cache/bazel/_bazel_parallels/5ff1ff2df121917af4fe9fa25c7709ef/external/mace//mace/python/tools/encrypt_opencl_codegen.py", line 60, in write_cl_encrypted_kernel_to_file
    cl_encrypted_kernel = env.get_template(template_path).render(
  File "/usr/lib/python2.7/dist-packages/jinja2/environment.py", line 812, in get_template
    return self._load_template(name, self.make_globals(globals))
  File "/usr/lib/python2.7/dist-packages/jinja2/environment.py", line 786, in _load_template
    template = self.loader.load(self, name, globals)
  File "/usr/lib/python2.7/dist-packages/jinja2/loaders.py", line 125, in load
    code = environment.compile(source, name, filename)
  File "/usr/lib/python2.7/dist-packages/jinja2/environment.py", line 565, in compile
    self.handle_exception(exc_info, source_hint=source_hint)
  File "/usr/lib/python2.7/dist-packages/jinja2/environment.py", line 754, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/home/parallels/.cache/bazel/_bazel_parallels/5ff1ff2df121917af4fe9fa25c7709ef/external/mace//mace/python/tools/str2vec_maps.cc.jinja2", line 28, in template
    {{key|tojson}}, {
jinja2.exceptions.TemplateAssertionError: no filter named 'tojson'
ERROR: /home/parallels/mace/mace/codegen/BUILD.bazel:26:1: no such target '@local_opencl_kernel_encrypt//:gen/encrypt_opencl_kernel.cc': target 'gen/encrypt_opencl_kernel.cc' not declared in package '' defined by /home/parallels/.cache/bazel/_bazel_parallels/5ff1ff2df121917af4fe9fa25c7709ef/external/local_opencl_kernel_encrypt/BUILD.bazel and referenced by '//mace/codegen:encrypt_opencl_kernel_gen'
ERROR: /home/parallels/mace/mace/codegen/BUILD.bazel:26:1: no such target '@local_opencl_kernel_encrypt//:gen/encrypt_opencl_kernel.h': target 'gen/encrypt_opencl_kernel.h' not declared in package '' defined by /home/parallels/.cache/bazel/_bazel_parallels/5ff1ff2df121917af4fe9fa25c7709ef/external/local_opencl_kernel_encrypt/BUILD.bazel and referenced by '//mace/codegen:encrypt_opencl_kernel_gen'
ERROR: Analysis of target '//mace/libmace:libmace_dynamic' failed; build aborted: Loading failed
INFO: Elapsed time: 6.718s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (33 packages loaded)
@LovelyBuggies LovelyBuggies changed the title no filter named to json jinja2: no filter named to json May 24, 2020
@LovelyBuggies
Copy link
Contributor Author

LovelyBuggies commented May 24, 2020

@lee-bin I think it should be okay to install jinja2 by pip, but not sure why #620 (forced to use apt or aptitude) happens?

@lee-bin
Copy link
Member

lee-bin commented May 25, 2020

@LovelyBuggies
Please try this pip install jinja2==2.10.
I'm not sure about #620, may be different versions of python are used.

@LovelyBuggies
Copy link
Contributor Author

LovelyBuggies commented May 25, 2020

Please try this pip install jinja2==2.10.
I'm not sure about #620, may be different versions of python are used.

Yeah, I tried, the fact is that I had jinja2==2.11.2 installed, but got ImportError: No module named jinja2 error when running bash tools/bazel-build-standalone-lib.sh [-abi=abi][-runtimes=rt1,rt2,...][-static].

$ bash tools/bazel-build-standalone-lib.sh [-abi=abi][-runtimes=rt1,rt2,...][-static]
build shared lib for armeabi-v7a + cpu_gpu_dsp
Starting local Bazel server and connecting to it...
...........
write version v0.13.0-0-g9a06864 to /home/parallels/.cache/bazel/_bazel_parallels/5ff1ff2df121917af4fe9fa25c7709ef/external/local_version_config/gen/version
Traceback (most recent call last):
  File "/home/parallels/.cache/bazel/_bazel_parallels/5ff1ff2df121917af4fe9fa25c7709ef/external/mace//mace/python/tools/encrypt_opencl_codegen.py", line 20, in <module>
    import jinja2
ImportError: No module named jinja2
ERROR: /home/parallels/mace/mace/codegen/BUILD.bazel:26:1: no such target '@local_opencl_kernel_encrypt//:gen/encrypt_opencl_kernel.cc': target 'gen/encrypt_opencl_kernel.cc' not declared in package '' defined by /home/parallels/.cache/bazel/_bazel_parallels/5ff1ff2df121917af4fe9fa25c7709ef/external/local_opencl_kernel_encrypt/BUILD.bazel and referenced by '//mace/codegen:encrypt_opencl_kernel_gen'
ERROR: /home/parallels/mace/mace/codegen/BUILD.bazel:26:1: no such target '@local_opencl_kernel_encrypt//:gen/encrypt_opencl_kernel.h': target 'gen/encrypt_opencl_kernel.h' not declared in package '' defined by /home/parallels/.cache/bazel/_bazel_parallels/5ff1ff2df121917af4fe9fa25c7709ef/external/local_opencl_kernel_encrypt/BUILD.bazel and referenced by '//mace/codegen:encrypt_opencl_kernel_gen'
ERROR: Analysis of target '//mace/libmace:libmace_dynamic' failed; build aborted: Loading failed
INFO: Elapsed time: 6.132s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (33 packages loaded)

$ pip3 show jinja2
WARNING: pip is being invoked by an old script wrapper. This will fail in a future version of pip.
Please see https://github.com/pypa/pip/issues/5599 for advice on fixing the underlying issue.
To avoid this problem you can invoke Python with '-m pip' instead of running pip directly.
Name: Jinja2
Version: 2.11.2
Summary: A very fast and expressive template engine.
Home-page: https://palletsprojects.com/p/jinja/
Author: Armin Ronacher
Author-email: [email protected]
License: BSD-3-Clause
Location: /home/parallels/.local/lib/python3.5/site-packages
Requires: MarkupSafe
Required-by: 

See, there is jinja2==2.11.2 in my pip3, but not sure why jinja2 is not found when building mace lib /confused.

@LovelyBuggies
Copy link
Contributor Author

LovelyBuggies commented May 25, 2020

If I used the method at #620 (comment), i.e., using apt-get to install, the error jinja2: no filter named to json will occur because of the jinja2 version issue.

More clues: apt-get install with upgrade option can only get 2.8.1 python-jinja2.

sudo apt-get install -y python-jinja2
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  aptitude-common libcwidget3v5 libpython-all-dev libpython-dev
  libpython2.7-dev python-all python-all-dev python-dev python-wheel
  python2.7-dev
Use 'sudo apt autoremove' to remove them.
Suggested packages:
  python-jinja2-doc
The following NEW packages will be installed:
  python-jinja2
0 upgraded, 1 newly installed, 0 to remove and 22 not upgraded.
Need to get 0 B/106 kB of archives.
After this operation, 843 kB of additional disk space will be used.
Selecting previously unselected package python-jinja2.
(Reading database ... 176645 files and directories currently installed.)
Preparing to unpack .../python-jinja2_2.8-1ubuntu0.1_all.deb ...
Unpacking python-jinja2 (2.8-1ubuntu0.1) ...
Setting up python-jinja2 (2.8-1ubuntu0.1) ...

@lee-bin
Copy link
Member

lee-bin commented May 25, 2020

What's the output of python --version

@LovelyBuggies
Copy link
Contributor Author

LovelyBuggies commented May 25, 2020

$ python --version
Python 2.7.12
$ python3 --version
Python 3.5.2

P.S. I am not using python2.

@lee-bin
Copy link
Member

lee-bin commented May 25, 2020

How do you ensure bazel use python3?

@LovelyBuggies
Copy link
Contributor Author

How do you ensure bazel use python3?

I cannot ensure, actually. Let me try 3.6+ and remove python2 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants