pycharm创建虚拟环境(傻瓜式、超简单)

本文介绍了虚拟环境的安装方法,包括手动安装、通过requirements.txt和requirements.yml文件安装,并提供了删除虚拟环境的步骤。还讨论了如何测试环境是否成功创建以及在安装过程中遇到下载速度慢的问题,给出了修改conda配置和pip源以加速下载的解决方案。

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

1.安装虚拟环境的三种方式

1.1手动安装

打开pycharm-》terminal

pycharm-》terminal输入

conda create -n py37 python=3.7

python激活

conda activate py37


transformers安装

pip install transformers

torch-gpu安装 

方法1

pip3 install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu113

方法2

pip install torch==1.9.0+cu111 torchvision==0.10.0+cu111 torchaudio==0.9.0 -f https://download.pytorch.org/whl/torch_stable.html
pip install torch==1.9.0+cu111 torchvision==0.10.0+cu111 torchaudio==0.9.0 -f https://download.pytorch.org/whl/torch_stable.html -i https://pypi.tuna.tsinghua.edu.cn/simple

1.2基于requirements.txt安装

pip install -r requirements.txt

按照requirements.txt安装

pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple 

1.3基于requirements.yml安装

安装 代码 

conda env create -f requirements.yml

保存本地环境为yml文件代码

conda env export > requirements.yml

1.4测试环境

import torch
torch.cuda.is_available()

2.删除虚拟环境代码

 确保已经退出当前环境

conda deactivate 

 查看当前存在的所有虚拟环境

conda env list 

删除指定名称的虚拟环境

conda env remove -n py37

3.查看虚拟环境

conda info --envs

4.下载太慢

解决使用conda env create -f environment.yml安装依赖包时Installing pip dependencies过慢的问题_installing pip dependencies 卡住_NOVAglow646的博客-优快云博客

修改channels为下面方式

channels:
  - conda-forge
  - 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

并在pip的依赖包里添加上镜像源(加上最后一行)。

-i https://pypi.tuna.tsinghua.edu.cn/simple

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值