No module named “Torch”

前端 未结 13 915
慢半拍i
慢半拍i 2021-01-04 01:41

I installed pytorch via

conda install pytorch-cpu torchvision-cpu -c pytorch

And I also tried

pip3 install https://download.pytorch         


        
相关标签:
13条回答
  • 2021-01-04 02:08

    Welcome to SO,

    please create a seperate conda environment

    activate this environment conda activate myenv and than install pytorch in it.

    Besides you can check which python you are currently using by which python

    0 讨论(0)
  • 2021-01-04 02:09

    Usually if the torch/tensorflow has been successfully installed, you still cannot import those libraries, the reason is that the python environment you try to import is not the python environment you installed.

    For example, if you have installed the torch/tensorflow using python='/usr/bin/python', then you cannot import them to python='/home/usrname/.../bin/python'.

    The solution is simple thus, just change the python and import again.

    0 讨论(0)
  • 2021-01-04 02:13

    Switch to python3 on the notebook

    0 讨论(0)
  • 2021-01-04 02:16

    Try to install PyTorch using pip:

    First create a Conda environment using:

    conda create -n env_pytorch python=3.6
    

    Activate the environment using:

    conda activate env_pytorch
    

    Now install PyTorch using pip:

    pip install torchvision 
    

    Note: This will install both torch and torchvision.

    Now go to Python shell and import using the command:

    import torch
    import torchvision
    
    0 讨论(0)
  • 2021-01-04 02:16

    Once after creating conda environment, activate it.

    And to install PyTorch,

    conda install -c pytorch pytorch
    
    0 讨论(0)
  • 2021-01-04 02:18

    If you are using windows and you have no CUDA, then go with the following command.

    pip install torch==1.7.0+cpu torchvision==0.8.1+cpu torchaudio===0.7.0 -f https://download.pytorch.org/whl/torch_stable.html
    

    You can visit its official site for more explanation. Pytorch Official site

    0 讨论(0)
提交回复
热议问题