conda中tensorflow安装

2020-05-01  本文已影响0人  rushui

conda的安装

下载Anaconda

wget https://repo.anaconda.com/archive/Anaconda3-2019.07-Linux-x86_64.sh
bash Anaconda3-2019.07-Linux-x86_64.sh

启动conda

cd anaconda3/bin
chmod 777 activate
. ./activate #当命令行前面出现(base)的时候说明现在已经在conda的环境中了。这时候输入conda list 命令就有反应了

添加频道

conda config --add channels bioconda
conda config --add channels conda-forge
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/

显示安装的频道

conda config --set show_channel_urls yes 

查看已经添加的channels

conda config --get channels

查看已安装软件:

conda list

创建环境

conda create -n py3

作用环境

source activate py3 # linux
activate py3    # windows

安装tensorflow

conda install tensorflow

测试tensorflow

#进入python
python

import tensorflow as tf
message = tf.constant('Welcome to the exciting world of Deep Neural Networks!')
with tf.Session() as sess:
    print(sess.run(message).decode())

如出现报错

import os
os.environ['TF_CPP_MIN_LOG_LEVEL']='2'

tensorboard使用

tensorboard --logdir=/www/tensorflow/log

jupyter notebook 使用

# 设置工作目录
vim /root/.jupyter/jupyter_notebook_config.py
# 修改#c.NotebookApp.notebook_dir = '' 为
c.NotebookApp.notebook_dir = '/www/jupyter/'

# 运行
jupyter notebook

# 出现Running as root is not recommended. Use --allow-root to bypass.错误
# 查看配置文件位置
jupyter notebook --generate-config --allow-root
vim /root/.jupyter/jupyter_notebook_config.py

# 修改#c.NotebookApp.allow_root = False 为
c.NotebookApp.allow_root =True
# 设置访问密码 
# 打开 ipython 输入
from notebook.auth import passwd
passwd()
# 此处输入密码和确认密码

复制 ‘sha1:f5643****************************’ 粘贴至配置文件
vim /root/.jupyter/jupyter_notebook_config.py
c.NotebookApp.password = u'sha1:ee0a34cc39b4:fa18734c6672a617a63e464ec61db047efbf5ed3'

# 外网访问
c.NotebookApp.ip = '10.192.10.161'

#后台运行
nohup jupyter notebook > /www/jupyter/log/jupyter.log 2>&1 &

配置nginx

# jupyter
server {
   listen       80;
   server_name  jupyter.ddmc.com;

   location / {
        proxy_pass http://10.192.10.161:8888;
        proxy_set_header Host $host;
        proxy_set_header X-Real-Scheme $scheme;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

        # WebSocket support
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";

        proxy_read_timeout 120s;
        proxy_next_upstream error;
    }
}

启动时不启动小环境

vim .bashrc
注释掉:
# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
#__conda_setup="$('/root/anaconda3/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"
#if [ $? -eq 0 ]; then
#    eval "$__conda_setup"
#else
#    if [ -f "/root/anaconda3/etc/profile.d/conda.sh" ]; then
#        . "/root/anaconda3/etc/profile.d/conda.sh"
#    else
#        export PATH="/root/anaconda3/bin:$PATH"
#    fi
#fi
#unset __conda_setup
# <<< conda initialize <<<
上一篇下一篇

猜你喜欢

热点阅读