如何用源代码安装Python 3.8.1

最简单的方式当然是yum install python3了,但Oracle Linux默认安装的是3.6.8,而我想安装更新一些的版本。

安装python3.8.1的过程如下:

  1. 官网下载源代码包
  2. 解压
  3. 进入目录Python-3.8.1
  4. 按照README.rst中的说明操作:
    ./configure
    make
    make test
    sudo make install

最后两步的时间时间较长。
我安装时,在最后一步报错:

python 3.8.1 make install ModuleNotFoundError: No module named 'zlib'

安装zlib开发包后通过:

sudo yum install zlib-devel

安装后可执行程序为python3.8, 符号链接python3指向此文件:

$ python3 --version
Python 3.8.1

升级pip:

$ pip3 install --user --upgrade pip
Collecting pip
  Using cached https://files.pythonhosted.org/packages/54/0c/d01aa759fdc501a58f431eb594a17495f15b88da142ce14b5845662c13f3/pip-20.0.2-py2.py3-none-any.whl
Installing collected packages: pip
Successfully installed pip-20.0.2

pip3安装某模块报错:

$ pip3 install --user pyinputplus
WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.

解决方法参见这里

yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel
make
make install 

pip3安装某模块再次报错:

WARNING: pip is being invoked by an old script wrapper. This will fail in a future version of pip.
Please see https://github.com/pypa/pip/issues/5599 for advice on fixing the underlying issue.
To avoid this problem you can invoke Python with '-m pip' instead of running pip directly.
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ReadTimeoutError("HTTPSConnectionPool(host='pypi.org', port=443): Read timed out. (read timeout=15)")': /simple/pyinputplus/
Collecting pyinputplus
  Using cached PyInputPlus-0.2.8.tar.gz (20 kB)
    ERROR: Command errored out with exit status 1:
     command: /usr/local/bin/python3.8 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-hofx1t7q/pyinputplus/setup.py'"'"'; __file__='"'"'/tmp/pip-install-hofx1t7q/pyinputplus/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-install-hofx1t7q/pyinputplus/pip-egg-info
         cwd: /tmp/pip-install-hofx1t7q/pyinputplus/
    Complete output (11 lines):
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/usr/local/lib/python3.8/site-packages/setuptools/__init__.py", line 20, in <module>
        from setuptools.dist import Distribution, Feature
      File "/usr/local/lib/python3.8/site-packages/setuptools/dist.py", line 35, in <module>
        from setuptools import windows_support
      File "/usr/local/lib/python3.8/site-packages/setuptools/windows_support.py", line 2, in <module>
        import ctypes
      File "/usr/local/lib/python3.8/ctypes/__init__.py", line 7, in <module>
        from _ctypes import Union, Structure, Array
    ModuleNotFoundError: No module named '_ctypes'
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

解决方法参见这里,安装以下包后重新安装Python:

$ sudo yum install libffi-devel 
发布了377 篇原创文章 · 获赞 43 · 访问量 55万+

猜你喜欢

转载自blog.csdn.net/stevensxiao/article/details/104107512