一般情況下都會自帶安裝了python2,所以不要刪除。繼續安裝你的python3就好,因為某些程序需要依賴目前python2環境。
一.安裝依賴環境
# yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel
二.下載Python3
從[官網下載](https://www.python.org/downloads/)相應的Python版本,目前最新版本為Python3.6.7,[點擊下載](https://www.python.org/ftp/python/3.6.3/Python-3.6.3.tgz)。
也可以通過如下命令下載:
wget https://www.python.org/ftp/python/3.6.7/Python-3.6.7.tgz
三.安裝
在Python下載目錄依次運行如下命令
[root@cdh1 opt]# tar zxvf Python-3.6.7.tgz
[root@cdh1 opt]# cd Python-3.6.7
創建安裝目錄
[root@cdh1 Python-3.6.7]# mkdir -p /usr/local/python3
[root@cdh1 Python-3.6.7]# ./configure --prefix=/usr/local/python3
[root@cdh1 Python-3.6.7]# make
[root@cdh1 Python-3.6.7]# make install
make是一個編譯命令,如果make的時候出現以下情況
那就是沒有找到makefile,可以看下configure的時候有沒有報錯呀?是不是提示有什么依賴的包沒有裝,先把依賴的包裝了。再configure試試,看有沒有makefile。
四.安裝依賴包(若不報錯,則此步驟不用安裝)
安裝python的時候出現如下的錯誤:
Python3.6安裝報錯 configure: error: no acceptable C compiler found in $PATH**
[root@master ~]#./configure --prefix=/usr/local/python3.6
checking build system type... i686-pc-linux-gnu
checking host system type... i686-pc-linux-gnu
checking for --enable-universalsdk... no
checking for --with-universal-archs... 32-bit
checking MACHDEP... linux
checking for --without-gcc... no
checking for gcc... no
checking for cc... no
checking for cl.exe... no
configure: error: in `/usr/local/src/pythonSoft/Python-3.3.4':
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details
由於本機缺少gcc編譯環境
1.通過yum安裝gcc編譯環境:yum install -y gcc
2.本機沒有安裝yum功能,可下載gcc安裝包:https://gcc.gnu.org/
[root@cdh1 Python-3.6.7]# yum install -y gcc
然后再make
[root@cdh1 Python-3.6.7]# make
[root@cdh1 Python-3.6.7]# make install
五.建立python3的軟鏈
一般情況下使用第一種方法
第一種方法:直接創建
[root@cdh1 Python-3.6.7]# ln -s /usr/local/python3/bin/python3 /usr/bin/python3
第二種方法:創建新版本的軟連接
###修改舊版本
mv /usr/bin/python /usr/bin/python_bak
###創建新的軟連接
ln -s /usr/local/python3/bin/python3 /usr/bin/python
六.將(/usr/local/python3/bin)加入PATH 路徑
[root@cdh1 Python-3.6.7]# vim ~/.bash_profile
將原:PATH=$PATH:$HOME/bin:
改成:PATH=$PATH:$HOME/bin:/usr/local/python3/bin
\# .bash_profile
\# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
\# User specific environment and startup programs
PATH=$PATH:$HOME/bin:/usr/local/python3/bin
export PATH
按ESC,輸入:wq回車退出
七.修改完PATH路徑記得執行行下面的命令,讓上一步修改生效
[root@cdh1 Python-3.6.7]# source ~/.bash_profile
八.最后檢查Python3及pip3是否安裝成功
[root@cdh1 Python-3.6.7]# python3 -V
Python 3.6.7
[root@cdh1 Python-3.6.7]# pip3 -V
pip 10.0.1 from /usr/local/python3/lib/python3.6/site-packages/pip (python 3.6)
[root@cdh1 Python-3.6.7]#python3
Python 3.6.7 (default, Mar 23 2020, 17:02:26)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-11)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
出現以上情況說明安裝成功,否則繼續以下安裝
如果有問題再創建一下pip3的軟鏈接,重新生成
[root@cdh1 Python-3.6.7]# ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
安裝pip以及setuptools
為了方便的安裝第三方庫,使用pip3命令,需要進行相應的安裝。 最新版本 setuptools (39.0.1)
[root@cdh1 Python-3.6.7]#wget --no-check-certificate https://pypi.python.org/packages/source/s/setuptools/setuptools-19.6.tar.gz#md5=c607dd118eae682c44ed146367a17e26
[root@cdh1 Python-3.6.7]# tar -zxvf setuptools-19.6.tar.gz
[root@cdh1 Python-3.6.7]# cd setuptools-19.6
[root@cdh1 setuptools-19.6]# python3 setup.py build
[root@cdh1 setuptools-19.6]#python3 setup.py install
如果前面沒布置好環境的話繼續操作如下方法
報錯: RuntimeError: Compression requires the (missing) zlib module
我們需要在linux中安裝zlib-devel包,進行支持。
[root@cdh1 Python-3.6.7]# yum install zlib-devel
需要對python3.6進行重新編譯安裝。
[root@cdh1 Python-3.6.7]# cd python3.6.7
[root@cdh1 Python-3.6.7]# make
[root@cdh1 Python-3.6.7]# make install
又是漫長的編譯安裝過程。
重新安裝setuptools
[root@cdh1 Python-3.6.7]# python3 setup.py build
[root@cdh1 Python-3.6.7]# python3 setup.py install
安裝pip命令如下:
[root@cdh1 Python-3.6.7]# wget --no-check-certificate https://pypi.python.org/packages/source/p/pip/pip-8.0.2.tar.gz#md5=3a73c4188f8dbad6a1e6f6d44d117eeb
[root@cdh1 Python-3.6.7]# tar -zxvf pip-8.0.2.tar.gz
[root@cdh1 Python-3.6.7]# cd pip-8.0.2
[root@cdh1 Python-3.6.7]# python3 setup.py build
[root@cdh1 Python-3.6.7]# python3 setup.py install
如果沒有意外的話,pip安裝完成
如果沒有搞好環境的話,會碰見親切的報錯:
[root@cdh1 Python-3.6.7]# pip3 install paramiko
報這個錯:pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
然后開始進行如下操作
[root@cdh1 Python-3.6.7]# yum install openssl
[root@cdh1 Python-3.6.7]# yum install openssl-devel
[root@cdh1 Python-3.6.7]# cd python3.6.7
[root@cdh1 Python-3.6.7]# make
[root@cdh1 Python-3.6.7]# make install
還可以參考下面同學的鏈接
https://www.cnblogs.com/kimyeee/p/7250560.html
根據自己需求安裝相應模塊
[root@cdh1 Python-3.6.7]# pip3 install requests
[root@cdh1 Python-3.6.7]# pip3 install flask
[root@cdh1 Python-3.6.7]# pip3 install gevent
[root@cdh1 Python-3.6.7]# pip3 install redis
[root@cdh1 Python-3.6.7]# pip3 install redis-py-cluster
[root@cdh1 Python-3.6.7]# pip3 install pymongo
[root@cdh1 Python-3.6.7]# pip3 install pillow
[root@cdh1 Python-3.6.7]# pip3 install numpy
[root@cdh1 Python-3.6.7]# pip3 install tensorflow
用命令將Python安裝包導出導入
導出
pip3 freeze > requirements.txt
導入
pip3 install -r requirements.txt
aliyun-python-sdk-core==2.13.15
aliyun-python-sdk-core-v3==2.13.11
aliyun-python-sdk-kms==2.10.1
beautifulsoup4==4.7.1
boto==2.49.0
boto3==1.10.32
botocore==1.13.32
bs4==0.0.1
certifi==2019.11.28
cffi==1.12.2
chardet==3.0.4
crcmod==1.7
demjson==2.2.4
docutils==0.15.2
gensim==3.8.1
gevent==1.4.0
greenlet==0.4.15
idna==2.8
jmespath==0.9.4
kafka==1.3.5
kafka-python==1.4.7
lxml==4.5.0
numpy==1.15.4
oss2==2.9.1
Pillow==7.0.0
pycparser==2.19
pycryptodome==3.9.7
pymongo==3.10.0
python-dateutil==2.8.0
redis==2.10.6
redis-py-cluster==1.3.6
requests==2.22.0
s3transfer==0.2.1
scipy==1.2.1
selenium==3.141.0
six==1.13.0
smart-open==1.9.0
soupsieve==1.8
threadpool==1.3.2
tornado==6.0.3
urllib3==1.25.7
wincertstore==0.2
在Linux系統下常用命令
Linux遠程拷貝scp命令
[root@iZbp17myadp30d5qukpv2wZ opt]# scp Python-3.6.7.tgz root@47.97.37.7:/opt/
The authenticity of host '47.97.37.7 (47.97.37.7)' can't be established.
ECDSA key fingerprint is e7:ac:cd:3b:3c:3e:b2:e1:0f:a1:4e:2d:81:25:1c:9b.
Are you sure you want to continue connecting (yes/no)? y
Please type 'yes' or 'no': y
Please type 'yes' or 'no': yes
Warning: Permanently added '47.97.37.7' (ECDSA) to the list of known hosts.
root@47.97.37.7's password:
Python-3.6.7.tgz
從本機拷貝到目標遠程主機
scp 拷貝目標文件 遠程用戶@遠程主機地址:遠程目錄
scp php-7.2.4.tar.gz root@192.168.9.142:/usr/local/src/ //這里是從當前主機拷貝到IP位142的局域網主機目錄/usr/local/src下
The authenticity of host '192.168.9.142 (192.168.9.142)' can't be established.
RSA key fingerprint is 11:b6:be:81:a0:be:b7:14:b4:2d:d6:99:de:8d:7c:f1.
Are you sure you want to continue connecting (yes/no)? yes //輸入回車會彈出提示,然后輸入yes回車
root@192.168.9.142's password: //輸入密碼即可執行完成之后,去目標遠程主機對應目錄查看,文件在,說明成功
從遠程主機拷貝到本機
scp root@192.168.9.142:/usr/local/src/redis.tar.gz /usr/local/src/ //這里是從目標主機142拷貝文件到本機/usr/local/src下
root@192.168.9.142's password: //輸入遠程主機密碼回車即可
redis.tar.gz 100% 1696KB 1.7MB/s 00:00 補充、一次拷貝多個文件或者目錄
scp root@192.168.9.142:/usr/local/src/cp_dir/*.php /usr/local/src/ //拷貝多個文件
scp -r root@192.168.9.142:/usr/local/src/cp_dir/ /usr/local/src/ //拷貝目錄
壓縮包解壓方式
1.unzip Python-3.6.7.zip
2.tar -zxvf java.tar.gz
3.tar zxvf Python-3.6.7.tgz
解壓到指定的文件夾
# tar -zxvf java.tar.gz -C /usr/java
安裝上傳下載文件命令
# yum -y install lrzsz
unzip命令解壓縮的時候,出現錯誤
# unzip: command not found
其原因是找不到zip壓縮軟件,用yum解決問題
# yum install -y unzip zip
腳本執行權限
# chmod +x curl_ip.sh (filename)
#./ filename
定時crontab執行py腳本
每1小時零5分執行py腳本
5 */1 * * * python3 /root/auto_test_jinRong.py >/dev/null 2>&1
每4小時零5分執行py腳本:
5 */4 * * * python3 /root/auto_test_jinRong.py >/dev/null 2>&1
每隔5分鍾執行py腳本:
*/5 * * * * python3 /root/auto_test_jinRong.py >/dev/null 2>&1