Ubuntu 21.10 上无法联系 pgAdmin 4 服务器错误

Ubuntu 21.10 上无法联系 pgAdmin 4 服务器错误

我安装了 pgAdmin 但当我打开它时出现此错误:

Failed to launch pgAdmin4. Error:
Error: spawn /usr/pgadmin4/venv/bin/python3 ENOENT

当我点击此命令时:

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

我明白

python3: can't open file '/usr/share/pgadmin4/web/pgAdmin4.py': [Errno 2] No such file or directory

然后我创建丢失的文件路径为,

sudo mkdir -p /var/cache/pgadmin/sessions

然后再次运行此命令

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

但我得到了同样的错误

答案1

在 Ubuntu 21.10(impish)上遇到了这个问题,因为我搞乱了安装路径,以为 pgadmin4 没有完全安装,但其实它已经安装好了。

错误是因为它假设安装了 python3.8(21.10 附带 python3.9),但实际上没有,所以所有符号链接和虚拟环境都失败了。但发生这种情况是因为您安装的 pgadmin4 版本与您的 Ubuntu 版本不匹配。

garrett@garrett-external:/etc/apt/sources.list.d$ ls
deadsnakes-ubuntu-ppa-impish.list  pgadmin4.list.save  pgdg.list.save
pgadmin4.list                      pgdg.list


##Looking at pgadmin4.list.save , I see I had at least tried to use
# hirsute 's repo:

garrett@garrett-external:/etc/apt/sources.list.d$ cat pgadmin4.list.save
    deb https://ftp.postgresql.org/pub/pgadmin/pgadmin4/apt/hirsute pgadmin4 main

##I'm thinking this is overriding the correct impish repos, so I'll
# try deleting that file, purging the installation and re-installing:

garrett@garrett-external:/etc/apt/sources.list.d$ ls
    deadsnakes-ubuntu-ppa-impish.list  pgadmin4.list  pgadmin4.list.save  pgdg.list  pgdg.list.save
garrett@garrett-external:/etc/apt/sources.list.d$ sudo rm pgadmin4.list.save

##double check that the pgadmin4 sources are correct...
garrett@garrett-external:/etc/apt/sources.list.d$ ls
    deadsnakes-ubuntu-ppa-impish.list  pgadmin4.list  pgdg.list  pgdg.list.save
garrett@garrett-external:/etc/apt/sources.list.d$ cat pgadmin4.list
  deb https://ftp.postgresql.org/pub/pgadmin/pgadmin4/apt/focal pgadmin4 main

##^ok definitely the problem...should fix that....

garrett@garrett-external:/etc/apt/sources.list.d$ sudo sed -i 's/focal/impish/g' /etc/apt/sources.list.d/pgadmin4.list
garrett@garrett-external:/etc/apt/sources.list.d$ cat ./pgadmin4.list
  deb https://ftp.postgresql.org/pub/pgadmin/pgadmin4/apt/impish pgadmin4 main

##uninstall pgadmin4
garrett@garrett-external:/etc/apt/sources.list.d$ sudo apt purge pgadmin4
garrett@garrett-external:/etc/apt/sources.list.d$ sudo apt autoremove

##reinstall pgadmin4
garrett@garrett-external:/etc/apt/sources.list.d$ sudo apt update && sudo apt install pgadmin4

And now it works fine

编辑:不要掉进下面的兔子洞

解决方法:使用 deadsnakes PPA 和一些临时的 apt 缓存更新技巧手动安装 python3.8

  #first add deadsnakes ppa...
  $  sudo add-apt-repository ppa:deadsnakes

  # Following the gist of https://brennan.io/2021/06/21/deadsnakes-hirsute/ ,
  # update the deadsnakes ppa's app repos to look at the past 2 LTS versions
  $ sudo vim /etc/apt/sources.list.d/deadsnakes-ubuntu-ppa-impish.list
     ---> change 
      'deb http://ppa.launchpad.net/deadsnakes/ppa/ubuntu/ impish main'  to 
      'deb http://ppa.launchpad.net/deadsnakes/ppa/ubuntu/ bionic main' , also add 
      'deb http://ppa.launchpad.net/deadsnakes/ppa/ubuntu/ focal main'


   #Add the following rules which blacklist all packages from 
   # the repos, and then selectively enable Python versions from the correct
   # locations. This can be put in any filename within the directory
   #      /etc/apt/preferences.d/  (I named mine deadsnakes_pref)

Explanation: Prevent installing from deadsnakes repo.
Package: *
Pin: release o=LP-PPA-deadsnakes
Pin-Priority: 1

Explanation: Allow installing python 3.{6,7} from deadsnakes/focal
Package: *python3.6* *python3.7*
Pin: release o=LP-PPA-deadsnakes,n=focal
Pin-Priority: 500

Explanation: Allow installing python 3.8 from deadsnakes/bionic
Package: *python3.8*
Pin: release o=LP-PPA-deadsnakes,n=bionic
Pin-Priority: 500

 ##temporarily change all your sources to bionic, so the python3.8 
 #dependencies will be met
   $  sudo sed -i 's/impish/bionic/g' /etc/apt/sources.list

  ## try to update the apt cache and install python3.8 . You'll get yelled
  #  at for not having the proper key ring:
  ****************
W: GPG error: http://us.archive.ubuntu.com/ubuntu bionic InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 3B4FE6ACC0B21F32
E: The repository 'http://us.archive.ubuntu.com/ubuntu bionic InRelease' is not signed.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.
****************

## so following 
## https://askubuntu.com/questions/13065/how-do-i-fix-the-gpg-error-no-pubkey  
## , I add the key
$  sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 3B4FE6ACC0B21F32

# now this should work
$ sudo apt update && sudo apt install python3.8

#after we're done, don't forget to change back your sources
$ sudo sed -i 's/bionic/impish/g' /etc/apt/sources.list
$ sudo apt update

#And now pgadmin4 should work. If you want to run it from the terminal, 
# add this line to your ~/.bash_aliases  file:
   alias pgadmin4='/usr/pgadmin4/bin/pgadmin4'  

答案2

只需再次安装 Pgadmin,它将修复操作系统升级后的断开的链接;)

如果你需要说明,可以按照此处的说明进行操作:https://computingforgeeks.com/how-to-install-pgadmin-4-on-ubuntu/

答案3

发生此问题的原因可能是Python 版本 3.8在 pgAdmin 中使用,但您安装了不同的 Python 版本。对我来说,修复方法是安装旧版 Python 3.8。在应用修复之前,请检查说明,以确保您遇到相同的问题。

sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt update
sudo apt install python3.8

之后 pgAdmin 运行良好。我之前安装的较新版本的 Python 也运行良好。

这里是解释

在阅读错误输出的第一行时,我发现安装文件夹是:

/usr/pgadmin4/venv/bin

我将当前目录更改为以下文件夹:

$ cd /usr/pgadmin4/venv/bin

并检查内容:

$ ls -al
lrwxrwxrwx 1 root root     7 Sep 20 09:47 python -> python3
lrwxrwxrwx 1 root root    18 Sep 20 09:47 python3 -> /usr/bin/python3.8

如您所见,链接指向 Python 3.8。但是它没有安装。我安装的 Python 版本是

$ python3 -V
Python 3.10.12

所以我安装了 python 3.8 来修复链接:

sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt update
sudo apt install python3.8

现在 pgAdmin 4 应用程序可以启动了。

相关内容