Python 尝试运行 pgAdmin4 时出错

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/41260004/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 00:41:54  来源:igfitidea点击:

Error trying to run pgAdmin4

pythonpostgresqlflaskpostgresql-9.4pgadmin-4

提问by Elad Tabak

I've installed postgresql 9.6 (using suggested linux installer) which comes with pgAdmin4, but getting a few errors.

我已经安装了 pgAdmin4 附带的 postgresql 9.6(使用建议的 linux 安装程序),但是遇到了一些错误。

First, I had to change the folder name from "pgAdmin 4" (note the extra space) to "pgAdmin4" to avoid "file not found error".

首先,我必须将文件夹名称从“pgAdmin 4”(注意多余的空格)更改为“pgAdmin4”以避免“找不到文件错误”。

Then I run sudo python pgAdmin4.pyand got the following error:

然后我运行sudo python pgAdmin4.py并收到以下错误:

Traceback (most recent call last):
   File "../../pgAdmin4.py", line 24, in <module>
      from pgadmin import create_app
   File "/opt/PostgreSQL/9.6/pgAdmin4/web/pgadmin/__init__.py", line 17, in <module>
      from flask import Flask, abort, request, current_app
ImportError: No module named flask

I tried following this related question: Flask ImportError: No Module Named Flask-- managed to installed flask on virtualenv.

我尝试关注这个相关问题: Flask ImportError: No Module Named Flask-- 设法在 virtualenv 上安装了Flask

But then I started getting other flask related modules that are missing: flask_babel, flask_login, flask_security. I installed all of them using pip, but then I got an error on missing module htmlmin.minifywhich I can't seems to able to install.

但后来我开始得到其他缺少的与烧瓶相关的模块:flask_babel、flask_login、flask_security。我使用 pip 安装了所有这些,但随后我在缺少模块时出现错误htmlmin.minify,我似乎无法安装。

Traceback (most recent call last):
   File "../pgAdmin4.py", line 24, in <module>
      from pgadmin import create_app
   File "/opt/PostgreSQL/9.6/pgAdmin4/web/pgadmin/__init__.py", line 23, in <module>
      from htmlmin.minify import html_minify
ImportError: No module named htmlmin.minify

I also exported PYTHONPATH to the one on flask, as described here, still getting the same error.

我还将 PYTHONPATH 导出到烧瓶上,如here所述,仍然出现相同的错误。

So, anyone have an idea how to make pgAdmin4 work on ubuntu environemt?

那么,有人知道如何使 pgAdmin4 在 ubuntu 环境中工作吗?

采纳答案by Nurjan

According to https://www.pgadmin.org/download/pip4.php.

根据https://www.pgadmin.org/download/pip4.php

Install the virtualenv by running:

通过运行安装 virtualenv:

sudo apt-get install virtualenv

You also need to install these 2 libraries:

您还需要安装这两个库:

sudo apt-get install libpq-dev python-dev 

Then:

然后:

cd ~/bin/
virtualenv pgadmin4

I prefer to use the ~/bin/directory for installing applications.

我更喜欢使用该~/bin/目录来安装应用程序。

Then you download the pgadmin4-1.1-py2-none-any.whlor pgadmin4-1.1-py3-none-any.whldepending on the python version you use. For this example we use python 2.7.

然后您下载pgadmin4-1.1-py2-none-any.whlpgadmin4-1.1-py3-none-any.whl取决于您使用的python 版本。对于这个例子,我们使用 python 2.7。

You download pgadmin4:

你下载pgadmin4:

wget https://ftp.postgresql.org/pub/pgadmin3/pgadmin4/v1.1/pip/pgadmin4-1.1-py2-none-any.whl

Activate the virtualenv:

激活虚拟环境:

. ~/bin/pgadmin4/bin/activate

After that you will see (pgadmin4)in the terminal.

之后,您将(pgadmin4)在终端中看到。

Inside of pgadmin4 run:

在 pgadmin4 内部运行:

pip install ./pgadmin4-1.1-py2-none-any.whl

After that you must be able to run pgadmin4:

之后,您必须能够运行 pgadmin4:

python ~/bin/pgadmin4/lib/python2.7/site-packages/pgadmin4/pgAdmin4.py 

In order to make the running process a bit easier you can create an alias. For instance, in Ubuntu 16.04 LTS, add alias in the ~/.bash_aliasesfile:

为了使运行过程更容易一些,您可以创建一个别名。例如,在 Ubuntu 16.04 LTS 中,在~/.bash_aliases文件中添加别名:

alias pgadmin4='. /home/your_username/bin/pgadmin4/bin/activate; /home/your_username/bin/pgadmin4/lib/python2.7/site-packages/pgadmin4/pgAdmin4.py'

Where your_usernameshould be replaced by your real user name.

whereyour_username应该换成你的真实用户名。

Then give execute permission, for example, 764to the pgAdmin4.pyfile in:

然后给执行权限,例如,764pgAdmin4.py文件在:

/home/your_username/bin/pgadmin4/lib/python2.7/site-packages/pgadmin4/pgAdmin4.py

Also you need to edit the pgAdmin4.pyfile and add this line in the very top:

您还需要编辑pgAdmin4.py文件并在最顶部添加此行:

#!/home/your_username/bin/pgadmin4/bin/python

where your_usernameis your real user name.

your_username你的真实用户名在哪里。

This will make sure that you run the application using the required version of python and include all necessary dependencies in order to run pgadmin4.

这将确保您使用所需版本的 python 运行应用程序并包含所有必要的依赖项以运行pgadmin4.

Then run . ~/.bashrcin order to apply the changes.

然后运行. ~/.bashrc以应用更改。

So now you can open your terminal and simply type pgadmin4in order to run it.

所以现在你可以打开你的终端并简单地输入pgadmin4以运行它。

Open your browser and point to:

打开浏览器并指向:

http://127.0.0.1:5050

One more thing to note - if you need to run pgadmin4in desktop mode you need to change SERVER_MODEto False in:

还要注意的一件事 - 如果您需要pgadmin4在桌面模式下运行,则需要在以下位置更改SERVER_MODE为 False:

/home/your_username/bin/pgadmin4/lib/python2.7/site-packages/pgadmin4/config.py

Otherwise when you visit localhost:5050 it will ask you for your login and password.

否则,当您访问 localhost:5050 时,它会询问您的登录名和密码。

Hope this helps.

希望这可以帮助。

回答by nyxz

After following the documentation on adding PgAdmin 4 to my Fedora 28 failed in every possible way I went with the Dockeroption:

在遵循有关将 PgAdmin 4 添加到我的 Fedora 28 的文档之后,我以各种可能的方式使用了Docker选项:

mkdir ~/.pgadmin4  # to store config and stuff
docker run -d --rm --network host -v ~/.pgadmin4:/pgadmin thajeztah/pgadmin4

Then go to http://localhost:5050and you are done with it.

然后访问http://localhost:5050就完成了。

See https://github.com/thaJeztah/pgadmin4-dockerfor more info.

有关更多信息,请参阅https://github.com/thaJeztah/pgadmin4-docker

回答by andrei040191

Please, try these commands:

请尝试以下命令:

sudo apt-get install pgadmin4

sudo python3.5 /usr/share/pgadmin4/web/pgAdmin4.py

回答by Дмитрий Винник

If you use Windows, try to delete the folder: %APPDATA%\pgAdmin

如果您使用 Windows,请尝试删除该文件夹: %APPDATA%\pgAdmin