部署常用指南

https://docs.conda.io/en/latest/miniconda.html#installing

环境配置
安装和配置 Anaconda
安装 Anaconda。
配置镜像源:
yaml

conda配置
vim ~/.condarc


channels:
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/pro/
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r/
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
show_channel_urls: true
channel_alias: https://mirrors.tuna.tsinghua.edu.cn/anaconda
default_channels:
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/pro
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
custom_channels:
  conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  msys2: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  bioconda: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  menpo: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  
创建虚拟环境
创建 Python 3.10 虚拟环境:
conda create --prefix=D:\work2\7.6\713\SalesGPT-main\Python310 python=3.10
激活虚拟环境:
D:\work2\7.6\713\SalesGPT-main\Python310\Scripts\activate
安装 PyTorch 和相关库
安装 PyTorch

https://pytorch.org/get-started/previous-versions/


安装其他库:
pip install einops auto-gptq

使用 Git
克隆 Git 仓库:
git clone [email protected]:huggingface/diffusers.git
使用 Git LFS:
git lfs install
SSH 密钥生成与配置
生成 SSH 密钥:
ssh-keygen -t rsa -b 4096 -C "[email protected]"
将密钥添加到 GitHub。
虚拟环境操作
激活虚拟环境:
source_name\Scripts\activate  # Windows
source_name/bin/activate      # Linux/macOS
查看 Conda 版本:
conda --version
查看 pip 版本:
pip --version
查看虚拟环境列表:
conda info --envs
查看当前虚拟环境中的软件包列表:
conda list
在虚拟环境中安装软件包:
pip install package_name
在虚拟环境中导出依赖项列表:
pip freeze > requirements.txt
退出虚拟环境:
deactivate

Git 使用
提交与同步
git add .
git commit -m "Commit message"
git push origin master
克隆与分支
git clone repository_url
git checkout -b new_branch_name
登录 Hugging Face
transformers-cli login

Nginx 操作
运行 Nginx:
nginx
检查 Nginx 配置:
nginx -t -c E:\app\nginx-1.25.1\conf\nginx.conf
重新加载 Nginx 配置:
nginx -s reload
SSH 密钥和 Git 配置
生成 SSH 密钥:
ssh-keygen -t rsa -b 4096 -C "[email protected]"
将密钥添加到 Git 账户。

配置 Git 用户名和邮箱:
git config --global user.name "Your Name"
git config --global user.email "[email protected]"

文件编辑
使用 Nano 编辑器保存文件:
按下 Ctrl + O 保存。
确认文件名并按下 Enter。
按下 Ctrl + X 退出编辑器。

虚拟环境拷贝
1激活源虚拟环境。
2导出依赖项列表至 requirements.txt。
3创建目标虚拟环境。
4在目标虚拟环境中安装依赖项。

切换工作目录至 FastChat 项目:
cd /hy-tmp/FastChat-main
设置 Hugging Face Hub 缓存路径:
export HUGGINGFACE_HUB_CACHE="/hy-tmp/hy-tmp/"
启动 FastChat 服务,加载模型:
python3 -m fastchat.serve.cli --model-path lmsys/vicuna-13b-v1.5-16k

创建一个名为 "vits" 的新 tmux 会话:
tmux new -s vits
关闭名为 "vits" 的 tmux 会话:
tmux kill-session -t vits

tmux,它是一个终端多路复用工具,允许您在一个终端窗口中同时运行多个终端会话。

步骤 1: 下载 Anaconda 安装脚本

使用 wget 命令从指定链接下载 Anaconda 安装脚本,通过 -c 参数可以断点续传下载。

wget -c https://repo.anaconda.com/archive/Anaconda3-2021.05-Linux-x86_64.sh
步骤 2: 安装 Anaconda

在 Anaconda 安装脚本所在的目录下,运行脚本安装 Anaconda。根据提示,一路回车,直到出现输入 "yes" 的要求时。

bash Anaconda3-2021.05-Linux-x86_64.sh
步骤 3: 配置环境变量

打开 /etc/profile 文件,使用 vim 或其他编辑器进行编辑。

vim /etc/profile
在文件末尾添加环境变量配置,将 Anaconda 的 bin 文件夹路径添加到 PATH 环境变量中。

export PATH=~/anaconda3/bin:$PATH
同样,打开 ~/.bashrc 文件也添加同样的环境变量配置。

vim ~/.bashrc
在文件末尾添加:

export PATH=~/anaconda3/bin:$PATH
最后,刷新环境变量使配置生效。
source /etc/profile
source ~/.bashrc

步骤 1: 配置 pip 镜像

创建 .pip 目录并进入:

mkdir ~/.pip
cd ~/.pip/
使用编辑器(如 vim)创建并编辑 pip.conf 文件:

vim pip.conf
在 pip.conf 文件中配置镜像,将以下内容添加进去:

plaintext
Copy code
[global] 
index-url = http://mirrors.aliyun.com/pypi/simple/ 
[install] 
trusted-host=mirrors.aliyun.com
配置后,pip 将使用阿里云镜像源进行软件包的下载和安装。

步骤 2: 创建和管理虚拟环境

创建虚拟环境(以创建名为 ChatGLM 的虚拟环境为例):

conda create -n ChatGLM python==3.10
初始化 Conda 的 bash 命令(通常只需执行一次):

conda init bash
在新终端窗口中激活虚拟环境(假设虚拟环境名为 ChatGLM):

conda activate ChatGLM
步骤 3: 常用 Conda 命令

创建虚拟环境:

conda create -n name python==3.7
激活虚拟环境:

conda activate name
退出虚拟环境:

conda deactivate
查看虚拟环境列表:

conda info --envs
删除虚拟环境(以删除名为 name 的虚拟环境为例):

conda remove -n name --all
清理 Conda 安装包及缓存(索引缓存、锁定文件、未使用的包和 tar 包):

conda clean -y --all
删除 pip 的缓存:
rm -rf ~/.cache/pip

你可能感兴趣的:(python)