conda 进入虚拟环境:
conda install pytorch torchvision cudatoolkit=10.2 -c pytorch
1.问题描述:conda无法创建虚拟环境并且无法安装其他第三方包,报错内容如下:
2.错误原因:默认镜像源访问速度过慢,会导致超时从而导致更新和下载失败。
3.解决方案一、更换镜像源为清华镜像源,并且删除默认镜像源。
解决方案二、不正常国内访问途径
其他可能的问题: 方案一和方案二可能会冲突,如果换了源需要换回正常访问途径再执行。
需要关闭,再使用方案一。
不正常国内访问途径先关闭,换源后,命令行去掉最后两个参数
conda install pytorch torchvision cudatoolkit=10.2
但执行之后选了yes,出现新错误:
在这里插入代码片
# >>>>>>>>>>>>>>>>>>>>>> ERROR REPORT <<<<<<<<<<<<<<<<<<<<<<
Traceback (most recent call last):
File "/opt/anaconda3/lib/python3.7/site-packages/conda/exceptions.py", line 819, in __call__
return func(*args, **kwargs)
File "/opt/anaconda3/lib/python3.7/site-packages/conda/cli/main.py", line 78, in _main
exit_code = do_call(args, p)
File "/opt/anaconda3/lib/python3.7/site-packages/conda/cli/conda_argparse.py", line 77, in do_call
exit_code = getattr(module, func_name)(args, parser)
File "/opt/anaconda3/lib/python3.7/site-packages/conda/cli/main_install.py", line 11, in execute
install(args, parser, 'install')
File "/opt/anaconda3/lib/python3.7/site-packages/conda/cli/install.py", line 253, in install
handle_txn(unlink_link_transaction, prefix, args, newenv)
File "/opt/anaconda3/lib/python3.7/site-packages/conda/cli/install.py", line 282, in handle_txn
unlink_link_transaction.execute()
File "/opt/anaconda3/lib/python3.7/site-packages/conda/core/link.py", line 223, in execute
self.verify()
File "/opt/anaconda3/lib/python3.7/site-packages/conda/common/io.py", line 46, in decorated
return f(*args, **kwds)
File "/opt/anaconda3/lib/python3.7/site-packages/conda/core/link.py", line 200, in verify
self.prepare()
File "/opt/anaconda3/lib/python3.7/site-packages/conda/core/link.py", line 192, in prepare
stp.remove_specs, stp.update_specs)
File "/opt/anaconda3/lib/python3.7/site-packages/conda/core/link.py", line 282, in _prepare
mkdir_p(transaction_context['temp_dir'])
File "/opt/anaconda3/lib/python3.7/site-packages/conda/gateways/disk/__init__.py", line 60, in mkdir_p
makedirs(path)
File "/opt/anaconda3/lib/python3.7/os.py", line 221, in makedirs
mkdir(name, mode)
PermissionError: [Errno 13] Permission denied: '/opt/anaconda3/.condatmp'
`$ /opt/anaconda3/bin/conda install pytorch torchvision cudatoolkit=10.2`
environment variables:
CIO_TEST=
CONDA_DEFAULT_ENV=base
CONDA_EXE=/opt/anaconda3/bin/conda
CONDA_PREFIX=/opt/anaconda3
CONDA_PROMPT_MODIFIER=
CONDA_PYTHON_EXE=/opt/anaconda3/bin/python
CONDA_ROOT=/opt/anaconda3
CONDA_SHLVL=1
DEFAULTS_PATH=/usr/share/gconf/ubuntu.default.path
LD_LIBRARY_PATH=/usr/local/cuda-10.0/lib64
MANDATORY_PATH=/usr/share/gconf/ubuntu.mandatory.path
PATH=/usr/local/cuda-10.2/bin:/opt/anaconda3/bin:/home/yuuzh/bin:/home/yuuz
h/.local/bin:/usr/local/cuda/bin:/usr/local/sbin:/usr/local/bin:/usr/s
bin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin}
REQUESTS_CA_BUNDLE=
SSL_CERT_FILE=
XDG_SEAT_PATH=/org/freedesktop/DisplayManager/Seat0
XDG_SESSION_PATH=/org/freedesktop/DisplayManager/Session0
active environment : base
active env location : /opt/anaconda3
shell level : 1
user config file : /home/yuuzh/.condarc
populated config files : /home/yuuzh/.condarc
conda version : 4.5.11
conda-build version : 3.15.1
python version : 3.7.0.final.0
base environment : /opt/anaconda3 (read only)
channel URLs : https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/linux-64
https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/noarch
https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/linux-64
https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/noarch
https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/linux-64
https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/noarch
https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/linux-64
https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/noarch
package cache : /opt/anaconda3/pkgs
/home/yuuzh/.conda/pkgs
envs directories : /home/yuuzh/.conda/envs
/opt/anaconda3/envs
platform : linux-64
user-agent : conda/4.5.11 requests/2.19.1 CPython/3.7.0 Linux/4.15.0-106-generic ubuntu/16.04 glibc/2.23
UID:GID : 1000:1000
netrc file : None
offline mode : False
An unexpected error has occurred. Conda has prepared the above report.
If submitted, this report will be used by core maintainers to improve
future releases of conda.
Would you like conda to send this report to the core maintainers?
[y/N]: y
Upload successful.
Thank you for helping to improve conda.
Opt-in to always sending reports (and not see this message again)
by running
$ conda config --set report_errors true
原因:
原因是软件没有权限进行创建设置的,所以这里推荐的手动创建设置,以下是设置方法
conda常用的命令。
1)conda list 查看安装了哪些包。
2)conda env list 或 conda info -e 查看当前存在哪些虚拟环境
3)conda update conda 检查更新当前conda
1、先创建虚拟环境
conda create -n your_env_name python=X.X(2.7、3.6等)
2、创建成功,后激活环境
# To activate this environment, use
#
# $ conda activate pytorch-env
#
# To deactivate an active environment, use
#
# $ conda deactivate
对虚拟环境中安装额外的包。
使用命令conda install -n your_env_name [package]即可安装package到your_env_name中
关闭虚拟环境(即从当前环境退出返回使用PATH环境中的默认python版本)。
使用如下命令即可。
Linux: source deactivate
Windows: deactivate
删除虚拟环境。
使用命令conda remove -n your_env_name(虚拟环境名称) --all, 即可删除。
删除环境中的某个包。
使用命令conda remove --name your_env_name package_name 即可。
激活虚拟环境后再执行上述报错命令:
conda install pytorch torchvision cudatoolkit=10.2
最后执行结果如下
最后,验证 torch 是否安装成功:
验证pytorch是否安装成功(linux)
要显示显卡信息,在终端输入:
sudo lshw -c video
要显示CUDA信息,在终端输入:
nvcc -V
查看Phthon版本,在终端输入:
python --version
验证pytorch是否安装成功,在终端进入python环境
此时进入python环境。
然后,继续输入
import torch
import torchvision
不报错就表明安装成功。
记住,一定要进入 conda 的虚拟环境哦。