文章目录
- 一、安装Anaconda3
* - 1.1下载及安装Anaconda3
– - 二、创建TensorFlow环境
- 三、安装TensorFlow
- 四、链接jupyter和TensorFlow
- 五、jupyterlab配置远程访问
- 五、测试
一、安装Anaconda3
提示:此教程在Ubuntu系统下安装:
1.1下载及安装Anaconda3
1.1.1下载Anaconda3
清华镜像源:https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/
官网:https://repo.anaconda.com/archive/
此处教程直接使用wget在清华镜像源进行下载
wget https:
1.1.2安装Anaconda3
下载完成后,在当前路径下执行命令:
[En]
When the download is complete, under the current path, execute the command:
bash Anaconda3-2021.11-Linux-x86_64.sh
按Enter键查看协议,一直继续;
直到看到Please answer ‘yes’ or ‘no’,输入yes;
系统提示Anaconda将要安装的路径,这里可以记录一下,之后配置环境变量会用到,按Enter键继续,等待安装完成。
检查conda是否添加到了环境变量中,输入conda:如果命令找到,则不需要添加环境变量;若出现”conda: 未找到命令”,则需要添加环境变量;
1.1.3配置Anaconda3环境变量
首先,看anaconda是否自动配置了环境变量:
source ~/.bashrc
再次输入conda:如果命令找到,则不需要添加环境变量;若出现”conda: 未找到命令”,则需要手动添加环境变量;
手动添加环境变量:
sudo vim ~/.bashrc
在最后面添加,这个是根据自己的anaconda3安装路径填写,不要直接复制,具体安装路径在安装中有显示:
export PATH=/homeanaconda3/bin:$PATH
保存并退出(Esc :wq);
更新环境变量:
source ~/.bashrc
输入conda,命令找到则安装成功。
二、创建TensorFlow环境
创建环境,python版本根据自己的需求选择
conda create --name tensorflow python=3.9
激活tensorflow环境
conda activate tensorflow
此时已经进入tensorflow环境
三、安装TensorFlow
安装tensorflow(具体版本根据自己选择)
conda install tensorflow-gpu==你想要的版本号
可以使用命令”conda search tensorflow-gpu”查看可以是用的gpu版本
TensorFlow+CUDA+cudnn等环境网上教程较多,安装的时候注意版本号之间的对应关系,可参考(https://zhuanlan.zhihu.com/p/434517802)
四、链接jupyter和TensorFlow
添加虚拟环境
conda install -n tensorflow ipykernel
安装ipython,jupyterlab
pip install ipython
pip install jupyterlab
安装nodejs
conda install -c conda-forge nodejs
安装nb_conda_kernels
conda install nb_conda_kernels
这个是为了让 jupyterlab识别到虚拟环境中的python内核
五、jupyterlab配置远程访问
这里主要配置端口、密码和正在运行的远程访问。
[En]
Here, the port, password and running remote access are mainly configured.
运行以下命令:
jupyter lab --generate-config
会生成文件:/.jupyter/jupyter_server_config.json,该文件中有一个密钥;
继续运行一下命令:
jupyter lab password
设置您自己的登录密码,用于远程登录。
[En]
Set your own login password, which will be used for remote login.
操作完毕会生成文件:/.jupyter/jupyter_lab_config.py,如下图所示:
编辑jupyter_lab_config.py文件
vim jupyter_lab_config.py
添加以下内容:
c.ServerApp.ip = '*' #指定访问ip,'*'表示所有ip都可以访问
c.ServerApp.allow_remote_access = True
c.ServerApp.port = 8523 #指定端口号,需要指定一个空闲端口
c.ServerApp.open_browser = False
c.ServerApp.password = u'此处为密钥' #密钥在jupyter_server_config.json文件中拷贝
保存并退出(Esc :wq);
此时基本配置完成;
运行以下命令开启jupyterlab服务:
nohup jupyter lab
查询该服务器的ip
ifconfig
eno1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.20.3.12 netmask 255.255.255.0 broadcast 172.20.3.255
inet6 fe80::e799:3298:8b80:d5f3 prefixlen 64 scopeid 0x20<link>
ether b0:7b:25:08:65:22 txqueuelen 1000 (以太网)
RX packets 1006171 bytes 850824765 (850.8 MB)
RX errors 0 dropped 216392 overruns 0 frame 0
TX packets 444015 bytes 59240163 (59.2 MB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
device interrupt 16 memory 0x92f00000-92f20000
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (本地环回)
RX packets 227944 bytes 31753471 (31.7 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 227944 bytes 31753471 (31.7 MB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
则局域网中的其他主机可以在网页中输入”172.20.3.12:8523″(服务器ip:端口号)使用jupyterlab服务,登录密码为刚刚配置过程中设置的密码;
如果您需要访问公网,则需要在路由器上配置端口映射,以将局域网端口映射到公网。
[En]
If you need public network access, you need to configure port mapping on the router to map LAN ports to public networks.
五、测试
在jupyterlab打开一个ipykernel,输入以下代码:
import tensorflow as tf
tf.compat.v1.disable_eager_execution()
sess = tf.compat.v1.Session()
a = tf.constant(1)
b = tf.constant(2)
print(sess.run(a+b))
如下图所示,在右上角选择kernel的地方,选择刚刚自己创建的环境
点击运行
如果操作没有报告错误,则环境构建成功。
[En]
If the operation does not report an error, the environment will be built successfully.
如果您想要中文字体界面,请使用以下命令在终端安装,并在设置中选择中文重启界面。
[En]
If you want the Chinese font interface, install it at the terminal with the following command, and select the Chinese restart interface in the settings.
pip install jupyterlab-language-pack-zh-CN
Original: https://blog.csdn.net/breezejc/article/details/124380717
Author: breezejc
Title: Jupyterlab安装+远程访问配置+使用TensorFlow+插件安装
原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/497013/
转载文章受原作者版权保护。转载请注明原作者出处!