python conda 基本操作

本文详细介绍了conda和pip的基本操作,包括安装、环境管理、依赖安装等。提供了Windows和Linux下的环境配置方法,并介绍了如何利用镜像加速资源下载。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

conda安装及使用

Anaconda 安装地址:(适用于正常使用时)
https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/
Miniconda 安装地址:(更加轻量)
https://docs.anaconda.com/free/miniconda/

win 环境变量:(系统变量path)
F:\Anaconda3
F:\Anaconda3\Library\bin
F:\Anaconda3\Scripts

Linux 环境变量:(.bashrc)
export PATH="/root/anaconda3/bin:$PATH"

conda创建虚拟环境:(envs是一个别名,自己取一个)
conda create -n envs python=3.8
创建完成后目录文件夹会生成在,conda的安装目录envs下边
进入虚拟环境:activate envs
退出虚拟环境:deactivate
删除虚拟环境:conda remove -n envs --all
linux进入拟环境:source activate envs

加速镜像

pip:
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple

conda:
# 编辑C:\Users\Administrator\.condarc 文件,将以下内容替换,或没有的话直接创建
channels:
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
#  - defaults
ssl_verify: true
show_channel_urls: true

pytorch:(快到20MB/S)
pip install torch==2.3.0+cu121 torchvision==0.18.0+cu121 torchaudio==2.3.0+cu121 -f https://mirror.sjtu.edu.cn/pytorch-wheels/torch_stable.html

pip 基础命令使用

使用pip安装包:pip install package_name
使用pip批量安装依赖:pip install -r Requirements.txt
在安装主包时,不安装任何子依赖包:pip install --no-deps package_name

模型下载

pip install huggingface_hub
export HF_ENDPOINT=https://hf-mirror.com

下载单个文件:(https://huggingface.co/Lykon/dreamshaper-xl-lightning/blob/main/DreamShaperXL_Lightning.safetensors)
huggingface-cli download Lykon/dreamshaper-xl-lightning DreamShaperXL_Lightning.safetensors --local-dir /root/DreamShaperXL_Lightning.safetensors

下载整个仓库:(https://huggingface.co/uwg/upscaler)
huggingface-cli download uwg/upscaler --local-dir ./

下载数据集:(https://huggingface.co/datasets/Gourieff/ReActor)
huggingface-cli download --repo-type dataset Gourieff/ReActor  --local-dir ./

civitai.com下载:
wget https://g.blfrp.cn/civitai.com/api/download/models/192916 --content-disposition

pip虚拟环境

pip创建虚拟环境:   # 先关掉杀毒软件,建议使用Anaconda创建虚拟环境
教程:https://www.cnblogs.com/shyern/p/11284127.html
1.安装虚拟环境python包:pip install virtualenv
2.到想要创建虚拟环境的路径下,运行cmd,输入virtualenv envs  (envs为自定义名称)
3.本目录下会生成一个envs文件夹,打开envs文件夹,再打开Scripts文件夹,将activate.bat文件,改为envs和envs.bat(envs为自定义名称),再打开系统变量-path将E:\qian\Scripts添加进去,然后在任意位置打开cmd输入envs,就可以进入创建的虚拟环境
4.输入deactivate,退出虚拟环境
5.若想删除虚拟环境:直接将主文件夹删除即可
如果遇到Cannot uninstall 'filelock'.。。。错误 执行pip install --ignore-installed  filelock,然后再次执行pip install virtualenv命令

argparse配置文件函数

argparse配置文件函数 (基础函数https://docs.python.org/zh-cn/3/library/argparse.html)
开头第一个‘--函数名’,调用的函数名
nargs='*' 设置零个或多个	nargs=' '+' 设置一个或多个		nargs='?' 设置零个或一个
default = ‘填写传入的值’
help = ‘这个选项的帮助信息’

注意!!! 如果有action=DictAction,函数,那么传入的值应该为dist(字典)格式
例如:		"jsonfile_prefix=data/panda_data/panda_patches_results"
应该填写为:{'jsonfile_prefix':'data/panda_data/panda_patches_results'}

注意!!!如果nargs='*',必须要传值时,必须传入多个值
例如:'weights=output/model_final.pdparams'
应该填写为:['weights=output/model_final.pdparams']

注意!!!如果default 未设置,那么默认为False

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值