Ubuntu16.04+Anaconda安装+换源+环境创建+tensorflow安装

一、Anaconda,下载

Anaconda 安装包可以到 https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/ 下载。

ps:也可以去官网下载 https://www.anaconda.com/download/

列表内容
这里写图片描述

ps:本次使用的是Anaconda3-5.0.0-Linux-x86_64.sh

二、Anaconda,安装

进入文件目录:

bash ./Anaconda3-5.0.0-Linux-x86_64.sh

这里写图片描述


.

全程 yes +回车 ,默认安装在home目录下

三、Anaconda,环境变量

1.检查环境变量,没有则添加

查看命令

sudo gedit ~/.bashrc

这里写图片描述 
检查末尾是否已经添加如下变量,没有则添加

export PATH="/home/用户名/anaconda3/bin:$PATH"

这里写图片描述

2.打开控制台 ,更换清华源(墙太高)

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --set show_channel_urls yes

3.创建一个名tensorflow (python3.5) 的环境

conda create -n tensorflow python=3.5

激活环境

source activate tensorflow

四、tensorflow安装

下载tensorflow

搜索 python tensorflow1.6/1.7/1.8/1.9(GPU),选择gpu版本并选择cp35,迅雷下载

tensorflow1.6

cd到tensorflow存放目录下,执行命令:

pip install --ignore-installed --upgrade tensorflow_gpu-1.6.0-cp35-cp35m-manylinux1_x86_64.whl

会报错,按照红色部分最后一行的命令,更新pip至最新版本

pip install --upgrade pip

重新执行命令

pip install --ignore-installed --upgrade tensorflow_gpu-1.6.0-cp35-cp35m-manylinux1_x86_64.whl

安装完成

五、验证,在终端输入python进入环境

执行以下代码

#Python
import tensorflow as tf
hello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()
print(sess.run(hello))

若输出:

Hello, TensorFlow!

则安装成功!

六、遇到的错误+解决办法

1.如果换源之后任然无法创建环境,并且报网络连接的错误:

报错如下:

CondaHTTPError: HTTP 000 CONNECTION FAILED for url <https://repo.continuum.io/pkgs/main/linux-64/repodata.json.bz2>
Elapsed: -

An HTTP error occurred when trying to retrieve this URL.
HTTP errors are often intermittent, and a simple retry will get you on your way.
ConnectionError(MaxRetryError("HTTPSConnectionPool(host='repo.continuum.io', port=443): Max retries exceeded with url: /pkgs/main/linux-64/repodata.json.bz2 (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7fd5d462df28>: Failed to establish a new connection: [Errno 101] Network is unreachable',))",),)

解决办法: 
打开源文件

vim  ~/.condarc

删除defaults行

这里写图片描述

2.如果安装文件夹出现一把小锁,运行命令报错

报错如下

Traceback (most recent call last):
      File "/home/joahluo/Anaconda/lib/python3.6/site-packages/conda/exceptions.py", line 640, in conda_exception_handler
        return_value = func(*args, **kwargs)
      File "/home/joahluo/Anaconda/lib/python3.6/site-packages/conda/cli/main.py", line 140, in _main
        exit_code = args.func(args, p)
      File "/home/joahluo/Anaconda/lib/python3.6/site-packages/conda/cli/main_create.py", line 68, in execute
        install(args, parser, 'create')
      File "/home/joahluo/Anaconda/lib/python3.6/site-packages/conda/cli/install.py", line 231, in install
        unknown=index_args['unknown'], prefix=prefix)
      File "/home/joahluo/Anaconda/lib/python3.6/site-packages/conda/core/index.py", line 101, in get_index
        index = fetch_index(channel_priority_map, use_cache=use_cache)
      File "/home/joahluo/Anaconda/lib/python3.6/site-packages/conda/core/index.py", line 120, in fetch_index
        repodatas = collect_all_repodata(use_cache, tasks)
      File "/home/joahluo/Anaconda/lib/python3.6/site-packages/conda/core/repodata.py", line 75, in collect_all_repodata
        repodatas = _collect_repodatas_serial(use_cache, tasks)
      File "/home/joahluo/Anaconda/lib/python3.6/site-packages/conda/core/repodata.py", line 485, in _collect_repodatas_serial
        for url, schan, pri in tasks]
      File "/home/joahluo/Anaconda/lib/python3.6/site-packages/conda/core/repodata.py", line 485, in <listcomp>
        for url, schan, pri in tasks]
      File "/home/joahluo/Anaconda/lib/python3.6/site-packages/conda/core/repodata.py", line 115, in func
        res = f(*args, **kwargs)
      File "/home/joahluo/Anaconda/lib/python3.6/site-packages/conda/core/repodata.py", line 473, in fetch_repodata
        with open(cache_path, 'w') as fo:
    PermissionError: [Errno 13] Permission denied: '/home/joahluo/Anaconda/pkgs/cache/09e2740c.json'

解决办法: 
运行如下命令,赋予权限

sudo chmod -R 777 Anaconda

ps:其中Anaconda是我的安装的文件夹名字

参考:

https://blog.csdn.net/Zhenguo_Yan/article/details/78110082

https://blog.csdn.net/LEILEI18A/article/details/79490175

https://blog.csdn.net/luojie140/article/details/78696330

猜你喜欢

转载自blog.csdn.net/wzt_gjt/article/details/81590590