linux环境
docker run -itd --privileged --name jupyter -h jupyter --net=host -v /tmp:/tmp cent7 bash docker exec -it jupyter bash [root@ai1 ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE cent7 latest 5e7dd7f9819a 5 weeks ago 589MB cent7环境是一个非常基础的centos7环境,只有600M 在这上面安装成功后,基本所有linux都可以安装成功
jupyter的python环境
jupyter 可以看作python环境下的一个依赖包,所以jupyter依存于python环境 python可以单独安装,即安装一个python软件,再pip install jupyter 或者 安装 anaconda3 anaconda3中自带python环境+各种常见python依赖包,其中就有jupyter jupyter的安装是比如认目录路径的, 即安装后以后,不能再改变这个目录了,安装时动态生成了一些文件,这些文件中写死了安装时的目录
python安装依赖问题
jupyter依赖于python环境,那么就需要先安装python环境, 在linux上,python环境依赖一些linux的库,所以要提前安装一些rpm包 anaconda3对于这一点做了优化,或者说它将一系列相关依赖打包好了,目的在于方便安装python环境
linux依赖包
yum install -y net-tools libaio numactl 如果为linux系统,则 安装如下依赖包,也可以先不安装,系统提示缺少相关依赖包里,再回来安装 yum install gcc-c++ python-devel.x86_64 cyrus-sasl-devel.x86_64
rpm离线安装
rpm -qa | grep python-devel rpm -qa | grep cyrus-sasl-devel yum search python-devel yum search cyrus-sasl-devel mkdir -p /opt/jupyter/rpm yum install --downloadonly --downloaddir=/opt/jupyter/rpm python-devel.x86_64 yum install --downloadonly --downloaddir=/opt/jupyter/rpm cyrus-sasl-devel.x86_64 rpm -Uvh --force --nodeps *.rpm
Anacodna3 linux版下载
到https://www.anaconda.com/下载及安装 https://repo.anaconda.com/archive/Anaconda3-2022.10-Linux-x86_64.sh https://repo.anaconda.com/archive/Anaconda3-2023.03-1-Linux-x86_64.sh https://repo.anaconda.com/archive/Anaconda3-2024.02-1-Linux-x86_64.sh Anaconda3-2022.10-Linux-x86_64.sh,对应Python3.9.13,本次选择这个版本
Anacodna3 linux 安装
jupyter可以,也不推荐使用root用户,所以新建一个普通用户 [root@jupyter /]# mkdir -p /ai/app [root@jupyter /]# useradd xt [root@jupyter /]# chown -R xt.xt /ai/ [root@jupyter /]# su - xt [xt@jupyter ~]$ sh /tmp/Anaconda3-2022.10-Linux-x86_64.sh [/home/xt/anaconda3] >>> /ai/app/anaconda3 PREFIX=/ai/app/anaconda3 installation finished. Do you wish the installer to initialize Anaconda3 by running conda init? [yes|no] [no] >>> yes
进入默认的base环境
[xt@jupyter ~]$ exit logout [root@jupyter /]# su - xt (base) [xt@jupyter ~]$ 退出当前shell后,再次进入就可以看到base 如果不使用/没有创建base环境,就需要配置一下环境变量
配置环境变量
export PATH=/ai/app/anaconda3/bin:$PATH
查看Jupyter
(base) [xt@jupyter ~]$ which jupyter /ai/app/anaconda3/bin/jupyter
安装jupyter
conda自带有jupyter, python则执行以下命令 pip install jupyter
配置python环境变量,告诉jupyter python库目录在哪 PATHHONPATH=/ai/app/anaconda3/lib/python3.9/site-packages
jupyter远程配置
配置python环境变量,告诉jupyter python库目录在哪 PATHHONPATH=/ai/app/anaconda3/lib/python3.9/site-packages jupyter notebook password #设置 jupyter 的密码 jupyter notebook --generate-config #生成自己配置文件,目录在 ~/.jupyter/jupyter_notebook_config.py 示例 jupyter notebook password book_1234 $ jupyter notebook --generate-config vim ~/.jupyter/jupyter_notebook_config.py c.NotebookApp.ip='*' c.NotebookApp.open_browser=False c.NotebookApp.port=8888
启动 jupyter notebook jupyter notebook --ip 0.0.0.0 jupyter notebook --ip 0.0.0.0 --allow-root 访问 http://ip:8888/ 虚拟机中有多个IP,且上面的方式访问不通时,可关闭防火墙 centos7关闭防火墙(ubantu没有防火墙问题,所以不需要你去关) systemctl status firewalld systemctl stop firewalld systemctl disable firewalld 也可能是虚拟机与主机共享了IP所致,可尝试 http://localhost:8888/
工作空间
任意建一个目录,在该目录下启动,这个目录就是工作空间了 本实验是安装在docker中的,docker通常放软件不放数据,工作空间属于数据,通常外挂,这里使用网络挂载 这里挂载的是windows共享目录 (base) [xt@jupyter ~]$ mkdir wks mount -t cifs -o username=Administrator,password=******,vers=3.0,dir_mode=0777,file_mode=0777,gid=1000,uid=1000 //192.168.56.1/jupyter /home/xt/wks cd wks (base) [xt@jupyter wks]$ jupyter notebook http://192.168.56.104:8888/
使用软件
全程只使用了anaconad3这个软件,并且是在一个600M左右的简易linux上安装的(意味着这个linux缺少各种依赖包) 经实践验证,anaconad3解决了python环境依赖问题 在linux上使用Python安装,linux依赖包这一步是跳不过去的
保存
只有配置文件不在/ai/app/anaconda3目录下,但它可重新生成, 所以只要打包这个目录就是一个解压即用的conda环境 vim /ai/app/anaconda3/readme.txt v1: Anaconda3-2022.10-Linux-x86_64.sh,Python3.9.13 install dir: /ai/app/anaconda3 (base) [xt@jupyter wks]$ cd /ai/app/ (base) [xt@jupyter app]$ tar -zcvf anaconda_v1.tar.gz anaconda3/
加载验证
功能
访问oracle/mysql pandas数据分析
linux 依赖包
python访问mysql不需要linux依赖包 python访问oracle需要一个oracle客户端,oracle客户端高版本可兼容访问低版本,所以你尽管/尽量下载高版本的 这个依赖不依赖任何其他rpm包 rpm -ivh oracle-instantclient-basic-21.8.0.0.0-1.x86_64.rpm
python依赖包
pip install pandas pip install chinese_calendar pip install matplotlib pip install pydotplus pip install requests pip install Flask pip install gevent pip install Flask-APScheduler pip install cx_Oracle pip install pymysql==1.0.2 pip install sqlalchemy 其中连接oracle还需要一个oracle客户端 # rpm -qa |grep oracle oracle-instantclient-basic-21.8.0.0.0-1.x86_64
连接测试
tpf.db_test.py中记录了连接oracle与mysql的测试方法 先设置连接配置,然后连接测试 经测试,该环境可以连接oracle与mysql
保存文件
conda_v2.tar.gz
将已有的jupyter环境,从一台服务器迁移到另外一台服务器
原系统: centos 7 ,gcc 4.8.5 新系统:麒麟,gcc 7.3.0 注意事项:目录不变
jupyter notebook password #设置 jupyter 的密码 jupyter notebook --generate-config #生成自己配置文件,目录在 ~/.jupyter/jupyter_notebook_config.py
--config=Full path of a config file. Default: '' Equivalent to: [--JupyterApp.config_file] --ip= The IP address the notebook server will listen on. Default: 'localhost' Equivalent to: [--NotebookApp.ip] --port= The port the notebook server will listen on (env: JUPYTER_PORT). Default: 8888 Equivalent to: [--NotebookApp.port]
## The password for HTTP authentication. (JUPYTER_GATEWAY_HTTP_PWD env var) # Default: None # c.GatewayClient.http_pwd = None cd ~/.jupyter/ cp jupyter_notebook_config.py jupyter_config_yewu.py vim jupyter_config_yewu.py c.NotebookApp.ip='*' c.NotebookApp.open_browser=False c.NotebookApp.port=8009 指定端口启动 jupyter notebook --port=8009 端口可以写在默认的配置文件中,配置文件默认放在用户下, 指定端口的目的在于想再起一套jupyter,以与第一套jupyter进行区分, 除了使用配置文件进行分区外,还可以创建一个用户进行分区
因此,若要在一台机器上安装多套jupyter,那么使用多个用户分隔环境即可