簡體   English   中英

安裝的python3.9沒有在linux中顯示

[英]Installed python3.9 not showing in linux

我按照此鏈接中的步驟安裝了 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

但是,它在第​​ 3 點拋出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,我該如何防止它這樣做?

問題:

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.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.9.13 with pyenv
CONFIGURE_OPTS="--with-openssl=/usr/local --with-openssl-rpath=auto" pyenv install 3.9.13

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

您可能已經安裝了它

嘗試運行$ python3 --version以查看您正在運行的 python 版本。 如果未安裝嘗試運行$ sudo apt-get update然后運行$ sudo apt-get install python3.9安裝 python3.9

希望這會有所幫助

您將需要添加deadsnakes 存儲庫。

sudo add-apt-repository ppa:deadsnakes/ppa

之后,您可以按照問題中的步驟進行操作。

如果您在添加 deadsnakes 存儲庫后仍然遇到相同的問題,則可能意味着您運行的是不受支持的 linux 版本。 然后,您可能必須從源代碼安裝 Python 3.9,您可以查看此答案以了解如何執行此操作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM