Centos7安装python和jupyter

1、首先安装

sqlite-devel

yum install sqlite-devel

2、安装python3 python 3.7.9版本

下载地址 https://www.python.org/downloads/release/python-362/

3.解压安装包

将安装包进行解压

$tar -xzvf Python-3.7.9.tgz

进入目录

$cd Python_3.7.9

添加配置

$./configure --prefix=/usr/local/python3

编译源码

$make

执行安装

$make install

建立python3的软链

$ln -s /usr/local/python3/bin/python3 /usr/bin/python3

将/usr/local/python3/bin加入PATH

$vim ~/.bash_profile

.bash_profile

Get the aliases and functions

if -f \~/.bashrc ; then

. ~/.bashrc

fi

User specific environment and startup programs

PATH=PATH:HOME/bin:/usr/local/python3/bin

export PATH

保存退出:wq

修改完后执行下面的命令,让上一步的修改生效:

$source ~/.bash_profile

4.make对应文件之前,检查开发环境

sudo yum groupinstall "Development Tools"

sudo yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel libffi-devel

创建虚拟环境目录(可以放在任何位置)

python3.7 -m venv ~/venv/jupyter_py37

或者使用指定路径

python3.7 -m venv /path/to/your/jupyter_env

检查是否创建成功

ls -la ~/venv/jupyter_py37/

激活虚拟环境

source ~/venv/jupyter_py37/bin/activate

激活后,命令行提示符会变化,显示虚拟环境名

应该看到类似:(jupyter_py37) user@host \~$

验证虚拟环境中的Python版本

python --version # 应该显示 Python 3.7.9

检查pip版本

pip --version

复制代码
pip3.7 install virtualenv -i https://pypi.tuna.tsinghua.edu.cn/simple

virtualenv venv

source venv/bin/activate

pip3.7 install numpy pandas matplotlib jupyter -i https://pypi.tuna.tsinghua.edu.cn/simple

pip3.7 install opencv-python -i https://pypi.tuna.tsinghua.edu.cn/simple

pip3.7 install notebook==6.5.5 jupyter==1.0.0 -i https://pypi.tuna.tsinghua.edu.cn/simple

解决方案:降级urllib3并配置root安全运行

# 激活虚拟环境

source ~/root/venv/bin/activate

# 降级urllib3和requests到兼容版本
pip uninstall -y urllib3 requests jupyterlab jupyter-server
pip install 'urllib3<2.0' 'requests<3.0' -i https://pypi.tuna.tsinghua.edu.cn/simple

# 安装稳定版本的jupyter notebook(跳过jupyterlab)
pip install notebook==6.5.5 jupyter==1.0.0 -i https://pypi.tuna.tsinghua.edu.cn/simple

2. 验证修复

# 测试urllib3版本
python -c "import urllib3; print('urllib3版本:', urllib3.version)"

# 测试requests
python -c "import requests; print('requests版本:', requests.version)"

# 测试jupyter
python -c "import notebook; print('Notebook版本:', notebook.version)"

方法一:命令行启动(简单)

# 直接启动(带--allow-root参数)
source ~/root/venv/bin/activate
jupyter notebook --allow-root --ip=0.0.0.0 --port=8888 --no-browser

# 或者后台运行
nohup jupyter notebook --allow-root --ip=0.0.0.0 --port=8888 --no-browser > /root/jupyter.log 2>&1 &

# 查看日志
tail -f /root/jupyter.log

##密码问题解决,

jupyter notebook password

如果是虚拟环境,那么先要设置密码,之后再重启,要不然,每次进入juypter,都要验证token。

登录进去,就是如图:

相关推荐
天天进步201520 分钟前
Python全栈项目--协同办公平台
开发语言·python
Doraemomo25 分钟前
Linux编程-标准IO和系统IO
linux·运维·服务器
骇客野人26 分钟前
Linux 查看 Java 进程常用命令
java·linux·运维
睡一觉就好了。32 分钟前
Linux 信号机制
linux·运维·网络
正点原子41 分钟前
【正点原子Linux连载】 第十章 pinctrl和gpio子系统实验 摘自【正点原子】ATK-DLRK3568嵌入式Linux驱动开发指南
linux·运维·驱动开发
GEOshijie1231 小时前
GEO服务商算法适配承诺怎么验收?48小时响应的合同化考核方案
人工智能·python
卷无止境1 小时前
FastAPI 前端托管全攻略:从静态文件到大型全栈项目架构
后端·python
气泡水。1 小时前
RHCSA笔记实记
linux·笔记
波特率1152001 小时前
linux当中的六大进程间通信方式
linux·嵌入式·ipc
RisunJan1 小时前
Linux命令-ssh-keyscan(从主机收集公钥)
linux·ssh