Search code examples
pythonpgadminpgadmin-4

pgAdmin4 not working anymore after restarting PC


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!


Solution

  • 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