1. 安装python
root@McJevons:/home# apt install python3.8
root@McJevons:/home# apt install python3.8-venv
2. 建立并启动python虚拟环境
root@McJevons:/home# mkdir data_science_env # 建立目录
root@McJevons:/home# cd data_science_env/ # 进入目录,
root@McJevons:/home/data_science_env# python3.8 -m venv env # 在目录下建立名为env的虚拟环境
root@McJevons:/home/data_science_env# source env/bin/activate # 启动虚拟环境
虚拟环境启动后,命令行提示符前会出现(env),表明目前处在env虚拟环境中,在此环境中安装的各种python库和配置都只对该环境生效。
3. 安装并配置jupyter notebook
# 在虚拟环境中操作
(env) root@McJevons:/home/data_science_env# pip install jupyter
# 重置notebook配置
(env) root@McJevons:/home/data_science_envjupyter notebook --generate-config --allow-root
Overwrite /root/.jupyter/jupyter_notebook_config.py with default config? [y/N]y
Writing default config to: /root/.jupyter/jupyter_notebook_config.py
# 进入python命令行,设置notebook密码,记住最后生成的公钥
(env) root@McJevons:/home/data_science_env# python
Python 3.8.0 (default, Oct 28 2019, 16:14:01)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from notebook.auth import passwd
>>> passwd()
Enter password:
Verify password:
'sha1:901ea3458357:e5e947d9129e7b485339d...'
# 打开notebook配置文件,并做相应修改
(env) root@McJevons:/home/data_science_env# vim /root/.jupyter/jupyter_notebook_config.py
c.NotebookApp.ip = '0.0.0.0' # 对外提供访问的ip
c.NotebookApp.port = 8888 # 对外提供访问的端口
c.NotebookApp.open_browser = False # 启动不打开浏览器
c.NotebookApp.password = 'sha1:901ea3458357:e5e947d9129e7b485339d...' # 公钥
c.NotebookApp.notebook_dir = u'/home/data_science_env/notebook' # 设置jupyter启动后默认文件夹
c.NotebookApp.allow_root = True # 允许root用户执行
4. 启动jupyter notebook
(env) root@McJevons:/home/data_science_env# jupyter notebook
参考:https://www.jianshu.com/p/0c9dcbf277ed