centos7.6 python3安装过程
安装python3
https://www.cnblogs.com/liuxuanhe/p/9219351.html
1.执行:yum install python-pip
若没有python-pip包,先执行:yum -y install epel-release,再执行yum install python-pip
2. pip install --upgrade pip
centos默认安装了python2.7
1. mkdir /usr/local/python3
2.安装依赖包:
yum groupinstall "Development tools" -y,不是必须安装的
yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel -y
yum -y install gcc
3.在/usr/local/python3目录下
cd /usr/local/python3
wget https://www.python.org/ftp/python/3.6.2/Python-3.6.2.tar.xz
4.在/usr/local/python3目录下
tar -xvf Python-3.6.2.tar.xz
cd Python-3.6.2
./configure --prefix=/usr/local/python3
make && make install
(可选)创建引用
ln -s /usr/local/python3/bin/python3.6 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
使用 virtualenv 创建虚拟环境
https://www.jianshu.com/p/66a437b95780
安装 virtualenv
pip install virtualenv
pip3 install virtualenv
[root@WX-TKY201-J02B-ZYC4Q-HP380-SV001 ~]# find / -name "virtualenv"
/usr/local/python3/bin/virtualenv
/usr/local/python3/lib/python3.6/site-packages/virtualenv
ln -s /usr/local/python3/bin/virtualenv /usr/bin/virtualenv3
预置好虚拟机环境的路径 /root下
[root@localhost ~]# cd /root
[root@localhost ~]# mkdir venv
[root@localhost ~]# cd venv/
创建虚拟环境
[root@localhost venv]# virtualenv -p /usr/local/python3/bin/python3.6 myenv
created virtual environment CPython3.6.2.final.0-64 in 1084ms
creator CPython3Posix(dest=/root/venv/myenv, clear=False, global=False)
seeder FromAppData(download=False, pip=bundle, wheel=bundle, setuptools=bundle, via=copy, app_data_dir=/root/.local/share/virtualenv)
added seed packages: pip==20.2.2, setuptools==49.6.0, wheel==0.35.1
activators PythonActivator,FishActivator,XonshActivator,CShellActivator,PowerShellActivator,BashActivator
或
[root@WX-TKY201-J02B-ZYC4Q-HP380-SV001 ~]# virtualenv3 -p /usr/local/python3/bin/python3.6 myenv
created virtual environment CPython3.6.2.final.0-64 in 536ms
creator CPython3Posix(dest=/root/myenv, clear=False, global=False)
seeder FromAppData(download=False, pip=bundle, setuptools=bundle, wheel=bundle, via=copy, app_data_dir=/root/.local/share/virtualenv)
added seed packages: pip==20.2.2, setuptools==49.6.0, wheel==0.35.1
activators BashActivator,CShellActivator,FishActivator,PowerShellActivator,PythonActivator,XonshActivator
[root@WX-TKY201-J02B-ZYC4Q-HP380-SV001 ~]#
虚拟环境已经创建完成
[root@localhost venv]# ll
total 0
drwxr-xr-x 4 root root 64 Aug 27 01:25 myenv
[root@localhost venv]# cd myenv/
[root@localhost myenv]# ls
bin lib pyvenv.cfg
激活虚拟环境
[root@localhost myenv]# cd bin/
[root@localhost bin]# . activate
# 这个时候就有python3 的命令了
(myenv) [root@localhost bin]# python
python python2 python2.7 python3 python3.6
# 执行python3命令
(myenv) [root@localhost bin]# python3
Python 3.6.2 (default, Aug 27 2020, 01:20:25)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
# python 也是用python3
(myenv) [root@localhost bin]# python
Python 3.6.2 (default, Aug 27 2020, 01:20:25)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
(myenv) [root@localhost bin]# ll
total 72
-rw-r--r-- 1 root root 2205 Aug 27 01:25 activate
-rw-r--r-- 1 root root 1424 Aug 27 01:25 activate.csh
-rw-r--r-- 1 root root 3055 Aug 27 01:25 activate.fish
-rw-r--r-- 1 root root 1751 Aug 27 01:25 activate.ps1
-rw-r--r-- 1 root root 1199 Aug 27 01:25 activate_this.py
-rw-r--r-- 1 root root 1146 Aug 27 01:25 activate.xsh
-rwxr-xr-x 1 root root 241 Aug 27 01:25 easy_install
-rwxr-xr-x 1 root root 241 Aug 27 01:25 easy_install3
-rwxr-xr-x 1 root root 241 Aug 27 01:25 easy_install-3.6
-rwxr-xr-x 1 root root 241 Aug 27 01:25 easy_install3.6
-rwxr-xr-x 1 root root 232 Aug 27 01:25 pip
-rwxr-xr-x 1 root root 232 Aug 27 01:25 pip3
-rwxr-xr-x 1 root root 232 Aug 27 01:25 pip-3.6
-rwxr-xr-x 1 root root 232 Aug 27 01:25 pip3.6
lrwxrwxrwx 1 root root 32 Aug 27 01:25 python -> /usr/local/python3/bin/python3.6
lrwxrwxrwx 1 root root 6 Aug 27 01:25 python3 -> python
lrwxrwxrwx 1 root root 6 Aug 27 01:25 python3.6 -> python
-rwxr-xr-x 1 root root 219 Aug 27 01:25 wheel
-rwxr-xr-x 1 root root 219 Aug 27 01:25 wheel3
-rwxr-xr-x 1 root root 219 Aug 27 01:25 wheel-3.6
-rwxr-xr-x 1 root root 219 Aug 27 01:25 wheel3.6
(myenv) [root@localhost bin]# ls
activate activate.ps1 easy_install easy_install3.6 pip-3.6 python3 wheel3
activate.csh activate_this.py easy_install3 pip pip3.6 python3.6 wheel-3.6
activate.fish activate.xsh easy_install-3.6 pip3 python wheel wheel3.6
(myenv) [root@localhost bin]# pip install django
Collecting django
Downloading Django-3.1-py3-none-any.whl (7.8 MB)
|████████████████████████████████| 7.8 MB 45 kB/s
Collecting pytz
Downloading pytz-2020.1-py2.py3-none-any.whl (510 kB)
|████████████████████████████████| 510 kB 37 kB/s
Collecting asgiref~=3.2.10
Downloading asgiref-3.2.10-py3-none-any.whl (19 kB)
Collecting sqlparse>=0.2.2
Downloading sqlparse-0.3.1-py2.py3-none-any.whl (40 kB)
|████████████████████████████████| 40 kB 36 kB/s
Installing collected packages: pytz, asgiref, sqlparse, django
Successfully installed asgiref-3.2.10 django-3.1 pytz-2020.1 sqlparse-0.3.1
(myenv) [root@localhost bin]#