安装的python3.9在linux中不显示

abh*_*bhi 5 python python-3.9

我按照此链接中的步骤安装了 python 3.9 。

  1. sudo apt update
  2. sudo apt install python3.9
  3. python3.9
  4. sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.[old-version] 1
  5. sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.9 2
  6. sudo update-alternatives --config python3

然而,它python3.9 not found在第三点上抛出了一个错误。另外,我注意到使用第二点安装时显示了 python3.9 Note, selecting 'postgresql-plpython3-9.5' for regex 'python3.9'

完整的消息是

Reading package lists... Done
Building dependency tree
Reading state information... Done
Note, selecting 'postgresql-plpython3-9.5' for regex 'python3.9'
The following packages were automatically installed and are no longer required:
  linux-aws-headers-4.4.0-1104 linux-aws-headers-4.4.0-1105 linux-aws-headers-4.4.0-1106 linux-aws-headers-4.4.0-1107 linux-aws-headers-4.4.0-1109 linux-aws-headers-4.4.0-1110 linux-aws-headers-4.4.0-1111
  linux-aws-headers-4.4.0-1112 linux-aws-headers-4.4.0-1113 linux-aws-headers-4.4.0-1114
Use 'sudo apt autoremove' to remove them.
The following NEW packages will be installed:
  postgresql-plpython3-9.5
0 upgraded, 1 newly installed, 0 to remove and 56 not upgraded.
Need to get 0 B/40.6 kB of archives.
After this operation, 166 kB of additional disk space will be used.
Selecting previously unselected package postgresql-plpython3-9.5.
(Reading database ... 362651 files and directories currently installed.)
Preparing to unpack .../postgresql-plpython3-9.5_9.5.25-0ubuntu0.16.04.1_amd64.deb ...
Unpacking postgresql-plpython3-9.5 (9.5.25-0ubuntu0.16.04.1) ...
Processing triggers for postgresql-common (173ubuntu0.3) ...
Building PostgreSQL dictionaries from installed myspell/hunspell packages...
Removing obsolete dictionary files:
Setting up postgresql-plpython3-9.5 (9.5.25-0ubuntu0.16.04.1) ...
Run Code Online (Sandbox Code Playgroud)

为什么要设置 postgresql-plpython3-9.5 以及如何阻止它这样做?

its*_*ire 12

问题:

deadsnakes ppa 不再适用于 Ubuntu Xenial。这就是你无法安装python3.9的原因。看看这个问题。您必须从源代码编译或将您的服务器升级到受支持的 Ubuntu 版本。

解决方案:自己搭建

如果您无法升级系统,您可以使用pyenv来安装任何给定的 python 版本,如下所述。为此,需要为 python 版本 >= 3.8 安装新版本的 openssl

# install dependencies
apt update
apt install -y build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libsqlite3-dev libreadline-dev libffi-dev curl libbz2-dev liblzma-dev git

# download and compile openssl
curl -L https://www.openssl.org/source/openssl-1.1.1s.tar.gz | (cd /usr/src; tar xz)
cd /usr/src/openssl-1.1.1s && ./config --prefix=/usr/local && make -j4 && make install

# download and configure pyenv
curl -L https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer | bash

echo >> ~/.bashrc # add new-line.
echo 'export PATH="/root/.pyenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(pyenv init -)"' >> ~/.bashrc
echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.bashrc
source ~/.bashrc

# build python 3.9.16 with pyenv
CONFIGURE_OPTS="--with-openssl=/usr/local --with-openssl-rpath=auto" pyenv install 3.9.16

# build python 3.10.9 with pyenv
CONFIGURE_OPTS="--with-openssl=/usr/local --with-openssl-rpath=auto" pyenv install 3.10.9
Run Code Online (Sandbox Code Playgroud)


小智 0

您可能已经安装了它

尝试运行$ python3 --version 看看你正在运行什么Python版本。如果未安装,请尝试运行$ sudo apt-get update,然后运行$ sudo apt-get install python3.9以安装 python3.9

希望这会有所帮助

  • 我尝试了这些,我安装了 python 3.5,安装 3.9 时它进入了 postgresql (4认同)