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

ImportError: cannot import name 'Markup' from 'jinja2' #27

Closed
samcro1967 opened this issue Apr 23, 2022 · 14 comments
Closed

ImportError: cannot import name 'Markup' from 'jinja2' #27

samcro1967 opened this issue Apr 23, 2022 · 14 comments

Comments

@samcro1967
Copy link

Container fails to start. Removed the database, container, and image to start from fresh and get the same results. Any ideas?

Traceback (most recent call last):                                                                                                                                                                                 File "//config/metatube.py", line 5, in <module>
    from metatube import create_app, socketio
  File "/config/metatube/__init__.py", line 4, in <module>
    from flask_jsglue import JSGlue
  File "/usr/local/lib/python3.9/site-packages/flask_jsglue.py", line 2, in <module>                                                                                                                                 from jinja2 import Markup                                                                                                                                                                                    ImportError: cannot import name 'Markup' from 'jinja2' (/usr/local/lib/python3.9/site-packages/jinja2/__init__.py)                                                                                               Traceback (most recent call last):                                                                                                                                                                                 File "//config/metatube.py", line 5, in <module>
    from metatube import create_app, socketio
  File "/config/metatube/__init__.py", line 4, in <module>
    from flask_jsglue import JSGlue
  File "/usr/local/lib/python3.9/site-packages/flask_jsglue.py", line 2, in <module>                                                                                                                                 from jinja2 import Markup                                                                                                                                                                                    ImportError: cannot import name 'Markup' from 'jinja2' (/usr/local/lib/python3.9/site-packages/jinja2/__init__.py)                                                                                               Traceback (most recent call last):                                                                                                                                                                                 File "//config/metatube.py", line 5, in <module>
    from metatube import create_app, socketio
  File "/config/metatube/__init__.py", line 4, in <module>
    from flask_jsglue import JSGlue                                                                                                                                                                                File "/usr/local/lib/python3.9/site-packages/flask_jsglue.py", line 2, in <module>                                                                                                                                 from jinja2 import Markup                                                                                                                                                                                    ImportError: cannot import name 'Markup' from 'jinja2' (/usr/local/lib/python3.9/site-packages/jinja2/__init__.py)
Traceback (most recent call last):                                                                                                                                                                                 File "//config/metatube.py", line 5, in <module>
    from metatube import create_app, socketio                                                                                                                                                                      File "/config/metatube/__init__.py", line 4, in <module>
    from flask_jsglue import JSGlue
  File "/usr/local/lib/python3.9/site-packages/flask_jsglue.py", line 2, in <module>                                                                                                                                 from jinja2 import Markup
ImportError: cannot import name 'Markup' from 'jinja2' (/usr/local/lib/python3.9/site-packages/jinja2/__init__.py)                                                                                               Traceback (most recent call last):                                                                                                                                                                                 File "//config/metatube.py", line 5, in <module>
    from metatube import create_app, socketio
  File "/config/metatube/__init__.py", line 4, in <module>                                                                                                                                                           from flask_jsglue import JSGlue
  File "/usr/local/lib/python3.9/site-packages/flask_jsglue.py", line 2, in <module>                                                                                                                                 from jinja2 import Markup                                                                                                                                                                                    ImportError: cannot import name 'Markup' from 'jinja2' (/usr/local/lib/python3.9/site-packages/jinja2/__init__.py)                                                                                               Traceback (most recent call last):
  File "//config/metatube.py", line 5, in <module>
    from metatube import create_app, socketio
  File "/config/metatube/__init__.py", line 4, in <module>                                                                                                                                                           from flask_jsglue import JSGlue
  File "/usr/local/lib/python3.9/site-packages/flask_jsglue.py", line 2, in <module>                                                                                                                                 from jinja2 import Markup                                                                                                                                                                                    ImportError: cannot import name 'Markup' from 'jinja2' (/usr/local/lib/python3.9/site-packages/jinja2/__init__.py)
@Gabisonfire
Copy link

Gabisonfire commented Apr 23, 2022

Same issue here. Woulb be nice to push tags to docker instead of overwriting latest so we can rollback in case of issue like this one :)

The issue is generated by flask_jsglue, issue is reported here: stewartpark/Flask-JSGlue#33 and fix submitted here https://github.com/stewartpark/Flask-JSGlue/pull/32/files
Seems this repo has been stale for 4 years, wonder if this will ever get pulled. Let me know if you need help with this @JVT038 , I can fork, merge and push to pypi

@alii76tt
Copy link

I don't know for sure the solution. When I searched on Stackoverflow, I came across this and tried it and it worked.
Stackoverflow: https://stackoverflow.com/a/71645733

Before

from jinja2 import Markup
...
return Markup('<script src="%s" type="text/javascript"></script>') % (js_path,)

After

from jinja2.utils import markupsafe
...
return markupsafe('<script src="%s" type="text/javascript"></script>') % (js_path,)

@Gabisonfire
Copy link

Yes @alii76tt that seems to be the solution, but it needs to be fixed in the library. See my post above.

@alii76tt
Copy link

Yes, definitely @Gabisonfire .

@JVT038
Copy link
Owner

JVT038 commented Apr 25, 2022

Well, I guess I'll just make a fork or something, and fix it.
Or if @Gabisonfire would like to do it, I would appreciate it!

@Gabisonfire
Copy link

@JVT038 Uploaded the fix: pip install Flask-JSGlue2==0.3.2
I ended up simply forking https://github.com/italomaia/Flask-JSGlue who had already pushed the fix. Thanks @italomaia

@JVT038
Copy link
Owner

JVT038 commented Apr 26, 2022

It should be fixed in 43eb3b5

@JVT038 JVT038 closed this as completed Apr 26, 2022
@samcro1967
Copy link
Author

@JVT038 I just removed my container and image and ran docker-compse up and am seeing the similiar issues with a new image pull.

Traceback (most recent call last):
  File "//config/metatube.py", line 5, in <module>
    from metatube import create_app, socketio
  File "/config/metatube/__init__.py", line 4, in <module>
    from flask_jsglue import JSGlue
  File "/usr/local/lib/python3.9/site-packages/flask_jsglue.py", line 4, in <module>
    from jinja2 import Markup
ImportError: cannot import name 'Markup' from 'jinja2' (/usr/local/lib/python3.9/site-packages/jinja2/__init__.py)

@JVT038
Copy link
Owner

JVT038 commented Apr 26, 2022

Yeah, I noticed that the fork from italomaia hadn't updated the code yet, so I'll have to do that manually.

@JVT038 JVT038 reopened this Apr 26, 2022
@Gabisonfire
Copy link

Gabisonfire commented Apr 26, 2022

I just noticed, I'm repushing it @JVT038, just bump to 0.3.3
It's my fault, I forked master but the acutal change by italomaia was on a different branch.

JVT038 added a commit that referenced this issue Apr 27, 2022
@JVT038 JVT038 closed this as completed Apr 28, 2022
@Gabisonfire
Copy link

Now it throws:

INFO  [alembic.runtime.migration] Context impl SQLiteImpl.
INFO  [alembic.runtime.migration] Will assume non-transactional DDL.
ERROR [flask_migrate] Error: Can't locate revision identified by 'c90bc7c126fd'

@JVT038
Copy link
Owner

JVT038 commented Apr 28, 2022

Make a backup of your sqlite database before doing this (in case it doesn't work)
Anyway:
Stop the metatube container
Open your database file somehow (Either via the terminal, or via a GUI program, such as Db Browser)
Then delete the table called 'alembic_version'
Now restart your container, and it should work.

@samcro1967
Copy link
Author

It worked for me this morning after updating the image. Knock on wood no issues thus far.

@mariadunn
Copy link

mariadunn commented May 6, 2022

ETA: I realised I could just copy the js_bridge.js file from the Flask-JSGlue repo into my app/templates/jsglue folder. Seems to be working now!


@JVT038 Uploaded the fix: pip install Flask-JSGlue2==0.3.2 I ended up simply forking https://github.com/italomaia/Flask-JSGlue who had already pushed the fix. Thanks @italomaia

I installed this update which fixed the initial Markup issue (thank you!) but now I'm getting this error:

raise TemplateNotFound(template)
jinja2.exceptions.TemplateNotFound: jsglue/js_bridge.js

I can see js_bridge is referenced in flask_jsglue.py so I'm assuming that's what is triggering the error (in case you can't tell, I'm rather a programming amateur!). I'd appreciate any advice on how I can fix this.

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

5 participants