【问题标题】:How to install Python 3.6 on Ubuntu 19.04?如何在 Ubuntu 19.04 上安装 Python 3.6?
【发布时间】:2019-04-20 12:44:46
【问题描述】:

我最近安装了Ubuntu 19.04,默认情况下有Python 3.7。我需要处理多个使用Python 3.6 的项目。

有没有办法在Disco Dingo上安装它?

我尝试了在 16.04 上工作的方法

milano@milano-desktop:~$ sudo add-apt-repository ppa:jonathonf/python-3.6
...
milano@milano-desktop:~$ sudo apt-get install python3.6
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Note, selecting 'python3.6-2to3' for regex 'python3.6'
Note, selecting 'libpython3.6-stdlib' for regex 'python3.6'
The following packages were automatically installed and are no longer required:
  fonts-liberation2 fonts-opensymbol gir1.2-geocodeglib-1.0
  gir1.2-gst-plugins-base-1.0 gir1.2-gstreamer-1.0 gir1.2-gudev-1.0
  gir1.2-udisks-2.0 grilo-plugins-0.3-base gstreamer1.0-gtk3 guile-2.2-libs
  libboost-date-time1.67.0 libboost-filesystem1.67.0 libboost-iostreams1.67.0
  libboost-locale1.67.0 libcdr-0.1-1 libclucene-contribs1v5 libclucene-core1v5
  libcmis-0.5-5v5 libcolamd2 libcurl4 libdazzle-1.0-0 libe-book-0.1-1 libeot0
  libepubgen-0.1-1 libetonyek-0.1-1 libevent-2.1-6 libfreerdp-client2-2
  libfreerdp2-2 libgc1c2 libgee-0.8-2 libgom-1.0-0 libgpgmepp6 libgpod-common
  libgpod4 liblangtag-common liblangtag1 liblirc-client0 liblua5.3-0
  libmediaart-2.0-0 libminiupnpc17 libmspub-0.1-1 libodfgen-0.1-1
  liborcus-0.14-0 libqqwing2v5 libraw19 librevenge-0.0-0 libsgutils2-2
  libsuitesparseconfig5 libvncclient1 libwinpr2-2 libxmlsec1 libxmlsec1-nss
  lp-solve media-player-info python3-mako python3-markupsafe syslinux
  syslinux-common syslinux-legacy usb-creator-common
Use 'sudo apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
milano@milano-desktop:~$ python3.6

Command 'python3.6' not found, did you mean:

  command 'python3.8' from deb python3.8-minimal (3.8.0~a3-2)
  command 'python3.7' from deb python3.7-minimal (3.7.3-2)

Try: sudo apt install <deb name>

python3 + 制表符

milano@milano-desktop:~$ python3
python3     python3.7   python3.7m  python3m 

死蛇

milano@milano-desktop:~$ sudo add-apt-repository ppa:deadsnakes/ppa
 This PPA contains more recent Python versions packaged for Ubuntu.

Disclaimer: there's no guarantee of timely updates in case of security problems or other issues. If you want to use them in a security-or-otherwise-critical environment (say, on a production server), you do so at your own risk.

Update Note
===========
Please use this repository instead of ppa:fkrull/deadsnakes.

Reporting Issues
================
Issues can be reported in the master issue tracker at:
https://github.com/deadsnakes/issues/issues

Supported Ubuntu and Python Versions
====================================
Python 3.6 - Ubuntu 14.04, Ubuntu 16.04

For Ubuntu up to 18.04, there's also packages for old Python versions from 2.3 to 3.4.

The packages may also work on other versions of Ubuntu or Debian, but that is not tested or supported.

Third-Party Python Modules
==========================
Python modules in the official Ubuntu repositories are packaged to work with the Python interpreters from the official repositories. Accordingly, they generally won't work with the Python interpreters from this PPA. As an exception, pure-Python modules for Python 3 will work, but any compiled extension modules won't.

To install 3rd-party Python modules, you should use the common Python packaging tools.  For an introduction into the Python packaging ecosystem and its tools, refer to the Python Packaging User Guide:
https://packaging.python.org/installing/

Sources
=======
The package sources are available at:
https://github.com/deadsnakes/
 More info: https://launchpad.net/~deadsnakes/+archive/ubuntu/ppa
Press [ENTER] to continue or Ctrl-c to cancel adding it.

Hit:1 http://cz.archive.ubuntu.com/ubuntu disco InRelease
Ign:2 http://ppa.launchpad.net/deadsnakes/ppa/ubuntu disco InRelease           
Get:3 http://cz.archive.ubuntu.com/ubuntu disco-updates InRelease [88,4 kB]    
Hit:4 http://security.ubuntu.com/ubuntu disco-security InRelease               
Hit:5 http://cz.archive.ubuntu.com/ubuntu disco-backports InRelease            
Ign:6 http://ppa.launchpad.net/jonathonf/python-3.6/ubuntu disco InRelease
Err:7 http://ppa.launchpad.net/deadsnakes/ppa/ubuntu disco Release
  404  Not Found [IP: 91.189.95.83 80]
Err:8 http://ppa.launchpad.net/jonathonf/python-3.6/ubuntu disco Release
  404  Not Found [IP: 91.189.95.83 80]
Reading package lists... Done                      
E: The repository 'http://ppa.launchpad.net/deadsnakes/ppa/ubuntu disco Release' does not have a Release file.
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.
E: The repository 'http://ppa.launchpad.net/jonathonf/python-3.6/ubuntu disco Release' does not have a Release file.
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.

【问题讨论】:

  • python3 并按制表符查看所有可能的版本。您也可以查看python36python3 -V。至于我,你的安装太短了,它没有安装它。在基于 Ubuntu 18.04 的 Linux Mint 19.1 上,我使用 deadsnake 存储库——可能是这个链接 launchpad.net/~deadsnakes/+archive/ubuntu/ppa。您也可以从 python.org 下载源代码并进行编译。
  • @furas Deadsnakes 版本也是如此。我已将选项卡 complete 添加到问题和 deadsnakes 输出的底部。
  • 你的python3.6项目有什么不能在python3.7上运行的吗?
  • @vaku 是的,因为 python3.7 在re 模块中发生了一些变化。例如,有点旧的 celery 无法使用,所以我不得不升级版本。
  • 所以下载源代码并编译它 - 描述应该在源代码的自述文件中:python.org/downloads/release/python-367

标签: python ubuntu ubuntu-19.04


【解决方案1】:

是的,正如@furas 所说,您可以下载python 3.6.83.6.7 的源代码(如果您需要其他格式,这些是.xz 源文件的直接链接,请访问3.6.83.6.7

这些是来自源文件README.rst 的一些内容

Build Instructions
------------------

On Unix, Linux, BSD, macOS, and Cygwin::

    ./configure
    make
    make test
    sudo make install

This will install Python as python3.

如果你想在你的系统中将 python3.6 安装为 python3.6(不是 python3),这里是 README.rst 文件中的一些其他指南

For example, if you want to install Python 2.7, 3.5, and 3.6 with 3.6 being the
primary version, you would execute ``make install`` in your 3.6 build directory
and ``make altinstall`` in the others.

谢谢...

【讨论】:

    【解决方案2】:

    不要乱搞你的系统。

    Ubuntu 19.04 作为 Python 3.7 作为给定标准,因此如果您想使用 Python 3.6.*,您应该安装 conda 并使用特定 Python 版本创建环境:

    conda create --name py36 -c conda-forge python=3.6.* pip  
    

    当然,您也可以创建其他虚拟环境并使用 pip。

    或者你可以去码头。


    在 Linux / macOS 上,您可以使用 nix 之类的

    nix-env -iA nixpkgs.python37
    

    进入一个环境,例如在本例中为 Python3.7(当然可以更改版本)

    或者作为一个非常好的 Python(高级)环境,您可以使用 mach-nix(带有 nix)之类的

    mach-nix env ./env -r requirements.txt 
    

    (甚至支持 conda [但目前处于测试阶段])

    或通过 api 之类的

    nix-shell -p nixFlakes --run "nix run github:davhau/mach-nix#with.ipython.pandas.seaborn.bokeh.scikit-learn "
    

    如果您真的想更改操作系统的版本,那么我建议您使用 NixOS。

    【讨论】:

      【解决方案3】:

      不需要从源代码编译,只需手动下载并安装带有依赖项的 deb-packages python 3.6:

      wget http://archive.ubuntu.com/ubuntu/pool/main/p/python3.6/libpython3.6-minimal_3.6.7-1~18.10_amd64.deb
      dpkg -i libpython3.6-minimal_3.6.7-1~18.10_amd64.deb
      wget http://archive.ubuntu.com/ubuntu/pool/main/p/python3.6/libpython3.6-stdlib_3.6.7-1~18.10_amd64.deb
      dpkg -i libpython3.6-stdlib_3.6.7-1~18.10_amd64.deb
      wget http://archive.ubuntu.com/ubuntu/pool/main/p/python3.6/python3.6-minimal_3.6.7-1~18.10_amd64.deb
      dpkg -i python3.6-minimal_3.6.7-1~18.10_amd64.deb
      
      wget http://archive.ubuntu.com/ubuntu/pool/main/p/python3.6/python3.6_3.6.7-1~18.10_amd64.deb
      dpkg -i python3.6_3.6.7-1~18.10_amd64.deb
      

      这足以运行 python 3.6。但是,某些模块可能不起作用,例如 pycurl,导致我没有找到解决方案。 ModuleNotFoundError 尝试导入时发生,ImportError 尝试安装 pycurl 时发生错误:cannot import name 'sysconfig' 因为 python3- distutils 包是从 3.7 版安装的,不兼容。 从 3.6 手动安装会破坏 3.7 版本的依赖关系,无论如何 apt 都会尝试修复它。

      【讨论】:

        猜你喜欢
        • 2019-10-11
        • 2023-03-15
        • 2017-07-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-09-10
        • 1970-01-01
        相关资源
        最近更新 更多