1、CentOS 上部署Python3
一、安裝依賴包python
二、官網下載python原碼包react
三、解壓安裝linux
四、修改配置文件
首先進入上一步解壓的目錄redis
五、開始編譯安裝sql
六、配置共享庫文文件bash
1)爲全部用用戶設置共享庫目目錄
#cd /usr/local/src/Python-3.6.5/
#cp libpython3.6m.so.1.0 /usr/local/lib64/
#cp libpython3.6m.so.1.0 /usr/lib/
#cp libpython3.6m.so.1.0 /usr/lib64/
2)刷新環境變量
#source /etc/profileapp
七、測試pythoncurl
Python 3.6.5 (default, Mar 29 2019, 17:13:23)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux
Type "help", "copyright", "credits" or "license" for more information.ide
exit()工具
八、測試 pip3
pip 9.0.3 from /usr/local/lib/python3.6/site-packages (python 3.6)
2、使用第三方的虛擬工具 Virtualenvwrapper
2.1 安裝virtualenvwrapper 提供了一系列命令使得和虛擬環境⼯做變得愉快許多。它把你全部的虛擬環境都放在一個地方。更重要的是,你只需運行一個命令便可進入到你的虛擬環境,就沒必要像以前須要先進如虛擬環境的目錄下安裝(確保 virtualenv 已經安裝了)
2.2 修改默認的環境目錄:
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
#指定解釋器
export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python3.6
#這個能夠自定義 虛擬環境存放目錄
export WORKON_HOME=~/.virtualenv
#項目存放目錄,須要本身建立
export PROJECT_HOME=~/.virtualenv/project_data
#自動加載virtualenvmrapper
source /usr/local/bin/virtualenvwrapper.sh
2.3 建立存放虛擬環境的目錄
mkdir ~/.virtualenv
2.4 初始化一下
2.5 基本使用: 建立一個虛擬環境:
2.6 退出虛擬環境:
deactivate
[root@redis ld.so.conf.d]# workon test
(test) [root@redis test]# deactivate
2.7 進入虛擬環境:
[root@redis ld.so.conf.d]# workon
python3
test
[root@redis ld.so.conf.d]# workon test
(test) [root@redis test]#
2.8 建立項目:
(test) [root@redis test]# mkproject test1
Using base prefix '/usr/local'
New python executable in /root/.virtualenv/test1/bin/python3.6
Also creating executable in /root/.virtualenv/test1/bin/python
Installing setuptools, pip, wheel...
done.
virtualenvwrapper.user_scripts creating /root/.virtualenv/test1/bin/predeactivate
virtualenvwrapper.user_scripts creating /root/.virtualenv/test1/bin/postdeactivate
virtualenvwrapper.user_scripts creating /root/.virtualenv/test1/bin/preactivate
virtualenvwrapper.user_scripts creating /root/.virtualenv/test1/bin/postactivate
virtualenvwrapper.user_scripts creating /root/.virtualenv/test1/bin/get_env_details
Creating /root/.virtualenv/project_data/test1
Setting project for test1 to /root/.virtualenv/project_data/test1
(test1) [root@redis test1]# ls
(test1) [root@redis test1]# ls /root/.virtualenv/project_data/
test test1
2.10列出當前環境安裝的包:
lssitepackages:
(test1) [root@redis test1]# lssitepackages
easy_install.py pip-19.0.3.dist-info pycache setuptools-40.8.0.dist-info wheel-0.33.1.dist-info
pip pkg_resources setuptools wheel
2.11 建立臨時運行環境:
mktmpenv
[root@redis test1]# mktmpenv
Using base prefix '/usr/local'
New python executable in /root/.virtualenv/tmp-4aa130f4957b04a/bin/python3.6
Also creating executable in /root/.virtualenv/tmp-4aa130f4957b04a/bin/python
Installing setuptools, pip, wheel...
done.
virtualenvwrapper.user_scripts creating /root/.virtualenv/tmp-4aa130f4957b04a/bin/predeactivate
virtualenvwrapper.user_scripts creating /root/.virtualenv/tmp-4aa130f4957b04a/bin/postdeactivate
virtualenvwrapper.user_scripts creating /root/.virtualenv/tmp-4aa130f4957b04a/bin/preactivate
virtualenvwrapper.user_scripts creating /root/.virtualenv/tmp-4aa130f4957b04a/bin/postactivate
virtualenvwrapper.user_scripts creating /root/.virtualenv/tmp-4aa130f4957b04a/bin/get_env_details
This is a temporary environment. It will be deleted when you run 'deactivate'.
2.12 臨時環境退出即刪除:
(tmp-4aa130f4957b04a) [root@redis tmp-4aa130f4957b04a]# deactivate
Removing temporary environment: tmp-4aa130f4957b04a
Removing tmp-4aa130f4957b04a...
2.13 刪除虛擬環境:
rmvirtualenv
[root@redis .virtualenv]# workon
python3
test1
test
[root@redis .virtualenv]# rmvirtualenv python3
Removing python3...
[root@redis .virtualenv]# workon
test1
test
2.14 在虛擬環境安裝包
全部的虛擬環境都在 ~/.virtualenv/project_data下,都是獨立的,互不影響,在虛擬環境中安裝包,使用pip便可,無需root權限
[root@redis .virtualenv]# workon test
(test) [root@redis test]# pip install selenium
Collecting selenium
Downloading https://files.pythonhosted.org/packages/80/d6/4294f0b4bce4de0abf13e17190289f9d0613b0a44e5dd6a7f5ca98459853/selenium-3.141.0-py2.py3-none-any.whl (904kB)
100% |████████████████████████████████| 911kB 15kB/s
Collecting urllib3 (from selenium)
Downloading https://files.pythonhosted.org/packages/62/00/ee1d7de624db8ba7090d1226aebefab96a2c71cd5cfa7629d6ad3f61b79e/urllib3-1.24.1-py2.py3-none-any.whl (118kB)
100% |████████████████████████████████| 122kB 11kB/s
Installing collected packages: urllib3, selenium
Successfully installed selenium-3.141.0 urllib3-1.24.1
(test) [root@redis test]# pip list
Package Version
pip 19.0.3
selenium 3.141.0
setuptools 40.8.0
urllib3 1.24.1
wheel 0.33.1
(test) [root@redis test]# deactivate
切換到env_python3.6查看《沒有selenium包》:
[root@redis test]# workon test1
(test1) [root@redis test1]# pip list
Package Version
pip 19.0.3 setuptools 40.8.0 wheel 0.33.1