Linux安装Anaconda、TensorFlow、Keras
1、安装anaconda
从清华镜像源下载需要的anaconda:
https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/
我下载的是红色框住的版本。
下载好之后通过xftp传到服务器上,并运行bash xxx.sh
安装过程中的截图如下,一路回车,输入y(yes)即可:
注意最后一步询问是否安装vscode,一般输no,因为在服务器里面都是用vim编辑器的,没必要多装一个。
# anaconda3(2),根据版本确定,Sweeneys为自己的用户名
export PATH="/home/Sweeneys/anaconda3/bin:$PATH"
# 刷新环境变量
source ~/.bashrc
可以看到之后的python版本成功变为anaconda的版本
配置清华镜像源。
因为anaconda服务器在国外,安装package时候会很慢,甚至会经常出现连接不上服务器的情况,所以需将镜像源映射到国内清华镜像源(国内被授权的),命令如下:
# 添加Anaconda的TUNA镜像
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
# 为避免上述镜像源中不存在,再添加几个第三方源
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 --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/bioconda/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/menpo/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
# 设置搜索时显示通道地址
conda config --set show_channel_urls yes
# 若想恢复官方源,即使用如下命令
conda config --remove-key channels
2、安装TensorFlow
1、使用conda 创建一个新的环境:
激活该环境
采用pip安装相应版本的TensorFlow-gpu
进入python查看安装是否成功以及版本是否正确
3、安装相应版本的keras
根据安装的TensorFlow安装相应版本的keras
如果使用conda激活环境出现如下错误:
CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'.
If your shell is Bash or a Bourne variant, enable conda for the current user with
$ echo ". /home/ubuntu/anaconda3/etc/profile.d/conda.sh" >> ~/.bashrc
or, for all users, enable conda with
$ sudo ln -s /home/ubuntu/anaconda3/etc/profile.d/conda.sh /etc/profile.d/conda.sh
The options above will permanently enable the 'conda' command, but they do NOT
put conda's base (root) environment on PATH. To do so, run
$ conda activate
in your terminal, or to put the base environment on PATH permanently, run
$ echo "conda activate" >> ~/.bashrc
Previous to conda 4.4, the recommended way to activate conda was to modify PATH in
your ~/.bashrc file. You should manually remove the line that looks like
export PATH="/home/ubuntu/anaconda3/bin:$PATH"
^^^ The above line should NO LONGER be in your ~/.bashrc file! ^^^
这是由于conda的激活命令出了问题,解决方法如下:
# 激活环境
source activate
# 退出环境
source deactivate
随后解决问题,可以进行激活环境了:
conda activate your-env-name
查看python、tensorflow、keras对应的版本号网址如下:
https://tensorflow.google.cn/install/source
https://docs.floydhub.com/guides/environments/