Ubuntu16.04 安装 python3.7 以及jupyter

本文详细介绍了如何在Linux环境下安装Python3.7,并利用pyenv进行版本管理,同时提供了配置Jupyter Notebook的方法,包括生成配置文件、设置密码及远程访问等步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

安装python3.7

参考自:https://www.cnblogs.com/bkylkh/p/9412906.html

1.安装依赖包

sudo apt-get update

sudo apt-get install build-essential python-dev python-setuptools python-pip python-smbus

sudo apt-get install build-essential libncursesw5-dev libgdbm-dev libc6-dev

sudo apt-get install zlib1g-dev libsqlite3-dev tk-dev

sudo apt-get install libssl-dev openssl

sudo apt-get install libffi-dev

 2. 安装pyenv

 git clone git://github.com/yyuu/pyenv.git ~/.pyenv
 echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc
 echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc
 echo 'eval "$(pyenv init -)"' >> ~/.bashrc
 exec $SHELL -l

3. 安装 python3.7.0

pyenv install 3.7.0 -v
安装完成之后,需要使用如下命令对数据库进行更新:
pyenv rehash
查看已经安装的python版本:
pyenv versions
* system (set by /root/.pyenv/version)
3.7.0

4.设置全局python版本

pyenv global 3.7.0 

之后输入python 默认就是 python3.7

python
Python 3.7.0 (default, Sep 30 2018, 11:18:04) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 

 

安装jupyter

pip3.7 install --upgrade pip //更新pip
pip3.7 install jupyter   //安装jupyter

此时输入

jupyter-notebook

会返回   jupyter: command not found

遇到这个状况退出重新登录就好。

仍有问题可以尝试再次安装

sudo apt install jupyter-notebook

这样本地就能运行 jupyter 了但是如果要是在服务器端设置的jupyter。想要通过 IP 访问,需要进行如下操作

配置服务器端jupyter

参考自:https://blog.youkuaiyun.com/simple_the_best/article/details/77005400

1. 生成一个 notebook 配置文件

默认情况下,配置文件 ~/.jupyter/jupyter_notebook_config.py 并不存在,需要自行创建。使用下列命令生成配置文件:

jupyter notebook --generate-config
  • 如果是 root 用户执行上面的命令,会发生一个问题:
Running as root it not recommended. Use --allow-root to bypass.
  • 提示信息很明显,root 用户执行时需要加上 --allow-root 选项。
jupyter notebook --generate-config --allow-config
  • 执行成功后,会出现下面的信息:
Writing default config to: /root/.jupyter/jupyter_notebook_config.py

 

2. 生成密码

自动生成

从 jupyter notebook 5.0 版本开始,提供了一个命令来设置密码:jupyter notebook password,生成的密码存储在 jupyter_notebook_config.json

$ jupyter notebook password
Enter password:  ****
Verify password: ****
[NotebookPasswordApp] Wrote hashed password to /Users/you/.jupyter/jupyter_notebook_config.json

手动生成

除了使用提供的命令,也可以通过手动安装,我是使用的手动安装,因为jupyter notebook password 出来一堆内容,没耐心看。打开 ipython 执行下面内容:

In [1]: from notebook.auth import passwd
In [2]: passwd()
Enter password:
Verify password:
Out[2]: 'sha1:67c9e60bb8b6:9ffede0825894254b2e042ea597d771089e11aed'

sha1:67c9e60bb8b6:9ffede0825894254b2e042ea597d771089e11aed

这一串就是要在 jupyter_notebook_config.py 添加的密码。

c.NotebookApp.password = 'sha1:67c9e60bb8b6:9ffede0825894254b2e042ea597d771089e11aed'

修改配置文件

jupyter_notebook_config.py 中找到下面的行,取消注释并修改。

vim .jupyter/jupyter_notebook_config.py
c.NotebookApp.allow_remote_access = True # 允许远程访问
c.NotebookApp.ip='*'
c.NotebookApp.password = 'sha:ce...刚才复制的那个密文'
c.NotebookApp.open_browser = False
c.NotebookApp.port =8888 #可自行指定一个端口, 访问时使用该端口
c.NotebookApp.terminals_enabled = True #允许开启终端
  • 以上设置完以后就可以在服务器上启动 jupyter notebook, root 用户使用 jupyter notebook --allow-root
  • 打开 IP:指定的端口, 输入密码就可以访问了。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值