CentOS 7.9--离线安装python3.9.18+virtualenv-20.25.0

2023-12-13 05:45:13

# 想在centos6.x 上安装新版本的python,但是担心在用系统的环境被破坏,所以需要安装python虚拟环境,然后就找到自用的aliyun主机先测试下离线安装,在用6.X环境是没有互联网的,必须需要离线安装。

1. 下载对应python源文件包(目录看到python的离线包的GUN方式的源文件)及相关的virturlenv软件

[root@AAA download]wget  https://www.python.org/ftp/python/3.9.18/Python-3.9.18.tgz

[root@AAA download]wget https://files.pythonhosted.org/packages/94/d7/adb787076e65dc99ef057e0118e25becf80dd05233ef4c86f07aa35f6492/virtualenv-20.25.0.tar.gz
[root@AAA download]ls -la

total 32672
drwxr-xr-x   2 root root     4096 Dec  9 11:31 .
dr-xr-xr-x. 20 root root     4096 Dec  9 11:35 ..
-rw-r--r--   1 root root 26294072 Aug 25 03:13 Python-3.9.18.tgz
-rw-r--r--   1 root root  7150307 Dec  2 00:24 virtualenv-20.25.0.tar.gz

2. 创建临时文件来存放解压的源文件并进行安装 --源文件安装使用的了.configure && make && make install 等命令

[root@AAA download]mkdir /test/pyhton39 /test/virtualenv
[root@AAA download]tar -zxvf  Python-3.9.18.tgz -C /test/python39/
[root@AAA download]tar .zxvf virtualenv-20.25.0.tar.gz -C /test/virtualenv/

[root@AAA download]cd /test/python39/
[root@AAA python39]ls 
Python-3.9.18
[root@AAA python39]cd Python-3.9.18
[root@AAA Python-3.9.18]ls
total 52812
-rw-rw-r--  1 1000 1000    20687 Aug 25 01:59 aclocal.m4
drwxr-xr-x  5 root root     4096 Dec  9 12:21 build
-rw-rw-r--  1 1000 1000      630 Aug 25 01:59 CODE_OF_CONDUCT.md
-rwxrwxr-x  1 1000 1000    49348 Aug 25 01:59 config.guess
-rw-r--r--  1 root root   692118 Dec  9 12:18 config.log
-rwxr-xr-x  1 root root    42592 Dec  9 12:18 config.status
-rwxrwxr-x  1 1000 1000    35276 Aug 25 01:59 config.sub
-rwxrwxr-x  1 1000 1000   515269 Aug 25 01:59 configure
-rw-rw-r--  1 1000 1000   174973 Aug 25 01:59 configure.ac
drwxrwxr-x 18 1000 1000     4096 Aug 25 02:16 Doc
drwxrwxr-x  2 1000 1000     4096 Aug 25 01:59 Grammar
drwxrwxr-x  4 1000 1000     4096 Aug 25 01:59 Include
-rwxrwxr-x  1 1000 1000    15368 Aug 25 01:59 install-sh
drwxrwxr-x 35 1000 1000     4096 Dec  9 12:20 Lib
-rw-r--r--  1 root root 33995450 Dec  9 12:20 libpython3.9.a
-rw-rw-r--  1 1000 1000    13937 Aug 25 01:59 LICENSE
drwxrwxr-x  8 1000 1000     4096 Aug 25 01:59 Mac
-rw-r--r--  1 root root    80908 Dec  9 12:18 Makefile
-rw-r--r--  1 root root    71550 Dec  9 12:18 Makefile.pre
-rw-rw-r--  1 1000 1000    71862 Aug 25 01:59 Makefile.pre.in
drwxrwxr-x  2 1000 1000     4096 Dec  9 12:18 Misc
drwxrwxr-x 14 1000 1000     4096 Dec  9 12:20 Modules
-rw-rw-r--  1 1000 1000       82 Aug 25 01:59 netlify.toml
drwxrwxr-x  4 1000 1000     4096 Dec  9 12:19 Objects
drwxrwxr-x  4 1000 1000     4096 Dec  9 12:19 Parser
drwxrwxr-x  6 1000 1000     4096 Aug 25 01:59 PC
drwxrwxr-x  2 1000 1000     4096 Aug 25 01:59 PCbuild
drwxrwxr-x  2 1000 1000     4096 Dec  9 12:21 Programs
-rw-r--r--  1 root root       26 Dec  9 12:20 pybuilddir.txt
-rw-r--r--  1 root root    48061 Dec  9 12:18 pyconfig.h
-rw-rw-r--  1 1000 1000    45912 Aug 25 01:59 pyconfig.h.in
-rwxr-xr-x  1 root root 17901688 Dec  9 12:20 python
drwxrwxr-x  3 1000 1000     4096 Dec  9 12:20 Python
-rw-r--r--  1 root root     3091 Dec  9 12:21 python-config
-rw-r--r--  1 root root     2047 Dec  9 12:21 python-config.py
-rw-r--r--  1 root root    65501 Dec  9 12:21 python-gdb.py
-rw-rw-r--  1 1000 1000    10215 Aug 25 01:59 README.rst
-rw-rw-r--  1 1000 1000   110680 Aug 25 01:59 setup.py
drwxrwxr-x 23 1000 1000     4096 Aug 25 01:59 Tools
# 这里要指定安装目录,所以在.configure阶段需要使用 --prefix 参数 可以参考我另一片文章或百度
[root@AAA Python-3.9.18] ./configure --prefix=/test/Python39 


# .configure 是自动收集系统环境而生产MAKEFILE 或makefile 所以接着要开始编译
[root@AAA Python-3.9.18]make

# 编译后就可以进行安装了  
[root@AAA Python-3.9.18]make install

3 .安装virturlenv 本来以为它也是需要上面步骤的,但是测试一下,它是解压后就可以使用了,前提是调用python来执行,正好使用刚才安装好的python3.9

# 进到刚才解压的目录并查看
[root@AAA test]cd virtualenv && ls
total 8
drwxr-xr-x 5 root root 4096 Dec  9 11:38 virtualenv-20.25.0
[root@AAA virtualenv]cd virtualenv-20.25.0 && ll
[root@feric virtualenv-20.25.0]# ll
total 40
-rw-r--r-- 1 root root 1074 Feb  2  2020 LICENSE
-rw-r--r-- 1 root root 4499 Feb  2  2020 PKG-INFO
-rw-r--r-- 1 root root 5942 Feb  2  2020 pyproject.toml
-rw-r--r-- 1 root root 1764 Feb  2  2020 README.md
drwxr-xr-x 3 root root 4096 Dec  9 11:38 src
drwxr-xr-x 2 root root 4096 Dec  9 11:38 tasks
drwxr-xr-x 4 root root 4096 Dec  9 11:38 tests
-rw-r--r-- 1 root root 2508 Feb  2  2020 tox.ini

# 安装virtualenv 且也指定目录

[root@feric virtualenv-20.25.0]mkdir -p /test/Virtualenv2

# 找到setup.py文件做在位置进行安装

[root@feric test ]#  python3.9 -m pip install -e virtualenv-20.25.0  --prefix=/test/Virtualenv2

./tests/unit/create/via_global_ref/greet/setup.py
./tests/unit/create/console_app/setup.py
./tests/unit/create/console_app/setup.cfg
./src/virtualenv/seed/wheels/embed/setuptools-69.0.2-py3-none-any.whl
./src/virtualenv/seed/wheels/embed/setuptools-68.0.0-py3-none-any.whl

[root@feric virtualenv-20.25.0]# cd tests/unit/create/console_app/

# 指定目录安装  --prefix= 后面就是要指定的路径

[root@feric console_app]# python3.9 setup.py install --prefix=/test/Virtualenv2

# 安装完成后进到目标目录查看情况
[root@feric console_app]# cd /test/
[root@feric test]# cd Virtualenv2/ && ll
total 8
drwxr-xr-x 2 root root 4096 Dec  9 15:56 bin
drwxr-xr-x 3 root root 4096 Dec  9 15:56 lib



4.创建虚拟环境

文章来源:https://blog.csdn.net/weixin_42419429/article/details/134895760
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。