conda创建pytorch1.4环境 及遇到的错误

conda创建pytorch1.4环境

用conda创建新的虚拟环境

conda create -n 新环境名 python=版本号(新环境名自己随便取)

conda create -n pytorch1.4 python=3.7

切换至(激活)新的虚拟环境

conda activate 环境名

conda activate pytorch1.4

如果遇到以下错误

IMPORTANT: You may need to close and restart your shell after running 'conda init'.

直接输入“activate 虚拟环境名”进入虚拟环境,输入“deactivate 虚拟环境名”退出虚拟环境。

source activate pytorch1.4

安装Pytorch1.4稳定版(2020-4-3号官网的稳定版是1.4)

到pytorch官网根据自己的情况进行选择:https://pytorch.org/

conda install pytorch==1.4.0 torchvision==0.5.0 cudatoolkit=10.1 -c pytorch

其中要选conda, CUDA版本的选择会要求电脑英伟达显卡驱动版本必须大于某个值,具体自行查。

查看CUDA版本

cat /usr/local/cuda/version.txt

pytorch官网安装pytorch1.4

将最下面的一行复制下来(末尾的 -c pytorch 不要复制,否则下载的源会默认是pytorch官方源,速度贼慢),我的是:

conda install pytorch torchvision torchaudio cudatoolkit=10.0

发现官网的总出错,决定用清华源安装。

清华源安装pytorch
1.开启清华源重要的是https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/ 这个源一定要添加进去,然后才能正常安装pytorch。

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/ 
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/ 
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/ 
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/peterjc123/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
conda config --set show_channel_urls yes

2.安装GPU版的如下. 我的cuda版本是10.0

conda install pytorch torchvision cudatoolkit=10.0 # -c pytorch 这个要去掉

验证
在(pytorch1.4) C:\Users\29530>后输入:python 回车 进入python环境,而后再输入import torch回车无异常表示pytorch安装成功, 然后输入: torch.cuda.is_available(),若返回 true,表示该pytorch可以使用GPU。
查看pytorch版本

torch.__version__

退出环境
输入:conda deactivate

其它
删除环境(不要乱删,这里只是说怎么做):
conda remove -n 环境名
删除清华源并切换回原版源(不要乱删,这里只是说怎么做):
conda config --remove-key channels

安装cv2

pip install opencv-python 

libGL.so.1: cannot open shared object file 的错误

新容器缺少依赖,安装一下就行了

apt update
apt install libgl1-mesa-glx

No module named 'imageio'错误

pip install imageio

No module named 'skimage'错误
意思是没有这个模块,在Linux服务器上需要先联网,联网之后使用命令

pip install scikit-image

等待下载安装完成即可

运行报No module named 'skimage.measure.simple_metrics'错误
说明这个给路径里缺少simple_metrics.py这个文件,直接复制一个过去即可,也可以复制下边的代码写一个新的。

from warnings import warn
from ..metrics.simple_metrics import (mean_squared_error,
                                       peak_signal_noise_ratio,
                                       normalized_root_mse)

__all__ = ['compare_mse',
           'compare_nrmse',
           'compare_psnr',
           ]


def compare_mse(im1, im2):
    warn('DEPRECATED: skimage.measure.compare_mse has been moved to '
         'skimage.metrics.mean_squared_error. It will be removed from '
         'skimage.measure in version 0.18.', stacklevel=2)
    return mean_squared_error(im1, im2)


if mean_squared_error.__doc__ is not None:
    compare_mse.__doc__ = mean_squared_error.__doc__ + """
    Warns
    -----
    Deprecated:
        .. versionadded:: 0.16

        This function is deprecated and will be removed in scikit-image 0.18.
        Please use the function named ``mean_squared_error`` from the
        ``metrics`` module instead.

    See also
    --------
    skimage.metrics.mean_squared_error
    """


def compare_nrmse(im_true, im_test, norm_type='euclidean'):
    warn('DEPRECATED: skimage.measure.compare_nrmse has been moved to '
         'skimage.metrics.normalized_root_mse. It will be removed from '
         'skimage.measure in version 0.18.', stacklevel=2)
    return normalized_root_mse(im_true, im_test, normalization=norm_type)


if normalized_root_mse.__doc__ is not None:
    compare_nrmse.__doc__ = normalized_root_mse.__doc__ + """
    Warns
    -----
    Deprecated:
        .. versionadded:: 0.16

        This function is deprecated and will be removed in scikit-image 0.18.
        Please use the function named ``normalized_root_mse`` from the
        ``metrics`` module instead.

    See also
    --------
    skimage.metrics.normalized_root_mse
    """


def compare_psnr(im_true, im_test, data_range=None):
    warn('DEPRECATED: skimage.measure.compare_psnr has been moved to '
         'skimage.metrics.peak_signal_noise_ratio. It will be removed from '
         'skimage.measure in version 0.18.', stacklevel=2)
    return peak_signal_noise_ratio(im_true, im_test, data_range=data_range)


if peak_signal_noise_ratio.__doc__ is not None:
    compare_psnr.__doc__ = peak_signal_noise_ratio.__doc__ + """
    Warns
    -----
    Deprecated:
        .. versionadded:: 0.16

        This function is deprecated and will be removed in scikit-image 0.18.
        Please use the function named ``peak_signal_noise_ratio`` from the
        ``metrics`` module instead.

    See also
    --------
    skimage.metrics.peak_signal_noise_ratio
    """

No module named 'tqdm'错误
直接

pip install tqdm

你可能感兴趣的:(pytorch,python,cuda,深度学习,pytorch,机器学习)