4

I'm trying to install pgadmin4 on Arch Linux. Here is what I did:

sudo pacman -S pgadmin4

Then I simply tried running pgadmin4 and got the following error:

"An error occurred initialising the pgAdmin 4 server:\n\nFailed to launch the application server, server thread exiting."

Then, I tried running pgAdmin4.py directly:

sudo python3 /usr/lib/pgadmin4/web/pgAdmin4.py

And I got an error with the following stacktrace:

Traceback (most recent call last):
  File "/usr/lib/pgadmin4/web/pgAdmin4.py", line 35, in <module>
    import config
  File "/usr/lib/pgadmin4/web/config.py", line 25, in <module>
    from pgadmin.utils import env, IS_WIN, fs_short_path
  File "/usr/lib/pgadmin4/web/pgadmin/__init__.py", line 28, in <module>
    from flask_security import Security, SQLAlchemyUserDatastore, current_user
  File "/usr/lib/python3.9/site-packages/flask_security/__init__.py", line 15, in <module>
    from .core import Security, RoleMixin, UserMixin, AnonymousUser, current_user
  File "/usr/lib/python3.9/site-packages/flask_security/core.py", line 48, in <module>
    from .mail_util import MailUtil
  File "/usr/lib/python3.9/site-packages/flask_security/mail_util.py", line 14, in <module>
    import email_validator
ModuleNotFoundError: No module named 'email_validator'

I then tried to install pip in an attempt to install the missing module myself:

sudo pacman -S python-pip

Then:

pip install email_validator

However, the error remains. Should I modify my PATH variable? What am I doing wrong?

EDIT

So, after some help from the comments, and some more searching, I modified the ~/.config/pgadmin/pgadmin4.conf file to have the following PythonPath=/usr/lib/python3.9/site-packages:/usr/lib/python3.9:/home/ddimitrov/.local/lib/python3.9/site-packages, which "resolved" this error but I was greeted with a brand new error:

Traceback (most recent call last):
  File "/usr/lib/pgadmin4/web/pgAdmin4.py", line 94, in <module>
    app = create_app()
  File "/usr/lib/pgadmin4/web/pgadmin/__init__.py", line 347, in create_app
    if not os.path.exists(SQLITE_PATH) or get_version() == -1:
  File "/usr/lib/pgadmin4/web/pgadmin/setup/db_version.py", line 19, in get_version
    return version.value
AttributeError: 'NoneType' object has no attribute 'value'

I tried since to reinstall pgadmin4 multiple times, same issue. Any help would be much appreciated.

Dimitar Dimitrov
  • 14,868
  • 8
  • 51
  • 79
  • could you ensure that `/usr/lib/python3.9/site-packages` actually contains `email_validator` after your installation. You might got into some confusion with different python versions – Raphael May 19 '21 at 20:21
  • the problem originates from flask_security: `from flask_security import Security, SQLAlchemyUserDatastore, current_user` You can try to run this import in your python console to narrow down the problem – Raphael May 19 '21 at 20:23
  • I don't see the package in `/usr/lib/python3.9/site-packages`, but I see it in `~/.local/lib/python3.9/site-packages`, is this not correct? I ran `pip list -v` and that's the only package with a different directory. – Dimitar Dimitrov May 19 '21 at 20:26
  • By the way none of those directories are in my `PATH` variable? Should I add them there? I mean the `site-packages` ones. – Dimitar Dimitrov May 19 '21 at 20:29
  • there is an extra env variable `PYTHONPATH`. Can you check that? https://www.tutorialspoint.com/What-is-PYTHONPATH-environment-variable-in-Python – Raphael May 19 '21 at 20:30
  • Hmm, It seems that this variable is not set. I didn't see anything about it on the Arch Wiki and the installation tutorials for python. Should I create it, and what should the value of it be? Did I miss something? – Dimitar Dimitrov May 19 '21 at 20:32
  • `~/.local/…` is not going to mean the same thing to sudo as it does to you. If pgadmin indeed runs runs on root (how about `postgres` user instead?) then you need to reason in terms of *their* PATH and HOME. And pythonpath – JL Peyret May 19 '21 at 20:33
  • JL got a point. For this and other reasons, the pgadmin docs recommend a virtual python env: https://www.pgadmin.org/download/pgadmin-4-python/ – Raphael May 19 '21 at 20:37
  • @JLPeyret So when I do, `sudo -iu postgres python3 /usr/lib/pgadmin4/web/pgAdmin4.py`, I get the exact same error. – Dimitar Dimitrov May 19 '21 at 20:37
  • @Raphael but I didn't install `pgadmin4` through `pip`, but rather through `pacman`, I assumed it would set things up, didn't see anything in the installation about that. Sorry, I'm a bit confused. – Dimitar Dimitrov May 19 '21 at 20:39
  • 2
    mh, I would assume that too but it seems to fail at some point. You could try to install the package system wide `sudo pip install email_validator` – Raphael May 19 '21 at 20:45
  • @Raphael, thanks that helped... I think? I mean I get another error now. `AttributeError: 'NoneType' object has no attribute 'value'`, not sure what's going on. Thank you for your help, btw! Much appreciated! – Dimitar Dimitrov May 19 '21 at 21:02
  • your welcome :) does this new error also occur in `flask_security` or is it another library? – Raphael May 19 '21 at 21:18
  • @Raphael Check my edit, I've included the new error and any progress that I've made. – Dimitar Dimitrov May 19 '21 at 21:26
  • that's a tricky one. pgadmin queries its internal sqlite database for its version but [Version.query.filter_by(name='ConfigDB')](https://github.com/postgres/pgadmin4/blob/master/web/pgadmin/setup/db_version.py) returns no rows. This case is not expected. Instead the query should either fail with an exception (which is handled) or return at least one row. Did you by any chance set this up with docker so that you could share the hole thing? – Raphael May 20 '21 at 10:29
  • @Raphael At this point, I'll just assume that this version of `pgadmin4` on the arch repo is broken, I've spent way too much time on this. I hope someone would find this useful, if I manage to fix it, I'll update this question. – Dimitar Dimitrov May 20 '21 at 11:28
  • This belongs on Server Fault. – mmirate Jun 09 '21 at 23:30

2 Answers2

5

This doesn't fix the specific issue, but it's too long to comment, but it will get you working:

You can run pgadmin4 via docker, and link it directly to the host network.

docker run -e 'PGADMIN_LISTEN_PORT=8080' \
           -e 'PGADMIN_DEFAULT_EMAIL=user@domain.com' \
           -e "PGADMIN_DEFAULT_PASSWORD=secret" \
           --network="host" \
           dpage/pgadmin4:latest

Then visit http://localhost:8080, login with user@domain.com:secret. You can now add servers like you might normally, just specify "localhost" as the host and your normal username (I think that's how arch configures access by default).

See also: https://www.pgadmin.org/docs/pgadmin4/latest/container_deployment.html#examples

You can also look into configuring pip install pgadmin4 and creating a config.py (perhaps in /etc/pgadmin4?) to set SERVER_MODE=False.

Really wish you could just go pgadmin4 --desktop-mode...

2

Per Bastien Durel (bastiendurel) @ https://bugs.archlinux.org/task/70855 it looks like you'd need to downgrade python-flask and python-flask-security-too. They cannot be past 2.0 and 4.0 respectively.

I was having the same issue and downgraded each package and it's working now, but this may break any other packages that rely on the latest versions of python-flask and python-flask-security-too.

If you downgrade, you'd also need to update your /etc/pacman.conf to ignore both packages when updating.