在这篇文章中,我们将带领您了解树莓派CENTOS7Python3.7安装jupyternotebook远程可访问的服务器的全貌,包括pycharm树莓派远程的相关情况。同时,我们还将为您介绍有关bas
在这篇文章中,我们将带领您了解树莓派 CENTOS7 Python3.7安装 jupyter notebook远程可访问的服务器的全貌,包括pycharm 树莓派远程的相关情况。同时,我们还将为您介绍有关bash – Jupyter / iPython Notebook的Root访问权限、Centos 7.4 安装 Jupyter NoteBook + TensorFlow 教程、CENTOS7 Python3.7 为jupyter notebook 安装python2.7内核、CentOS7.5 部署 Jupyter Notebook 并通过外网访问的知识,以帮助您更好地理解这个主题。
本文目录一览:- 树莓派 CENTOS7 Python3.7安装 jupyter notebook远程可访问的服务器(pycharm 树莓派远程)
- bash – Jupyter / iPython Notebook的Root访问权限
- Centos 7.4 安装 Jupyter NoteBook + TensorFlow 教程
- CENTOS7 Python3.7 为jupyter notebook 安装python2.7内核
- CentOS7.5 部署 Jupyter Notebook 并通过外网访问
树莓派 CENTOS7 Python3.7安装 jupyter notebook远程可访问的服务器(pycharm 树莓派远程)
1、前提条件:完成jupyter notebook安装
2、生成密码
python3.7
>>from notebook.auth import passwd
>>passwd() #输入密码后得到生成的密文,复制密文
3、生成配置文件
jupyter notebook --generate-config #生成默认配置文件
4、修改配置文件
vi ~/.jupyter/jupyter_notebook_config.py #打开上一步生成的配置文件,修改下面几行内容
c.NotebookApp.password = ''sha1:<your-sha1-hash-value>''
c.NotebookApp.port = 8888
c.NotebookApp.ip = ''0.0.0.0''
c.NotebookApp.open_browser = False
c.NotebookApp.allow_remote_access = True
c.NotebookApp.notebook_dir = ''/home/pi/web_notebooks''
注意:如果notebook为5.6.0以下版本,c.NotebookApp.ip = ''*'',为5.7.0,则设置为c.NotebookApp.ip = ''0.0.0.0''
5、放开8888端口
sudo firewall-cmd --zone=public --add-port=8888/tcp --permanent
sudo systemctl restart firewalld.service
6、中间出现的错误,参见第4点的注意项
Traceback (most recent call last):
File "/usr/local/python370/lib/python3.7/site-packages/notebook/notebookapp.py", line 869, in _default_allow_remote
addr = ipaddress.ip_address(self.ip)
File "/usr/local/python370/lib/python3.7/ipaddress.py", line 54, in ip_address
address)
ValueError: '''' does not appear to be an IPv4 or IPv6 address
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/python370/bin/jupyter-notebook", line 11, in <module>
sys.exit(main())
File "/usr/local/python370/lib/python3.7/site-packages/jupyter_core/application.py", line 266, in launch_instance
return super(JupyterApp, cls).launch_instance(argv=argv, **kwargs)
File "/usr/local/python370/lib/python3.7/site-packages/traitlets/config/application.py", line 657, in launch_instance
app.initialize(argv)
File "<decorator-gen-7>", line 2, in initialize
File "/usr/local/python370/lib/python3.7/site-packages/traitlets/config/application.py", line 87, in catch_config_error
return method(app, *args, **kwargs)
File "/usr/local/python370/lib/python3.7/site-packages/notebook/notebookapp.py", line 1629, in initialize
self.init_webapp()
File "/usr/local/python370/lib/python3.7/site-packages/notebook/notebookapp.py", line 1379, in init_webapp
self.jinja_environment_options,
File "/usr/local/python370/lib/python3.7/site-packages/notebook/notebookapp.py", line 158, in __init__
default_url, settings_overrides, jinja_env_options)
File "/usr/local/python370/lib/python3.7/site-packages/notebook/notebookapp.py", line 251, in init_settings
allow_remote_access=jupyter_app.allow_remote_access,
File "/usr/local/python370/lib/python3.7/site-packages/traitlets/traitlets.py", line 556, in __get__
return self.get(obj, cls)
File "/usr/local/python370/lib/python3.7/site-packages/traitlets/traitlets.py", line 535, in get
value = self._validate(obj, dynamic_default())
File "/usr/local/python370/lib/python3.7/site-packages/notebook/notebookapp.py", line 872, in _default_allow_remote
for info in socket.getaddrinfo(self.ip, self.port, 0, socket.SOCK_STREAM):
File "/usr/local/python370/lib/python3.7/socket.py", line 748, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -2] Name or service not known
bash – Jupyter / iPython Notebook的Root访问权限
我已经尝试过$sudo jupyter notebook以root身份运行笔记本,但这只会返回:
$jupyter: 'notebook' is not a Jupyter command
所以,我留下了运行$jupyter笔记本(除非有办法以root身份运行Jupyter笔记本).
我也不能在笔记本本身做su root因为这需要输入而笔记本不会让我输入.
最后,据称Jupyter笔记本有一个–allow-root选项:
http://jupyter-notebook.readthedocs.io/en/latest/config.html
但是,看起来–allow_root不再是一个选项. (我尝试通过添加NotebookApp.allow_root = True来修改配置文件,但这不起作用.)
有什么想法吗?也许我做错了什么?
解决方法
编辑:
在编辑配置文件之前,您需要以root身份运行jupyter notebook –generate-config来生成文件.
Centos 7.4 安装 Jupyter NoteBook + TensorFlow 教程
前言
这几天看学习视频,看到一个很好玩的东西 Jupyter Notebook
,但是视频上面都是安装的本地的。于是乎我想着,自己买的服务器闲着也是闲着就拿出来装一个,这样的话可以“云”使用。
0. 安装篇
这里我就直接使用 pyenv
的虚拟环境去安装,之前我有写过 Centos 7.4
安装 pyenv
,以及虚拟环境的使用。不知道的大家可以去看一下这篇文章《Centos 7.4 多版本Python以及虚拟环境安装》。
先创建一个虚拟环境
创建一个 Python v3.6.9
的虚拟环境,并进入环境。直接上命令吧:
# 创建
pyenv virtualenv 3.6.9 Jupyter_3.6
# 进入
pyenv activate Jupyter_3.6
接着就是简单粗暴的安装:
pip install ipython
pip install jupyter
其实到这里安装环节应该说是差不多了,但是要运行起来还需要配置一下。
下面放一下安装截图:
ipython
安装
jupyter
安装
1. 配置篇
生成配置文件
# 如果是root用户要加 --allow-root (我用的 root )
jupyter notebook --generate-config --allow-root
这里再使用 ipython
生成一下秘钥:
# 进入 ipython
ipython
# 这个是进入 ipython 后系统输出的
Python 3.6.9 (default, Aug 8 2019, 17:18:19)
Type ''copyright'', ''credits'' or ''license'' for more information
IPython 7.7.0 -- An enhanced Interactive Python. Type ''?'' for help.
# In 是输入,Out 是输出
# 引包
In [1]: from notebook.auth import passwd
In [2]: passwd()
Enter password:
Verify password:
# 记住这个秘钥
Out[2]: ''sha1:5d8d5d6ea2a5:04a*************************3c24b7280b67''
# 退出
In [3]: exit()
下面修改配置文件:
# 对外提供访问的ip
c.NotebookApp.ip = ''0.0.0.0''
# 对外提供访问的端口
c.NotebookApp.port = 37197
# 启动不打开浏览器
c.NotebookApp.open_browser = False
# 上面生成的秘钥
c.NotebookApp.password = ''sha1:5d8d5d6ea2a5:04a*************************3c24b7280b67''
# 设置jupyter启动后默认文件夹
c.NotebookApp.notebook_dir = u''/root/jupyter/jupyter_dir''
# 允许root用户执行
c.NotebookApp.allow_root = True
安装插件、使用主题
pip install jupyter_contrib_nbextensions
jupyter contrib nbextension install --user
pip install jupyterthemes # 安装
jt -t chesterish # 使用chesterish主题(可能需要重启jupyter)
jt -r # 恢复默认主题
运行
jupyter notebook
已经正常运行,可以打开服务器的 IP:PORT
就可以看到运行效果啦:
然后登录的话就是刚刚我们设置的密码,当然不是秘钥啦,是变成秘钥前输入了两次那个密码。
右上角那里有个 New
创建一个新文件,然后选 Python 3
啦。
到这里安装已经完成啦,安心食用吧!
后台运行
但是你会发现这样不可以后台运行,退出以后就访问不了了。
这个时候一条命令就可以帮你解决问题。
# cofing 后面对应的刚开始的那个配置文件
nohup jupyter notebook --config=/root/.jupyter/jupyter_notebook_config.py > /dev/null 2>&1 &
2. TensorFlow 安装篇
这个就比较简单了
pip install tensorflow
我机器上装完以后会有报错,报错信息如下:
FutureWarning: Passing (type, 1) or ''1type'' as a synonym of type is deprecated; in a future version of numpy
找了一些资料好像说是 numpy
版本过高的问题。于是乎下卸载,再安装一个低版本。
pip uninstall numpy
pip install numpy==1.1.3
这样我的 Centos 7.4
上就可以运行啦,可以看到版本号是 1.3.0!
拒绝拖延(感谢关注)
公众号:前端曰
公众号ID:js-say
ps:是(yuē)不是(ri)
CENTOS7 Python3.7 为jupyter notebook 安装python2.7内核
sudo yum install python2-pip
sudo python2 -m pip install wheel setuptools ipython==5.8.0 --index-url=https://pypi.tuna.tsinghua.edu.cn/simple --trusted-host pypi.tuna.tsinghua.edu.cn
sudo python2 -m pip install ipykernel==4.10.0 --index-url=https://pypi.tuna.tsinghua.edu.cn/simple --trusted-host pypi.tuna.tsinghua.edu.cn
python2 -m ipykernel install --name python2.7.5
或者
1.直接在/usr/local/python371/share/jupyter/kernels/中添加一个文件夹,名称为kernel_name,例如:python2.7.5
2.文件夹放3个文件:kernel.json logo-32x32.png logo-64x64.png
3.kernel.json内容如下:
{
"display_name": "python2.7.5",
"language": "python",
"argv": [
"/usr/bin/python2",
"-m",
"ipykernel_launcher",
"-f",
"{connection_file}"
]
}
4.创建一个启动脚本:start.sh
nohup /usr/local/python371/bin/jupyter notebook > /home/pi/web_notebooks/log/jupyter.log 2>&1 &
5.jupyter内核管理命令
查看jupyter notebook kernel 命令: jupyter kernelspec kernelname
删除jupyter notebook kernel 命令: jupyter kernelspce remove kernelname
添加:
python2 -m ipykernel install —name python2.7
列表:
python2 -m ipykernel list
jupyter kernelspce liust
6.其他
mypip371 install jupyter_contrib_nbextensions
python371 -m jupyter contrib nbextension install --user
http://localhost:8888/nbextensions?nbextension=toc2/main
CentOS7.5 部署 Jupyter Notebook 并通过外网访问
服务器部署在阿里云,想要在服务器内部进行python脚本测试比较麻烦,这时就想到了Jupyter Notebook,我们安装后即可直接在浏览器进行文学化编程,非常方便高效。
一、Jupyter notebook 是什么?
如何使用 Jupyter notebook。Jupyter notebook 是一种 Web 应用,能让用户将说明文本、数学方程、代码和可视化内容全部组合到一个易于共享的文档中。
Jupyter Notebook 已迅速成为处理数据的必备工具。其用途包括数据清理和探索、可视化、机器学习和大数据分析。我为我的个人博客创建了一个 notebook 示例,它展示了 notebook 的许多特点。这项工作通常在终端中完成,也即使用普通的 Python shell 或 IPython 完成。可视化在单独的窗口中进行,而文字资料以及各种函数和类脚本包含在独立的文档中。但是,notebook 能将这一切集中到一处,让用户一目了然。
GitHub 上也直接支持 Jupyter notebook 的渲染。借助此出色的功能,你可以轻松地共享工作。http://nbviewer.jupyter.org/ 也会提供 GitHub 代码库中的 notebook ,以及存储在其他地方的 notebook。
二、jupyter notebook使用
安装
pip install jupyter notebook
启动
jupyter notebook --allow-root # 如果是root用户则需要授权
# jupyter notebook
启动之后我们可以看到结果:
(base) [root@css Code]# jupyter notebook --allow-root
[I 14:08:27.170 NotebookApp] JupyterLab extension loaded from /root/anaconda3/lib/python3.7/site-packages/jupyterlab
[I 14:08:27.170 NotebookApp] JupyterLab application directory is /root/anaconda3/share/jupyter/lab
[I 14:08:27.174 NotebookApp] Serving notebooks from local directory: /work/Code
[I 14:08:27.174 NotebookApp] The Jupyter Notebook is running at:
[I 14:08:27.174 NotebookApp] http://localhost:8888/?token=04f6dcbcca528d3f3d0ca0ff349ebee4d755a872b3c31b42
[I 14:08:27.175 NotebookApp] or http://127.0.0.1:8888/?token=04f6dcbcca528d3f3d0ca0ff349ebee4d755a872b3c42
[I 14:08:27.175 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[W 14:08:27.201 NotebookApp] No web browser found: could not locate runnable browser.
[C 14:08:27.201 NotebookApp]
To access the notebook, open this file in a browser:
file:///root/.local/share/jupyter/runtime/nbserver-58623-open.html
Or copy and paste one of these URLs:
http://localhost:8888/?token=04f6dcbcca528d3f3d0ca0ff349ebee4d755a872b3c42
or http://127.0.0.1:8888/?token=04f6dcbcca528d3f3d0ca0ff349ebee4d755a872b3c42
我们可以看到,可以通过http://127.0.0.1:8888 进行访问,如果需要公网IP访问,需要打开8888端口的防火墙:
firewall-cmd --zone=public --add-port=8888/tcp --permanent
firewall-cmd --reload
通过上边的试了下,内网可以访问,外网还不能访问,还需要再做相关配置。
三、外网访问
1、Jupyter密码配置
将生成的密钥复制下来
(base) [root@css scraper]# ipython
Python 3.7.6 (default, Jan 8 2020, 19:59:22)
Type ''copyright'', ''credits'' or ''license'' for more information
IPython 7.12.0 -- An enhanced Interactive Python. Type ''?'' for help.
In [1]: from notebook.auth import passwd
In [2]: passwd()
Enter password:
Verify password:
Out[2]: ''sha1:3c7ece6d01a3:aef0f9818ea49be2c2f2cc5f5a6228fd327ec00d''
2、修改配置文件
1.生成配置文件,输入:
jupyter lab --generate-config
配置文件输出路径:
Writing default config to: /root/.jupyter/jupyter_notebook_config.py
2.打开 jupyter_notebook_config.py 配置文件,修改一下下面几处。
vim /root/.jupyter/jupyter_notebook_config.py
# 将ip设置为*,意味允许任何IP访问
c.NotebookApp.ip = ''*''
# 这里的密码就是上边我们生成的那一串
c.NotebookApp.password = ''sha1:3c7ece6d01a3:aef0f9818ea49be2c2f2cc5f5a6228fd327ec00d''
# 服务器上并没有浏览器可以供Jupyter打开
c.NotebookApp.open_browser = False
# 监听端口设置为8888或其他自己喜欢的端口
c.NotebookApp.port = 8888
# 我们可以修改jupyter的工作目录,也可以保持原样不变,如果修改的话,要保证这一目录已存在
#c.MappingKernelManager.root_dir = ''/root/jupyter_run''
# 允许远程访问
c.NotebookApp.allow_remote_access = True
3、防火墙开启
我们再上边已经开启了防火墙,如果没开启记得一定要开启8888这个端口的防火墙,否则公网访问不了。
firewall-cmd --zone=public --add-port=8888/tcp --permanent
firewall-cmd --reload
3、远程访问 Notebook
1.启动 Jupyter
jupyter lab --allow-root
2.浏览器输入
打开浏览器,输入http://公网ip地址:8888(例如,我这里输入http://98.126.219.176:8888)
3.结果显示
4.测试
新建一个文件,写一段代码打印当前时间测试:
我们可以看到新建的文件后缀为.ipynb
,这是notebook特有的文件后缀, 以后我们就可以通过jupty浏览器写代码了,就像写文章一样方便,这里写好测试好代码之后可以导出python文件即可,非常的方便。
相关文章:
Python 基础八-Jupyter notebook入门学习
云服务centos搭建jupyter notebook并通过外网访问
如何从外网调用内网的jupyter-notebook
今天关于树莓派 CENTOS7 Python3.7安装 jupyter notebook远程可访问的服务器和pycharm 树莓派远程的讲解已经结束,谢谢您的阅读,如果想了解更多关于bash – Jupyter / iPython Notebook的Root访问权限、Centos 7.4 安装 Jupyter NoteBook + TensorFlow 教程、CENTOS7 Python3.7 为jupyter notebook 安装python2.7内核、CentOS7.5 部署 Jupyter Notebook 并通过外网访问的相关知识,请在本站搜索。
本文标签: