配置服务器:Linux 使用 conda 我所遇到的所有坑
熟悉三妹的小伙伴可能知道,三妹最近跳槽到了互联网,成为了 BAT 中的一个小小程序媛,因此 Mac 呀、服务器呀都是新的,如同一张白纸要被我配置成我喜欢的样子。
坦白说,我是相当不喜欢配置服务器环境的,坑太多。
但是,作为21世纪新时代程序媛,天不怕地不怕,坚决不能被 bug 打倒。
服务器基本上都是一个套路,大家共用一个服务器,但是每个人都有自己的路径,只能在有权限的路径下为所欲为,当然了,配置的东西也只限于自己用。
所以,本文记录了我配置服务器过程中,遇到的所有坑以及我如何最终填上坑的。
我目前接触到的项目是用 TensorFlow 训练模型,所以整体的配置服务器思路为:
安装 conda -> 新建虚拟环境 -> 安装 TensorFlow 和Python 等包。
一、安装 conda
1、Conda 官网
Installing on Linux — conda 4.10.3.post41+bc22d85c documentation
我其实做了两手准备,一个是使用 wget 命令直接在服务器安装,第二个是先把相应的包下载到 Mac 本地,再用 scp 命令传到服务器(公司限制,已经不能使用我最爱的 FileZilla 了,悲伤。。。)
所以第二种方法中提到的 Linux 版本的 Conda,就在上面的链接里下载就好。
2、官网地址的链接使用 wget 命令安装太慢,有没有啥办法?
答:有~ 可以使用清华大学镜像站中 Anaconda 的所有版本的网址:
https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/
找到自己想要的那个版本,然后右键复制链接地址,之后在服务器端新建一个目录,比如我就叫它 conda,进入 conda 文件夹后,wget + 复制好的地址,运行即可。
如:
wget https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/Anaconda3-2021.05-Linux-x86_64.sh
3、坑
好吧,我就知道不可能这么顺利的让我安装成功。
坑 1:
ERROR: cannot verify mirrors.tuna.tsinghua.edu.cn's certificate, issued by ‘/C=US/O=Let's Encrypt/CN=R3’: Issued certificate has expired. To connect to mirrors.tuna.tsinghua.edu.cn insecurely, use `--no-check-certificate'.
上面报错的意思是:
连接到 mirrors.tuna.tsinghua.edu.cn 不安全,使用“不检查证书”,即在 wget 后加入no-check-certificate 即可解决。
坑 2:
Anaconda3-2021.05-Linux-x86_64.sh: Permission denied Cannot write to ‘Anaconda3-2021.05-Linux-x86_64.sh’ (Success).
上面报错的意思是:
普通用户没有写入权限。应该切换到该用户家目录下,用户具有写入权限。
好吧,我切换, cd /home/自己路径。
坑 2 解决。
经过上述两个问题,我成功的下载了 Conda,效果如下:
4、bash 命令
安装好了 .sh 脚本之后需要运行,命令如下:
bash 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: This End User License Agreement (the "Agreement") is a legal agreement between y ou and Anaconda, Inc. ("Anaconda") and governs your use of Anaconda Individual E dition (which was formerly known as Anaconda Distribution). Subject to the terms of this Agreement, Anaconda hereby grants you a non-exclusi ve, non-transferable license to: * Install and use the Anaconda Individual Edition (which was formerly known as Anaconda Distribution), * Modify and create derivative works of sample source code delivered in Anacon da Individual Edition from Anaconda's repository; and * Redistribute code files in source (if provided to you by Anaconda as source) and binary forms, with or without modification subject to the requirements set forth below. Anaconda may, at its option, make available patches, workarounds or other update s to Anaconda Individual Edition. Unless the updates are provided with their sep arate governing terms, they are deemed part of Anaconda Individual Edition licen sed to you as provided in this Agreement. This Agreement does not entitle you to any support for Anaconda Individual Edition. 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 permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, th is list of conditions and the following disclaimer in the documentation and/or o --More--
上述这一坨,就不停点击 空格键 就行。
You must comply with all domestic and international export laws and regulations that apply to the software, which include restrictions on destinations, end user s, and end use. Anaconda Individual Edition includes cryptographic software. The country in which you currently reside may have restrictions on the import, poss ession, use, and/or re-export to another country, of encryption software. BEFORE using any encryption software, please check your country's laws, regulations an d policies concerning the import, possession, or use, and re-export of encryptio n software, to see if this is permitted. See the Wassenaar Arrangement http://ww w.wassenaar.org/ for more information. Anaconda has self-classified this software as Export Commodity Control Number (E CCN) 5D992.c, which includes mass market information security software using or performing cryptographic functions with asymmetric algorithms. No license is req uired for export of this software to non-embargoed countries. The Intel Math Kernel Library contained in Anaconda Individual Edition is classi fied by Intel as ECCN 5D992.c with no license required for export to non-embargo ed countries. The following packages listed on https://www.anaconda.com/cryptography are inclu ded 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
上面这个步骤,都不用问,肯定写 yes 呀,不然费这么大劲安装是因为工作量不饱和吗?
Anaconda3 will now be installed into this location: ************* - Press ENTER to confirm the location - Press CTRL-C to abort the installation - Or specify a different location below
上边的 ************* 是我伪装的打码,其实就是问题把 Anaconda3 安装在下边路径行不行,行的话就按回车键。
Preparing transaction: done Executing transaction: done installation finished. Do you wish the installer to initialize Anaconda3 by running conda init? [yes|no] [no] >>> yes
安装好了初始化一下,继续无脑填 yes。
==> For changes to take effect, close and re-open your current shell. <== If you'd prefer that conda's base environment not be activated on startup, set the auto_activate_base parameter to false: conda config --set auto_activate_base false Thank you for installing Anaconda3!
最后,重启终端就行啦。
补充:
升级 conda 版本:
conda update -n base -c defaults conda
二、创建虚拟环境
1、检查已有虚拟环境
conda env list
2、创建虚拟环境
conda create -n tensorflow_dev
坑 3:
一开始使用下边命令:
conda env create -n tensorflow_dev
报错:
SpecNotFound: Invalid name, try the format: user/package
去掉 env 即可。
3、启动虚拟环境
conda activate tensorflow_dev
4、安装包
conda install 包名
还可以指定版本:
conda install python=3.8
5、退出虚拟环境
conda deactivate
P.S. 我竟然才知道 Linux 图标是它: