暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

Python安装 for Linux

我们不秃头 2021-08-12
446

创建yum源配置信息

[root@Python01 ~]# cat > etc/yum.repos.d/dvd.repo <<END
> [dvd]
> name=install dvd
> baseurl=file:///media/cdrom/Server
> enabled=1
> gpgcheck=0
> END
[root@Python01 ~]#
[root@Python01 ~]#
[root@Python01 ~]# umount media/RHEL_6.1\ x86_64\ Disc\ 1/
umount: media/RHEL_6.1 x86_64 Disc 1/: not found
[root@Python01 ~]# umount media/
Red Hat Enterpri/ rhel/
[root@Python01 ~]# umount media/Red\ Hat\ Enterpri/
[root@Python01 ~]# mkdir media/cdrom
[root@Python01 ~]# mount dev/cdrom media/cdrom
mount: block device dev/sr0 is write-protected, mounting read-only
[root@Python01 ~]# yum clean all
Loaded plugins: product-id, refresh-packagekit, security, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Cleaning repos: dvd rhel-media
Cleaning up Everything
[root@Python01 ~]# yum list
Loaded plugins: product-id, refresh-packagekit, security, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
dvd | 3.9 kB 00:00 ...
dvd/primary_db | 3.1 MB 00:00 ...
file:///media/rhel/repodata/repomd.xml: [Errno 14] Could not open/read file:///media/rhel/repodata/repomd.xml
Trying other mirror.
Error: Cannot retrieve repository metadata (repomd.xml) for repository: rhel-media. Please verify its path and try again
[root@Python01 ~]# cd etc/yum.repos.d/
[root@Python01 yum.repos.d]# ls
dvd.repo packagekit-media.repo rhel-media.repo rhel-source.repo
[root@Python01 yum.repos.d]# ls -alrt
total 32
-rw-r--r--. 1 root root 529 Oct 30 2013 rhel-source.repo
-rw-r--r--. 1 root root 154 Jun 9 2018 rhel-media.repo
-rw-r--r-- 1 root root 125 Jan 17 20:51 packagekit-media.repo
drwxr-xr-x. 2 root root 4096 Jan 17 21:02 .
-rw-r--r-- 1 root root 79 Jan 17 21:02 dvd.repo
drwxr-xr-x. 112 root root 12288 Jan 17 21:03 ..
[root@Python01 yum.repos.d]# more rhel-media.repo
[rhel-media]
name=Red Hat Enterprise Linux 6.5
baseurl=file:///media/rhel
enabled=1
gpgcheck=1
gpgkey=file:///media/rhel/RPM-GPG-KEY-redhat-release
[root@Python01 yum.repos.d]# mount dev/cdrom media/rhel
mount: block device dev/sr0 is write-protected, mounting read-only
[root@Python01 yum.repos.d]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 18G 5.2G 12G 31%
tmpfs 1004M 76K 1004M 1% dev/shm
/dev/sr0 3.6G 3.6G 0 100% media/cdrom
/dev/sr0 3.6G 3.6G 0 100% media/rhel
[root@Python01 yum.repos.d]# yum list
Loaded plugins: product-id, refresh-packagekit, security, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
rhel-media | 3.9 kB 00:00 ...
rhel-media/primary_db | 3.1 MB 00:00 ...
Installed Packages
………………
………………

  

安装依赖包[1]

[root@Python01 yum.repos.d]# yum groupinstall 'Development Tools'
Loaded plugins: product-id, refresh-packagekit, security, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Setting up Group Process
dvd/group_gz | 204 kB 00:00 ... 
rhel-media/group_gz | 204 kB 00:00 ... 
………………
………………
Installed:
  autoconf.noarch 0:2.63-5.1.el6 automake.noarch 0:1.11.1-4.el6 byacc.x86_64 0:1.9.20070509-7.el6 cscope.x86_64 0:15.6-6.el6 ctags.x86_64 0:5.8-2.el6                  
  diffstat.x86_64 0:1.51-2.el6 doxygen.x86_64 1:1.6.1-6.el6 flex.x86_64 0:2.5.35-8.el6 git.x86_64 0:1.7.1-3.el6_4.1 indent.x86_64 0:2.2.10-7.el6              
  intltool.noarch 0:0.41.0-1.1.el6 libtool.x86_64 0:2.2.6-15.5.el6 patchutils.x86_64 0:0.3.1-3.1.el6 rcs.x86_64 0:5.7-37.el6 redhat-rpm-config.noarch 0:9.0.3-42.el6   
  rpm-build.x86_64 0:4.8.0-37.el6 subversion.x86_64 0:1.6.11-9.el6_4 swig.x86_64 0:1.3.40-6.el6 systemtap.x86_64 0:2.3-3.el6   
Dependency Installed:
  gettext-devel.x86_64 0:0.17-16.el6 gettext-libs.x86_64 0:0.17-16.el6 kernel-devel.x86_64 0:2.6.32-431.el6 perl-Error.noarch 1:0.17015-4.el6 perl-Git.noarch 0:1.7.1-3.el6_4.1  
  systemtap-client.x86_64 0:2.3-3.el6 systemtap-devel.x86_64 0:2.3-3.el6  
Complete!
root@Python01 yum.repos.d]# yum install zlib-devel bzip2-devel openssl-devel ncurses-devel
Loaded plugins: product-id, refresh-packagekit, security, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Existing lock /var/run/yum.pid: another copy is running as pid 2444.
Another app is currently holding the yum lock; waiting for it to exit...
  The other application is: PackageKit
………………
………………
Installed:
  bzip2-devel.x86_64 0:1.0.5-7.el6_0 openssl-devel.x86_64 0:1.0.1e-15.el6                                                           
Dependency Installed:
  keyutils-libs-devel.x86_64 0:1.4-4.el6 krb5-devel.x86_64 0:1.10.3-10.el6_4.6 libcom_err-devel.x86_64 0:1.41.12-18.el6 libselinux-devel.x86_64 0:2.0.94-5.3.el6_4.1      
  libsepol-devel.x86_64 0:2.0.41-4.el6        
Complete!

  

下载&安装[2]

[root@Python01 yum.repos.d]# wget https://www.python.org/ftp/python/3.6.8/Python-3.6.8.tar.xz
--2019-01-17 21:10:29-- https://www.python.org/ftp/python/3.6.8/Python-3.6.8.tar.xz
Resolving www.python.org... 151.101.72.223, 2a04:4e42:36::223
Connecting to www.python.org|151.101.72.223|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 17212420 (16M) [application/octet-stream]
Saving to: “Python-3.6.8.tar.xz”
………………
………………
[root@Python01 tmp]# mv /etc/yum.repos.d/Python-3.6.8.tar.xz ./
[root@Python01 tmp]# ls -alrt
total 47256
-rw-------. 1 root root 0 Jun 9 2018 yum.log
drwx------. 2 root root 4096 Jun 9 2018 virtual-root.rSCU9Y
drwx------. 2 root root 4096 Jun 9 2018 virtual-root.7DydZv
-rw-r--r--. 1 root root 657212 Jun 9 2018 ncurses-devel-5.7-3.20090208.el6.x86_64.rpm
-rw-r--r--. 1 root root 5691656 Jun 9 2018 cmake-2.8.8.tar.gz
-rw-r--r--. 1 root root 24596474 Jun 9 2018 mysql-5.5.32.tar.gz
drwxr-xr-x. 13 root root 4096 Jun 9 2018 cmake-2.8.8
drwx------ 2 root root 4096 Oct 27 22:47 keyring-EH7hOk
drwx------ 2 root root 4096 Oct 27 22:47 virtual-root.HoXf8X
-rw-r--r-- 1 root root 144458 Nov 6 10:16 mysql.sql.gz
-rw-r--r-- 1 root root 1030 Nov 6 10:16 oldboy.sql.gz
-rw-r--r-- 1 root root 534 Nov 6 10:16 test.sql.gz
-rw-r--r-- 1 root root 17212420 Dec 24 11:02 Python-3.6.8.tar.xz
dr-xr-xr-x. 27 root root 4096 Jan 17 20:34 ..
-r--r--r-- 1 root root 11 Jan 17 20:34 .X0-lock
drwxrwxrwt 2 root root 4096 Jan 17 20:34 .X11-unix
drwx------ 2 gdm gdm 4096 Jan 17 20:40 orbit-gdm
drwxrwxrwt 2 root root 4096 Jan 17 20:40 .ICE-unix
drwx------ 2 root root 4096 Jan 17 20:40 keyring-7eAys2
drwx------. 2 root root 4096 Jan 17 20:40 .esd-0
drwx------. 2 root root 4096 Jan 17 20:40 pulse-uBpS5OTDEoVl
drwx------ 2 root root 4096 Jan 17 20:40 virtual-root.DUox8e
drwx------. 2 gdm gdm 4096 Jan 17 20:40 pulse-rRQBmTRK3NFA
drwx------ 2 root root 4096 Jan 17 20:44 orbit-root
drwxrwxrwt. 16 root root 4096 Jan 17 21:47 .
[root@Python01 tmp]# tar Jxvf Python-3.6.8.tar.xz 
………………
………………
[root@Python01 tmp]# cd Python-3.6.8
[root@Python01 Python-3.6.8]# ls
aclocal.m4 config.sub configure.ac Grammar install-sh LICENSE Makefile.pre.in Modules Parser PCbuild pyconfig.h.in README.rst Tools
config.guess configure Doc Include Lib Mac Misc Objects PC Programs Python setup.py
[root@Python01 Python-3.6.8]# which python
/usr/bin/python
[root@Python01 Python-3.6.8]# ls /usr/local/bin/
ccmake cmake cpack ctest
[root@Python01 Python-3.6.8]# ls -alrt /usr/local/bin/
total 37268
-rwxr-xr-x. 1 root root 8984165 Jun 9 2018 ccmake
-rwxr-xr-x. 1 root root 8867005 Jun 9 2018 cmake
-rwxr-xr-x. 1 root root 9453904 Jun 9 2018 cpack
-rwxr-xr-x. 1 root root 10841386 Jun 9 2018 ctest
drwxr-xr-x. 2 root root 4096 Jun 9 2018 .
drwxr-xr-x. 14 root root 4096 Jun 9 2018 ..
[root@Python01 Python-3.6.8]# ls /usr/local/
bin doc etc games include lib lib64 libexec man sbin share src
[root@Python01 Python-3.6.8]# ./configure --prefix=/usr/local/python3
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking for python3.6... no
checking for python3... no
checking for python... python
checking for --enable-universalsdk... no
………………
………………
creating Modules/Setup
creating Modules/Setup.local
creating Makefile
If you want a release build with all stable optimizations active (PGO, etc),
please run ./configure --enable-optimizations
[root@Python01 Python-3.6.8]# ./configure --enable-optimizations
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
………………
………………
creating Modules/Setup
creating Modules/Setup.local
creating Makefile
[root@Python01 Python-3.6.8]# make && make install
Building with support for profile generation:
make clean
make[1]: Entering directory `/tmp/Python-3.6.8'
find . -depth -name 'pycache' -exec rm -rf {} ';'
find . -name '.py[co]' -exec rm -f {} ';'
find . -name '.[oa]' -exec rm -f {} ';'
………………
………………
Looking in links: /tmp/tmpnb11nmja
Collecting setuptools
Collecting pip
Installing collected packages: setuptools, pip
Successfully installed pip-18.1 setuptools-40.6.2

  

创建软链接[3]

[root@Python01 Python-3.6.8]# ln -s /usr/local/python3/bin/python3.5 /usr/local/bin/python3

参考资料

[1]

安装依赖包: 缺少依赖包后期使用会出现异常错误,很难排查

[2]

下载&安装: 此处我们安装python3.x,在安装包中有一个README的文件,里面有详细的操作步骤。

[3]

创建软链接: 为了便于直接使用,如果创建软链接后还是不能使用,需要检查一下环境变量。


文章转载自我们不秃头,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论