文章目录
1、安装python3.9.13
1.1、安装依赖
yum install -y zlib-devel bzip2-devel libffi-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make
yum install libffi-devel -y
1.2、下载python源码包
wget https://www.python.org/ftp/python/3.9.13/Python-3.9.13.tgz
tar -zxvf Python-3.9.13.tgz
cd Python-3.9.13
./configure --prefix=/usr/local/python39
make&&make install
建立命令软链接
先查看python2和python3安装在哪
which python
which python3
ln -s /usr/local/python39/bin/python3 /usr/bin/python3
ln -s /usr/local/python39/bin/pip3 /usr/bin/pip3
查看版本号
python3 -V
2、安装pip
如果安装的python不带pip,可以通过以下命令安装
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py #下载安装脚本
python get-pip.py #运行安装脚本
2.1、更新pip
python.exe -m pip install --upgrade pip
2.2、pip可用的包安装源
如果觉得国外源慢,可以使用以下国内源
#阿里云
https://mirrors.aliyun.com/pypi/simple/
#中国科技大学
https://pypi.mirrors.ustc.edu.cn/simple/
#豆瓣(douban)
https://pypi.douban.com/simple/
#清华大学
https://pypi.tuna.tsinghua.edu.cn/simple/
#中国科学技术大学
https://pypi.mirrors.ustc.edu.cn/simple/
2.3、查看版本号
pip -V
2.4、安装模块
pip install package
# 指定版本和更新源安装
pip install -i https://mirrors.aliyun.com/pypi/simple/ numpy==1.23.2
2.5、列出已安装的包
pip list
2.6、卸载模块
pip uninstall package
2.7、显示指定安装包的信息
pip show package
2.8、检查包是否有更新
pip list --outdated
2.9、更新指定的包
pip install --upgrade package
2.10、更新所有包
pip-review --local --interactive
2.11、批量安装requirements.txt
通requirements.txt批量安装
为项目生成依赖包配置文件requirements.txt
pip freeze > requirements.txt
根据requirements.txt批量安装依赖包
pip install -r requirements.txt
3、安装conda
官网下载:https://www.anaconda.com/download/
清华镜像:https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/
3.1、创建环境
# 创建一个新的环境:
conda create -n python310 python=3.10
3.2、管理环境
## 激活环境:
conda activate python310
# 退出环境:
conda deactivate
# 列出所有环境:
conda env list
# 删除环境:
conda env remove --name python310
3.3、管理包
# 安装包:
conda install 包名
#安装特定版本的包:
conda install 包名=版本号
#升级包:
conda update 包名
#卸载包:
conda remove 包名
#搜索包:
conda search 包名
#搜索版本处于1.0.0及1.1之间的pandas
conda search "pandas [version='>=1.0.0,<1.1']"
3.4、管理包环境
# 导出环境到文件:
conda env export > 环境文件.yml
# 从环境文件创建环境:
conda env create -f 环境文件.yml
#克隆环境:
conda create --clone 源环境名称 --name 新环境名称
3.5、其他常用命令
#显示已安装的包列表:
conda list
# 显示包的详细信息:
conda info 包名
# 显示conda的版本信息:
conda --version
# 显示conda的帮助信息:
conda --help
3.6、conda下添加国内镜像源
# 1.配置清华镜像源
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
#设置搜索时显示通道地址
conda config --set show_channel_urls yes
# 2.配置中科大镜像源
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/msys2/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/bioconda/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/menpo/
# 3、配置上海交通大学镜像源
conda config --add channels https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.sjtug.sjtu.edu.cn/anaconda/cloud/conda-forge/
# 显示添加的镜像源
conda config --show channels