UBUNTU 安装openai 从零开始 pytorch1.3.1 报错 单独安装

本文档详细介绍了在Ubuntu系统中安装OpenAI及PyTorch 1.3.1的过程,包括更换软件源、安装必要的软件包、创建Anaconda环境、安装OpenMPI等步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

船新UBUNTU 安装openai 从零开始 @TOC

从零开始 openai 安装 pytorch1.3.1安装

新手上车,装了一个星期,从第一句cd命令开始,真是令人头皮发麻!
咱就从换源开始,一步步安装openai

一、换源

二、输入法安装

三、openai安装

五、Fm

一、换源

1.备份文件

sudo cp /etc/apt/sources.list sources_backup.list

2.修改文件

sudo gedit /etc/apt/sources.list

3.写入源,保存。(ubuntu16.04)

#清华大学源

deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial main restricted
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates main restricted
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security main restricted
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security multiverse

#阿里云源

deb-src http://archive.ubuntu.com/ubuntu xenial main restricted
deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted multiverse universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted multiverse universe
deb http://mirrors.aliyun.com/ubuntu/ xenial universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates universe
deb http://mirrors.aliyun.com/ubuntu/ xenial multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
deb http://archive.canonical.com/ubuntu xenial partner
deb-src http://archive.canonical.com/ubuntu xenial partner
deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted multiverse universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-security universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-security multiverse

阿里源(ubuntu18.04)

deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse

阿里源(ubuntu20.04)

deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse

阿里镜像站

https://developer.aliyun.com/mirror/ubuntu/?spm=a2c6h.25603864.0.0.47634af3iBaqpg

3.更新

a.这个命令,会访问源列表里的每个网址,并读取软件列表,然后保存在本地电脑。我们在新立得软件包管理器里看到的软件列表,都是通过update命令更新的。

sudo apt-get update

b.解决各种缺少依赖问题

sudo apt-get -f install

c.这个命令,会把本地已安装的软件,与刚下载的软件列表里对应软件进行对比,如果发现已安装的软件版本太低,就会提示你更新。

sudo apt-get upgrade

安装驱动

1、卸载驱动

sudo apt-get remove nvidia-*

2、查询可用驱动

sudo ubuntu-drivers devices

会出现类似的 (每个版本 因时间推进而可能版本号不同 以自己的为准
driver : nvidia-driver-470 - distro non-free driver : nvidia-driver-460-server - distro non-free recommended driver : xserver-xorg-video-nouveau - distro free builtin
3、选取在上面列表中自己需要的列表中的驱动安装即可 一般不推荐安装test的驱动

sudo apt install nvidia-driver-470

4、检验驱动是否安装成功

sudo nvidia-smi

5、编辑内核

sudo nano /etc/modprobe.d/blacklist.conf

文件末尾加上 blacklist nouveau 然后保存

sudo update-initramfs -u

使改动生效,这句很重要
7、重启

sudo reoot

二、输入法安装

https://blog.youkuaiyun.com/sandalphon4869/article/details/100781978
https://jingyan.baidu.com/article/fec4bce28610c4f2618d8b13.html

(ubuntu18.04)
https://blog.youkuaiyun.com/qq_27211927/article/details/80877684
IBus与fcitx切换的时候记得要重启

1.v2ay

在这里插入图片描述
/opt/v2ray/v2ray-linux-64/v2ray
/opt/v2ray/v2ray-linux-64

2.sh文件安装

bash xxxxx

三、openai安装

openai官网教程

这个是openai官方的教程页面

1.Anaconda(Anaconda3-5.3.0)

官方历史版本,找到Anaconda3-5.3.0-Linux-x86_64.sh
官方教程用的是5.3.0,跟着官方推荐一步一步装准没错!

https://repo.anaconda.com/archive/

下载完成,打开终端,进行安装

bash ~/Downloads/Anaconda3-5.3.0-Linux-x86_64.sh

安装完成后需要关闭终端再次打开,Anaconda才能生效

2.spinningup环境创建

创建一个spinningup的环境(这个名字可以随便改) 使用python3.6

conda create -n spinningup python=3.6

3.进入spinningup的环境

在之前创建好的环境中继续安装 接下来的环境依赖包

conda activate spinningup

4.安装OpenMPI

sudo apt-get update && sudo apt-get install libopenmpi-dev

5.git安装

sudo apt install git

6.安装Spinning Up

从github把Spinning Up载到本地

git clone https://github.com/openai/spinningup.git

移动到spinningup文件夹

cd spinningup

执行安装

pip install -e .

四、报错

安装pytorch1.3.1失败

下载到99%后突然崩了
在这里插入图片描述

tensorflow镜像

https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple/tensorflow/

解决方案:

1.下载好需要的pytorch版本
pytorch各个版本的.whl文件下载地址

https://download.pytorch.org/whl/torch_stable.html

2.下载完成后,进入文件目录,进行pip安装就行了

pip install torch-1.3.1-cp36-cp36m-linux_x86_64.whl

3.安装完成后再次回到sinningup文件进行

pip install -e .

五、Fm

1.更新软件

sudo apt-get update

2.安装推荐软件

sudo apt-get install -y --no-install-recommends build-essential
sudo apt-get install -y --no-install-recommends cmake
sudo apt-get install -y --no-install-recommends libzmqpp-dev
sudo apt-get install -y --no-install-recommends libopencv-dev

3.创建conda环境

conda create --name Fm python=3.6
conda activate Fm

4.git下载flightmare

cd ~/Desktop
git clone https://github.com/uzh-rpg/flightmare.git

5.添加环境变量

echo “export FLIGHTMARE_PATH=~/Desktop/flightmare” >> ~/.bashrc
source ~/.bashrc

6.安装依赖

conda activate Fm
cd flightmare/

install tensorflow GPU (for non-gpu user, use pip install tensorflow==1.14)

pip install tensorflow-gpu==1.14

install scikit

pip install scikit-build

记得安装eigen3.3.4

7.安装flightmare

cd flightmare/flightlib
it first compile the flightlib and then install it as a python package.
编译需要核数>4,内存>4G
pip install .

<think>好的,我现在需要帮用户解决如何在指定环境中安装PyTorch 1.3.1的问题。用户提供的引用资料里有几个相关的安装方法,我需要先仔细看看这些引用内容,然后整理出正确的步骤。 首先,用户提到了引用[1],里面提到使用conda安装PyTorch1.3.1和torchvision0.4.2的命令,但这个是CPU版本。用户可能需要在有或没有GPU的环境下安装,但这里明确是CPU版本。然后引用[2]是关于在Windows10下用Anaconda创建环境的步骤,用的是conda create命令,环境名是pytorch_gpu,不过用户可能不一定需要GPU版本,但可以借鉴创建环境的步骤。引用[3]讲的是用pip3安装PyTorch,但遇到了问题,后来修改了pip3脚本,然后安装成功,这里用的是sudo pip3 install torch torchvision,但可能对应的是较新版本,而用户需要的是1.3.1。引用[4]提到PyTorch官网可以选版本,尤其是历史版本,可能需要用不同的URL来安装旧版本。 用户的问题是如何在指定环境中安装PyTorch1.3.1。根据这些引用,我需要综合出两种方法:conda和pip安装,同时需要指定版本号。可能还需要注意CUDA版本的问题,不过用户可能不需要特定CUDA版本,或者需要根据情况选择。 首先,创建指定环境的步骤可以参考引用[2],用conda create命令。然后,安装PyTorch1.3.1的话,如果是conda安装,需要找到对应的conda命令。引用[1]中给出的是CPU版本的命令,即conda install pytorch1.3.1 torchvision0.4.2,但可能需要指定channel,比如pytorch的官方channel或者用-c pytorch。不过用户可能需要检查是否该命令在conda中有效,或者是否需要其他参数。 另外,引用[4]提到历史版本可能需要从特定的URL下载,比如用pip安装时加上--extra-index-url。例如,对于1.3.1版本,可能需要找到对应的wheel文件地址。例如,PyTorch的历史版本通常托管在https://download.pytorch.org/whl/,所以可能需要用类似pip install torch==1.3.1 torchvision==0.4.2 -f 加上对应的URL。 但需要注意,不同的CUDA版本可能需要不同的包。例如,如果用户需要CUDA 9.2或10.1的支持,可能需要不同的下载链接。但用户可能只需要CPU版本,这时候可以指定cu92或cu101,或者直接使用CPU版本。例如,PyTorch1.3.1的CPU版本可以通过pip install torch==1.3.1+cpu torchvision==0.4.2+cpu -f https://download.pytorch.org/whl/torch_stable.html,但需要确认这个版本是否存在。 但根据引用[1]中的conda命令,conda install pytorch1.3.1 torchvision0.4.2可能已经默认是CPU版本,因为引用[1]提到是“cpu版本”。而使用pip安装时,可能需要指定对应的版本和CUDA版本。例如,引用[3]中安装的是普通版本,但用户需要的是1.3.1,所以可能需要明确版本号。 综合这些信息,正确的步骤应该是: 1. 创建指定环境:使用conda create命令,如引用[2]中的例子,创建环境并指定Python版本。 2. 激活环境:conda activate env_name。 3. 安装PyTorch1.3.1和对应的torchvision,根据用户选择用conda或pip安装。 对于conda安装,可能需要检查是否在conda的channel中存在该版本。比如,conda install pytorch==1.3.1 torchvision==0.4.2 -c pytorch,或者使用特定的channel。但根据引用[1],直接使用conda install pytorch1.3.1 torchvision0.4.2可能有效,但可能缺少channel参数,导致找不到包。这时候可能需要添加pytorch的channel,例如:conda install pytorch==1.3.1 torchvision==0.4.2 -c pytorch。 对于pip安装,需要找到对应的wheel文件。根据PyTorch官网的历史版本页面,PyTorch1.3.1对应的命令可能类似于:pip install torch==1.3.1 torchvision==0.4.2 -f https://download.pytorch.org/whl/torch_stable.html。或者根据CUDA版本不同,可能需要不同的URL。例如,对于CUDA 9.2,可能是https://download.pytorch.org/whl/cu92/torch_stable.html,而CPU版本可能是https://download.pytorch.org/whl/cpu/torch_stable.html。 但需要验证这些URL是否有效。例如,访问https://download.pytorch.org/whl/cu92/torch_stable.html,看看是否有torch-1.3.1的版本。假设存在的话,那么用户可以选择对应的CUDA版本或者CPU版本。 如果用户不需要CUDA,可以用CPU版本,这时候安装命令可能如引用[1]中的conda命令,或者用pip install时指定CPU版本。 因此,总结步骤: 方法一:使用conda安装(CPU版本) - 创建环境:conda create -n myenv python=3.7 - 激活环境:conda activate myenv - 安装PyTorch1.3.1 CPU版本:conda install pytorch==1.3.1 torchvision==0.4.2 -c pytorch 但需要检查这个命令是否可行,可能正确的包名和版本是否存在。例如,在conda的pytorch channel中,是否存在pytorch1.3.1的CPU版本。根据引用[1]中的命令,用户可能已经成功安装了CPU版本,所以可能正确。 方法二:使用pip安装(支持CUDA或CPU) - 创建环境 - 激活环境 - 根据CUDA版本选择安装命令,例如: - CUDA 9.2: pip install torch==1.3.1+cu92 torchvision==0.4.2+cu92 -f https://download.pytorch.org/whl/torch_stable.html - CUDA 10.1: pip install torch==1.3.1+cu101 torchvision==0.4.2+cu101 -f https://download.pytorch.org/whl/torch_stable.html - CPU: pip install torch==1.3.1+cpu torchvision==0.4.2+cpu -f https://download.pytorch.org/whl/torch_stable.html 需要注意的是,PyTorch1.3.1的版本对应的torchvision版本是0.4.2,所以需要一起指定。同时,正确的URL可能需要调整,比如使用不同的CUDA版本标签。 另外,引用[3]中用户使用sudo pip3安装,但推荐在虚拟环境中安装,这样不需要sudo权限。因此,在创建conda环境后,应该使用pip install而不需要sudo。 可能遇到的问题包括:pip无法找到对应的版本,这时候需要确保指定的URL正确,或者版本号正确。例如,PyTorch的旧版本可能存放在不同的路径下,或者需要额外的索引URL,如引用[4]中的示例使用了--extra-index-url参数。 综上,整理出两种方法,并说明CUDA和CPU版本的安装方式,确保用户能根据自身需求选择正确的命令。同时,提醒用户注意Python版本兼容性,例如PyTorch1.3.1可能支持Python3.6或3.7,需要用户创建环境时选择正确的Python版本。</think>以下是安装 PyTorch 1.3.1 的步骤说明: --- ### **方法一:通过 Conda 安装(CPU版本)** 1. **创建并激活指定环境** 打开 Anaconda Prompt,运行以下命令创建独立环境(以 `python=3.7` 为例): ```bash conda create -n pytorch_env python=3.7 conda activate pytorch_env ``` 2. **安装 PyTorch 1.3.1** 直接使用 Conda 安装 CPU 版本(无需 CUDA): ```bash conda install pytorch==1.3.1 torchvision==0.4.2 -c pytorch ``` 此命令会从 PyTorch 官方渠道下载对应版本[^1]。 --- ### **方法二:通过 Pip 安装(支持 CUDA/CPU)** 1. **创建并激活环境** 参考 Conda 环境创建步骤,或使用 Python 虚拟环境。 2. **根据硬件选择安装命令** - **CUDA 9.2 版本**: ```bash pip install torch==1.3.1+cu92 torchvision==0.4.2+cu92 -f https://download.pytorch.org/whl/torch_stable.html ``` - **CUDA 10.1 版本**: ```bash pip install torch==1.3.1+cu101 torchvision==0.4.2+cu101 -f https://download.pytorch.org/whl/torch_stable.html ``` - **CPU 版本**: ```bash pip install torch==1.3.1+cpu torchvision==0.4.2+cpu -f https://download.pytorch.org/whl/torch_stable.html ``` 通过 `-f` 参数指定 PyTorch 官方历史版本仓库地址[^4]。 --- ### **验证安装** ```python import torch print(torch.__version__) # 应输出 1.3.1 print(torch.cuda.is_available()) # 检查 CUDA 是否可用(若安装 GPU 版本) ``` ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值