由于最近有個任務需要在python環(huán)境下跑,項目是python3.6 + tensorflow1.3.1.現總結安裝環(huán)境:
卸載Python3.6方法:
首先用命令: whereis python 查看所要刪除的python3.6文件位置然后用命令: rm -rf 刪除
安裝Python3.6.8方法:
一:單獨使用Python, setuptools, pip安裝包安裝
由于我是CentOS7的環(huán)境,CentOS7下確認不是缺少gcc等一些底層的依賴.按下面步驟執(zhí)行安裝
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
yum update yum install openssl-devel bzip2-devel expat-devel gdbm-devel readline- devel sqlite-devel gcc gcc-c++ openssl-devel libffi-devel python-devel mariadb-devel yum -y groupinstall "Development tools" 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 yum install wget wget https://www.python.org/ftp/python/3.6.8/Python-3.6.8.tar.xz (也可以換成3.6.2版本,看自己的需要) mkdir /usr/local/python3 tar -xvJf Python-3.6.8.tar.xz cd Python-3.6.8 ./configure --prefix=/usr/local/python3 (注:./configure --prefix=/usr/local/python3這句的作用就是將程序安裝在/usr/local/python3這個目錄下) make && make install (注:make是編譯,make install是安裝) ln -s /usr/local/python3/bin/python3 /usr/bin/python3 (注: 創(chuàng)建軟鏈接將 /usr/bin/python3指向/usr/local/python3/bin/python3) 安裝setuptools,下載setuptools wget --no-check-certificate https://pypi.python.org/packages/source/s/setuptools/setuptools-19.6.tar.gz#md5=c607dd118eae682c44ed146367a17e26 或者 wget https://pypi.python.org/packages/source/s/setuptools/setuptools-19.6.tar.gz#md5=c607dd118eae682c44ed146367a17e26 --no-check-certificate tar -zxvf setuptools-19.6.tar.gz cd setuptools-19.6 python3 setup.py build python3 setup.py install 安裝PIP,下載PIP: wget --no-check-certificate https://pypi.python.org/packages/source/p/pip/pip-8.0.2.tar.gz#md5=3a73c4188f8dbad6a1e6f6d44d117eeb 或者 wget https://pypi.python.org/packages/source/p/pip/pip-8.0.2.tar.gz#md5=3a73c4188f8dbad6a1e6f6d44d117eeb --no-check-certificate tar -zxvf pip-8.0.2.tar.gz cd pip-8.0.2 python3 setup.py build python3 setup.py install 設置軟鏈接: ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3 提示你更新pip的版本,我更新版本: pip3 install --upgrade pip //更新pip pip3 install --upgrade setuptools //更新setuptools |
25.配置pip使用的鏡像源,我本人配置的阿里源
國
內鏡像源列表:
豆瓣(douban) http://pypi.douban.com/simple/
清華大學 https://pypi.tuna.tsinghua.edu.cn/simple/
阿里云 http://mirrors.aliyun.com/pypi/simple/
中國科技大學 https://pypi.mirrors.ustc.edu.cn/simple/
中國科學技術大學 http://pypi.mirrors.ustc.edu.cn/simple/
配置pip的方法:
1
2
3
4
|
cd ~/.pip 如果沒有pip這個路徑的話自己創(chuàng)建一個: mkdir ~/.pip cd ~/.pip touch pip.conf gedit pip.conf |
在pip.conf文件里添加:
1
2
3
4
|
[global] index-url = http://mirrors.aliyun.com/pypi/simple/ [install] trusted-host=mirrors.aliyun.com |
安裝依賴包:
1
2
3
4
5
|
pip3 install numpy scipy matplotlib lmdb pillow pip3 install torch torchvision --user pip3 install nltk natsort pip3 install tensorflow==1.3.1 pip3 install opencv-python |
查看共享庫:yum whatprovides libSM.so.6
安裝共享庫:yum install libSM-1.2.2-2.el7.x86_64 --setopt=protected_multilib=false
1
2
3
|
pip3 install easydict Python3. 6.2 要安裝yum install python - qt4 否則報: ImportError: libXext.so. 6 : cannot open shared object file : No such file or directory |
二:使用anaconda安裝,由于我本人是直接把開發(fā)用的anaconda庫打包放到我本地的(本地之前沒有安裝過anaconda),直接配置anaconda使用的。
如果和我一樣直接拿別人的庫用的話要注意:
/anaconda3/bin/pip
/anaconda3/bin/conda 這些文件開頭的路徑地址,要么地址一致要么修改這個里面的地址,我本人是直接放到/root/data01下面的
配置環(huán)境變量:
vi ~/.bashrc //編輯環(huán)境變量
source ~/.bashrc //保存后環(huán)境變量生效
給root用戶的anaconda權限:
source /data01/anaconda3/bin/activate root
查看conda環(huán)境:
conda env list
激活要使用的環(huán)境:
conda activate py365
查看conda中所安裝的模塊: conda list
查找模塊: anaconda search -t conda numpy
顯示安裝命令: anaconda show xxxxx/xxxxxx
安裝命令: conda install --channel https://conda.anaconda.org/ukoethe numpy
安裝python3.6.8:conda create -n py368 python==3.6.8
生成環(huán)境yml文件:conda env export > environment.yml
根據yml生成環(huán)境:conda env create -f environment.yml
------設置清華源-----
查看源:conda config --show-sources
添加源:
1
2
3
|
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/ conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/ |
#設置搜索時顯示通道地址: conda config --set show_channel_urls yes
#刪除設置的通道: conda config --remove-key channels
總結
以上所述是小編給大家介紹的CentOS7下安裝python3.6.8的教程,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對服務器之家網站的支持!
如果你覺得本文對你有幫助,歡迎轉載,煩請注明出處,謝謝!
原文鏈接:https://blog.csdn.net/lookup123/article/details/103806378