0

I have a strange problem. I followed this tutorial to install pgAdmin4 on my Ubuntu 16.04 machine. It works fine until i restart my PC.

When I try to run python lib/python2.7/site-packages/pgadmin4/pgAdmin4.py from my ~/pgadmin4 directory, it prints this error:

    Traceback (most recent call last)
  File "lib/python2.7/site-packages/pgadmin4/pgAdmin4.py", line 34, in <module>
    import config
  File "/home/myUsername/pgadmin4/lib/python2.7/site-packages/pgadmin4/config.py", line 30, in <module>
    from pgadmin.utils import env, IS_PY2, IS_WIN, fs_short_path
  File "/home/myUsername/pgadmin4/lib/python2.7/site-packages/pgadmin4/pgadmin/__init__.py", line 17, in <module>
    from flask import Flask, abort, request, current_app, session, url_for
  File "/usr/local/lib/python2.7/dist-packages/flask/__init__.py", line 19, in <module>
    from jinja2 import Markup, escape
  File "/usr/local/lib/python2.7/dist-packages/jinja2/__init__.py", line 33, in <module>
    from jinja2.environment import Environment, Template
  File "/usr/local/lib/python2.7/dist-packages/jinja2/environment.py", line 15, in <module>
    from jinja2 import nodes
  File "/usr/local/lib/python2.7/dist-packages/jinja2/nodes.py", line 19, in <module>
    from jinja2.utils import Markup
  File "/usr/local/lib/python2.7/dist-packages/jinja2/utils.py", line 647, in <module>
    from markupsafe import Markup, escape, soft_unicode
ImportError: No module named markupsafe

I've already installed several modules (before markupsafe, many others were missing) using pip. But there is always a new one missing every time I try to rerun it.

Does anyone know how to solve that?

Looking forward to reading some answers and thanks in advance!

Jakob Herk
  • 157
  • 11

1 Answers1

1

I have had a look at the tutorial you linked and it seems that it installed the needed libraries in a Python virtualenv. What happened, I guess, is that you forgot to activate the virtualenv (a isolated environment) after the reboot.

Specifically, as per the tutorial:

$ cd pgAdmin4
$ source bin/activate

That should fix all the links and executables for the packages that you installed in the virtualenv.

As you asked for other ways to do this (avoid having to type it every time), you could just run your script using the virtualenv interpreter. So, what you could do, is to directly use that specific one instead of the one in your global $PATH (when you run python in the terminal, that is the one you use). To do so, in this specific case, it is enough for you to cd into the pgAdmin4 virtualenv directory and run:
bin/python lib/python2.7/site-packages/pgadmin4/pgAdmin4.py

  • 1
    Thanks, that works! But I have to type it every time i restart my PC. Do you know how I can make it permanent? – Jakob Herk Oct 21 '18 at 07:31
  • Hi Jakob, I have just updated my answer to be more complete. Please, let me know if this suits better your use-case. – Marco Pernigotti Oct 21 '18 at 08:20
  • Hi Marco, I don't get your answer. Could you explain it? – Jakob Herk Oct 21 '18 at 15:17
  • Hi, I have tried to improve the explanation a bit. Basically, as you asked for it, I gave you an option to avoid having to repeat the `source bin/activate` at each reboot: using the interpreter in the `bin` directory of the virtualenv. What _activate_ script does it's more detailed here: https://virtualenv.pypa.io/en/stable/userguide/#activate-script Long story short, it will rewrite your `$PATH` to use the interpreter located inside the virtualenv. – Marco Pernigotti Oct 21 '18 at 17:25
  • sorry but when executing the command above it doesn't work after reboot – Jakob Herk Oct 21 '18 at 20:18
  • I am truly sorry it did not work, it sure did for me in the past. If I may, I'd like to point you to [systemd unit-files](https://www.freedesktop.org/software/systemd/man/systemd.unit.html), so you could create a service, which might be more reliable and flexible than an alias. – Marco Pernigotti Oct 21 '18 at 22:15
  • I've already figured out a different solution. Thanks for your help, i appreciate it. Liebe Grüße aus Österreich :) – Jakob Herk Oct 22 '18 at 07:06