一.Linux安装python
1.版本检查
Linux中一般都安装了python,但是版本一般都很旧,可以这样查看版本
python --version #或者 python3 --version
2.安装依赖
假如不是管理员用户,记得加上sudo获取权限
yum groupinstall "Development Tools"
这条命令安装 "Development Tools" 软件包组,它包含编译 Python 和其他软件所需的基础开发工具,
目的就是为了确保系统具备编译 Python 源码的基本环境。
yum install gcc openssl-devel bzip2-devel libffi-devel zlib-devel#可能不全
这条命令是下载python运行编译需要的额外的库,确保关键程序不会出差错
如果下面报错,再执行一下这个:
sudo yum install zlib-devel bzip2-devel openssl-devel ncurses-devel \ sqlite-devel readline-devel tk-devel libffi-devel xz-devel
还有这个:
make clean#清理之前的编译文件 ./configure --prefix=/usr/local --enable-shared # 不加 --enable-optimizations make -j$(nproc)#调用开始编译 sudo make altinstall#安装
3.安装python源码
wget https://www.python.org/ftp/python/3.9.7/Python-3.9.7.tgz
注意:没有wget需要用yum先下载工具S
可能下载缓慢,可以使用国内镜像下载(我用阿里镜像)
wget https://mirrors.aliyun.com/python/3.9.7/Python-3.9.7.tgz
4.解压文件安装
解压文件:
tar -xf Python-3.9.7.tgz
进入文件:
cd Python-3.9.7
为 Python 解释器启用优化选项,从而提高运行性能:
./configure --enable-optimizations
设置核心数量:
make -j 2 #根据自己虚拟机的核心数量
安装(alinstall可以避免覆盖原本有的版本):
sudo make altinstall
验证安装:
python3.9 --version
最后设置一下默认版本:
sudo update-alternatives --install /usr/bin/python python /usr/local/bin/python3.9 1 sudo update-alternatives --config python
至此python安装完成!
二.Linux安装anaconda
anaconda下载指令,访问Anaconda官网(Download Anaconda Distribution | Anaconda)获取最新Linux安装脚本链接:
这里先切换到opt目录中以免错误
wget https://repo.anaconda.com/archive/Anaconda3-2021.05-Linux-x86_64.sh
检验脚本完整性:
sha256sum Anaconda3-2021.05-Linux-x86_64.sh
注意:输出应该与官网提供的SHA256对比,确保完整性
运行安装脚本:
bash Anaconda3-2021.05-Linux-x86_64.sh
注意安装路径!
激活安装:
source ~/.bashrc
验证安装:
conda --version python --version
!!!!不顺利再看这里
——
如果没有jupyter lab安装:
pip install jupyterlab -i https://mirrors.aliyun.com/pypi/simple/
在base环境下可能由于环境太乱,不能启用jupyter lab,需要创建一个新环境来运行jupter lab
conda create -n jupyter_env python=3.10 jupyterlab -c conda-forge conda activate jupyter_env jupyter lab --version#查看是否可以使用
第一次使用,用--allow-root启用(不建议一直用这个,有安全风险,新建一个用户)
jupyter lab --allow-root
——
三.连接本地pycharm
1.启用服务会有端口号一般为8888:
jupyter lab --allow-root
2.注意:一定要开放端口(防火墙)
查看防火墙状态是否running:
sudo systemctl status firewalld
检查端口是否放行以下可以查看那些是放行了的:
sudo firewall-cmd --list-ports | grep 8888
如果没有jupyter的端口放行那么就要执行放行:
sudo firewall-cmd --add-port=8888/tcp --permanent
然后重新加载防火墙:
sudo firewall-cmd --reload
再执行上面的代码,查看是否放行:
sudo firewall-cmd --list-ports | grep 8888
3.测试
在自己电脑浏览器先测试假如jupyter lab运行完成会有地址出现例如这样,找到自己的地址:
To access the server, open this file in a browser: file:///root/.local/share/jupyter/runtime/jpserver-102053-open.html Or copy and paste one of these URLs: http://localhost.localdomain:8888/lab?token=c17e39461663b708ecec8629c3d1a95f7ed9fa2ddcb2250d http://127.0.0.1:8888/lab?token=c17e39461663b708ecec8629c3d1a95f7ed9fa2ddcb2250d
其中将localhost.localdomain替换为自己的ip,例如这样:
http://192.168.75.128:8888/lab?token=c17e39461663b708ecec8629c3d1a95f7ed9fa2ddcb2250d
复制这网址到浏览器测试:
说明没有问题了
将上面的http复制,打开pycharm创建一个文件打开setting——>搜索——>jupyter Server——>configerd server 粘贴上去——>apply
就成功的连接好了,恭喜你又迈出一步!