IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> Python知识库 -> centos7安装python3及pytorch -> 正文阅读

[Python知识库]centos7安装python3及pytorch

一、安装Python3

1、首先安装依赖环境

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 libffi-devel

2、下载python3的源码
版本根据自己需求选择,官网网址:https://www.python.org/downloads/source/,下载taz格式的压缩包文件
在这里插入图片描述
3、下载完成后,把安装包解压到/usr用户目录中

tar -zxvf /home/xxx/Downloads/Python-3.8.11.tgz -C /usr

4、建立一个空文件夹python3,用于存放后面变编译的python源码

mkdir /opt/python3

5、进入解压后的python3安装包文件夹,编译,编译安装

cd /usr/Python-3.8.11
./configure --prefix=/usr/local/python3
make && make install

若报错

configure: error: in `/usr/Python-3.8.11':
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details

是因为由于本机缺少gcc编译环境,yum安装gcc编译环境:

yum install -y gcc

6、安装成功
python安装在之前新建的/opt/python3路径中
请添加图片描述
7、建立软链接

whereis python
python: /usr/bin/python /usr/bin/python2.7 /usr/lib/python2.7 /usr/lib64/python2.7 /etc/python /usr/include/python2.7 /opt/python3/bin/python3.8 /opt/python3/bin/python3.8-config /usr/share/man/man1/python.1.gz
ln -s /opt/python3/bin/python3.8 /usr/bin/python3
ln -s /opt/python3/bin/pip3.8 /usr/bin/pip3

8、添加环境变量
编辑/etc/profile文件

vim /etc/profile

在最后一行添加

export PATH=$PATH:/opt/python3/bin

使环境变量生效

source /etc/profile

9、测试python3和pip3是否可用
命令行输出python3
请添加图片描述
命令行输出pip3
请添加图片描述

二、安装pytorch

1、安装Anaconda

(1)下载安装包
官网下载x64版安装包:https://www.anaconda.com/products/individual#download-section
Anaconda Linux安装包地址:https://repo.anaconda.com/archive/Anaconda3-2021.05-Linux-x86_64.sh
(2)建立一个空文件夹/usr/anaconda,将安装包移动到此文件夹下

mkdir anaconda
mv /home/wwj/Downloads/Anaconda3-2021.05-Linux-x86_64.sh /usr/anaconda

(3)赋予bash文件权限

chmod 777 Anaconda3-2021.05-Linux-x86_64.sh

(4)安装anaconda

cd /usr/anaconda
./Anaconda3-2021.05-Linux-x86_64.sh
Welcome to Anaconda3 2021.05

In order to continue the installation process, please review the license
agreement.
Please, press ENTER to continue
>>> 
===================================
End User License Agreement - Anaconda Individual Edition
===================================

Copyright 2015-2021, Anaconda, Inc.

All rights reserved under the 3-clause BSD License:
.......
Anaconda reserves all rights not expressly granted to you in this Agreement.

Redistribution and use in source and binary forms, with or without modification, are permit
ted provided that the following conditions are met:

  * Redistributions of source code must retain the above copyright notice, this list of con
ditions and the following disclaimer.
......

一直按回车键,直到

The Intel Math Kernel Library contained in Anaconda Individual Edition is classified by Int
el as ECCN 5D992.c with no license required for export to non-embargoed countries.

The following packages listed on https://www.anaconda.com/cryptography are included in the 
repository accessible through Anaconda Individual Edition that relate to cryptography.

Last updated April 5, 2021

Do you accept the license terms? [yes|no]
[no] >>> 

输入yes,按enter

Anaconda3 will now be installed into this location:
/root/anaconda3

  - Press ENTER to confirm the location
  - Press CTRL-C to abort the installation
  - Or specify a different location below

[/root/anaconda3] >>> /opt/anaconda3

输入anaconda安装路径

PREFIX=/opt/anaconda3
Unpacking payload ...
Collecting package metadata (current_repodata.json): done                                  
Solving environment: done
Preparing transaction: done
Executing transaction: done
installation finished.
Do you wish the installer to initialize Anaconda3
by running conda init? [yes|no]
[no] >>> 

输入yes,回车

Thank you for installing Anaconda3!

===========================================================================

Working with Python and Jupyter notebooks is a breeze with PyCharm Pro,
designed to be used with Anaconda. Download now and have the best data
tools at your fingertips.

PyCharm Pro for Anaconda is available at: https://www.anaconda.com/pycharm

(5)查看anaconda是否安装成功

conda

请添加图片描述

conda list

请添加图片描述
(6)启动jupyter notebook

touch ~/.condarc
source ~/.bashrc
jupyter notebook

出现权限问题

(base) [root@localhost anaconda]# jupyter notebook
[I 21:37:19.531 NotebookApp] Writing notebook server cookie secret to /root/.local/share/jupyter/runtime/notebook_cookie_secret
[I 2021-08-08 21:37:20.459 LabApp] JupyterLab extension loaded from /opt/anaconda3/lib/python3.8/site-packages/jupyterlab
[I 2021-08-08 21:37:20.459 LabApp] JupyterLab application directory is /opt/anaconda3/share/jupyter/lab
[C 21:37:20.463 NotebookApp] Running as root is not recommended. Use --allow-root to bypass.

使用 jupyter notebook --generate-config 命令生成jupyter配置文件,将会提示当前生成的配置文件的存放路径,一般为 ~/.jupyter/jupyter_notebook_config.py
vim ~/.jupyter/jupyter_notebook_config.py打开配置文件,找到 #c.NotebookApp.allow_root = False ,去掉#,并修改为True

## Whether to allow the user to run the notebook as root.
#  Default: False
c.NotebookApp.allow_root = True

保存该文件,启动jupyter notebook
请添加图片描述
复制网址到浏览器即可打开jupyter notebook
请添加图片描述

2、安装pytorch

# 安装pytorch和torchvision
conda install pytorch -c pytorch
conda install torchvision -c pytorch

测试一下

(base) [root@localhost opt]# python
Python 3.8.8 (default, Apr 13 2021, 19:58:26) 
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> x=torch.rand(5,3)
>>> print(x)
tensor([[0.1521, 0.1508, 0.4489],
        [0.8602, 0.4759, 0.7634],
        [0.9307, 0.6808, 0.3035],
        [0.9490, 0.9632, 0.3540],
        [0.8841, 0.5200, 0.0960]])
>>> exit()
  Python知识库 最新文章
Python中String模块
【Python】 14-CVS文件操作
python的panda库读写文件
使用Nordic的nrf52840实现蓝牙DFU过程
【Python学习记录】numpy数组用法整理
Python学习笔记
python字符串和列表
python如何从txt文件中解析出有效的数据
Python编程从入门到实践自学/3.1-3.2
python变量
上一篇文章      下一篇文章      查看所有文章
加:2021-08-09 10:12:00  更:2021-08-09 10:14:01 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年5日历 -2024/5/17 14:37:08-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码