从Conda到Miniconda的pip包迁移
从AnoConda到MiniConda的pip包迁移
用了一段时间才知道,AnoConda不是经常都要用的,对于我这样的新手来说,从开始菜单启动Prompt,以及直接在pycharm中选择配好的环境,就足够了。
早期在anoconda中做了一个base的完整复制:
conda creat --name pycharm3 --clone base
(不知啥原因,在navigater中不能clone,只能在命令行中实现)
而且通过pip安装了pytorch,以及其他一些东西
在Pycharm中,解释器中的包很多
今天新装了miniconda,并复制了一个 名叫torch3的环境
以下操作实现对pip包的迁移
1)在conda的pycharm3环境中,使用
pip freeze > torch3.txt
2)在笔记本中编辑txt文件,删除不想要的包
大概是这样子
segyio1.9.1
spyder3.3.1
spyder-kernels0.2.6
sympy1.1.1
torch1.6.0
torchvision0.7.0
3)在miniconda的torch3环境中,使用
pip install -r torch3.txt
这样就把大环境中的包确定下来,然后通过网络重装了。
4)多数都可以重装,但发现 torch装不上。
于是在pytorch官网找到标准方法:
pip install torch=1.6.0 torchvision=0.7.0 -f https://download.pytorch.org/whl/torch_stable.html
执行命令后提示如下:
C:\Users\XXX>pip install torch=1.6.0 torchvision=0.7.0 -f https://download.pytorch.org/whl/torch_stable.html
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Looking in links: https://download.pytorch.org/whl/torch_stable.html
Collecting torch===1.6.0
Downloading https://download.pytorch.org/whl/cu102/torch-1.6.0-cp38-cp38-win_amd64.whl (1077.4 MB)
开始下载……
5)考虑到可能要重用,这次直接在浏览器中下载上面的链接的whl
https://download.pytorch.org/whl/cu102/torch-1.6.0-cp38-cp38-win_amd64.whl
下载完,用 pip install -f .\torch-1.6.0-cp38-cp38-win_amd64.whl安装 这个最大的 whl
(报错了,但是装上了,后来查可以用
pip install --no-index -f=<目录>/ <包名>)
6)然后再次运行 pip install torch=1.6.0 torchvision=0.7.0 -f https://download.pytorch.org/whl/torch_stable.html
软件会自动下载并安装其他小的包。
7)然后到pycharm中切换到miniconda中的环境。这时解释器中的包就少多了。
再试试 import torch,没问题!
(end)