【问题标题】:Installed python3.9 not showing in linux安装的python3.9没有在linux中显示
【发布时间】:2022-07-05 23:35:42
【问题描述】:

我按照link 中的步骤安装了 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) ...

为什么要设置 postgresql-plpython3-9.5,我该如何防止它这样做?

【问题讨论】:

  • 它只选择了postgresql-plpython3-9.5,因为您的源中没有 python3.9 包可用。
  • ...现在,要开始尝试理解为什么会这样,我们需要阅读您的链接。请不要这样做——即使链接断开,问题也应该是独立的,足以回答问题。我们需要知道的一些事情才能回答这个问题:您正在运行哪个特定的发行版?您的sources.list 中有什么内容?上次您尝试从该sources.list 文件中的所有位置检索包数据库时,apt-get update 是否运行且没有错误?将所有这些的答案包含在问题本身中,而不是在链接后面。
  • @CharlesDuffy 我编辑了我的问题。

标签: python python-3.9


【解决方案1】:

问题:

deadsnakes ppa 不再适用于 Ubuntu Xenial。这就是您无法安装python3.9的原因。请参阅this 问题。您必须从源代码编译或将您的服务器升级到受支持的 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.1q.tar.gz | (cd /usr/src; tar xz)
cd /usr/src/openssl-1.1.1q && ./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 'export PATH="/root/.pyenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(pyenv init -)"' >> ~/.bashrc
echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.bashrc
source ~/.bashrc

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

【讨论】:

  • 添加说明如何在 Ubuntu Xenial 上构建当前的 python (>=3.8)
【解决方案2】:

您可能已经安装了它

尝试运行$ python3 --version 查看您正在运行的 python 版本。 如果未安装尝试运行$ sudo apt-get update 然后运行$ sudo apt-get install python3.9 安装python3.9

希望这会有所帮助

【讨论】:

  • 我试过了,我安装了 python 3.5,安装 3.9 时进入 postgresql
  • 奇怪,也许可以尝试卸载 python 并重新安装它
【解决方案3】:

您需要添加 deadsnakes 存储库。

sudo add-apt-repository ppa:deadsnakes/ppa

之后,您可以按照问题中的步骤进行操作。

如果您在添加 deadsnakes 存储库后仍然遇到相同的问题,则可能意味着您运行的是不受支持的 linux 版本。然后您可能需要从源代码安装 Python 3.9,您可以查看this answer 了解如何安装。

【讨论】:

    猜你喜欢
    • 2022-11-23
    • 1970-01-01
    • 2023-03-30
    • 2021-07-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-13
    • 2022-10-17
    相关资源
    最近更新 更多