CentOS7下安装python3.6.8

由于最近有个任务需要在python环境下跑,项目是python3.6 + tensorflow1.3.1.现总结安装环境:
卸载Python3.6方法:
首先用命令: whereis python 查看所要删除的python3.6文件位置然后用命令: rm -rf 删除


安装Python3.6.8方法:
一:单独使用Python, setuptools, pip安装包安装
由于我是CentOS7的环境,CentOS7下确认不是缺少gcc等一些底层的依赖.按下面步骤执行安装

  1. yum update

  2. 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

  3. yum -y groupinstall "Development tools"

  4. 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

  5. yum install wget

  6. wget https://www.python.org/ftp/python/3.6.8/Python-3.6.8.tar.xz (也可以换成3.6.2版本,看自己的需要)

  7. mkdir /usr/local/python3

  8. tar -xvJf  Python-3.6.8.tar.xz

  9. cd Python-3.6.8

  10. ./configure --prefix=/usr/local/python3
    (注:./configure --prefix=/usr/local/python3这句的作用就是将程序安装在/usr/local/python3这个目录下)

  11. make && make install
    (注:make是编译,make install是安装)

  12. ln -s /usr/local/python3/bin/python3 /usr/bin/python3
    (注: 创建软链接将 /usr/bin/python3指向/usr/local/python3/bin/python3)

  13. 安装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

  14. tar -zxvf setuptools-19.6.tar.gz

  15. cd setuptools-19.6

  16. python3 setup.py build

  17. python3 setup.py install

  18. 安装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 

  19. tar -zxvf pip-8.0.2.tar.gz

  20. cd pip-8.0.2

  21. python3 setup.py build

  22. python3 setup.py install

  23. 设置软链接:
    ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3

  24. 提示你更新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的方法:
cd ~/.pip 如果没有pip这个路径的话自己创建一个: mkdir ~/.pip
cd ~/.pip
touch pip.conf
gedit pip.conf

在pip.conf文件里添加:
[global]
index-url = http://mirrors.aliyun.com/pypi/simple/
[install]
trusted-host=mirrors.aliyun.com

  1. 安装依赖包:
    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

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安装,由于我本人是直接把开发用的anaconda库打包放到我本地的(本地之前没有安装过anaconda),直接配置anaconda使用的。
如果和我一样直接拿别人的库用的话要注意:
/anaconda3/bin/pip
/anaconda3/bin/conda 这些文件开头的路径地址,要么地址一致要么修改这个里面的地址,我本人是直接放到/root/data01下面的
CentOS7下安装python3.6.8

配置环境变量: 

 vi ~/.bashrc //编辑环境变量

 source ~/.bashrc //保存后环境变量生效

给root用户的anaconda权限:
source  /data01/anaconda3/bin/activate root
查看conda环境:
conda env list
激活要使用的环境:
conda activate py365

CentOS7下安装python3.6.8
查看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
生成环境yml文件:conda env export > environment.yml
根据yml生成环境:conda env create -f environment.yml

------设置清华源-----
查看源:conda config --show-sources

添加源:
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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值