笔记笔记
  • Home
  • AI&ML
  • Example
  • Zoo
  • 关于
⌘ K
macOS - 返回
常用命令
Shell 软件
iTerm
Homebrew
macOS 制作 U 盘 启动
DNS
系统工具
Python 环境
桌面软件
VMware Fusion
最后更新时间:
Copyright © 2023-2024 | Powered by dumi | GuoDapeng | 冀ICP备20004032号-1 | 冀公网安备 冀公网安备 13024002000293号

TABLE OF CONTENTS

‌
‌
‌
‌

Python 环境

pyenv

简单的 Python 版本管理工具。

pyenv

brew install pyenv

Poetry

依赖项管理和打包的工具。

Poetry

# 安装 poetry
brew install poetry
# 卸载 poetry
brew uninstall poetry
cd ~/Library/Caches
rm -r pypoetry
# 查看配置
poetry config --list
# 设置虚拟环境在项目目录
poetry config virtualenvs.in-project
poetry config virtualenvs.in-project true
# 创建 python3 环境
poetry env use python3
# 激活虚拟环境
source .venv/bin/activate
# 退出虚拟环境
deactivate

poetry shell 命令目前需要安装 poetry-plugin-shell 插件才行。brew 安装的 poetry 不能正常的安装 poetry-plugin-shell。

项目配置

# 创建项目
poetry new StructBERTTrain
# 设置虚拟环境在项目目录
poetry config virtualenvs.in-project true
# 设置镜像源
poetry source add --priority=primary mirrors https://pypi.tuna.tsinghua.edu.cn/simple/
# 查看配置
poetry config --list
# 创建虚拟环境
poetry env use python3
# 创建虚拟环境指定 python 版本
poetry env use ~/.pyenv/versions/3.10.14/bin/python
# 进入虚拟环境
poetry shell
# 安装依赖;新建项目一遍没有依赖
poetry install
# 查看依赖树;新项目也没啥可看的
poetry show --tree

添加依赖

ModelScope

poetry add modelscope
poetry add numpy==1.24.1
poetry add torch torchvision torchaudio
# 如果出现这个错误,说明没有安装 modelscope[nlp]
# ModuleNotFoundError: ZeroShotClassificationPipeline: No module named 'transformers'
pip install "modelscope[nlp]" -f https://modelscope.oss-cn-beijing.aliyuncs.com/releases/repo.html

Hugging Face

poetry add torch torchvision torchaudio
poetry add huggingface_hub 'huggingface_hub[cli,torch]'
poetry add transformers
poetry add accelerate

其他常用包

poetry add fastapi