skip to Main Content

Hello everyone please help me I have problem with import Torch, I have been tried everything what chat gpt told me. Creating new env and virtual env with python 3.9 and other versions.
Updated pip, conda, libmamba, github. I already don’t know what to do. Please someone help me. One week I can not solve it.

(myenv) ______ ~ % conda install pytorch::pytorch torchvision torchaudio -c pytorch
Collecting package metadata (current_repodata.json): | WARNING conda.models.version:get_matcher(556): Using .* with relational operator is superfluous and deprecated and will be removed in a future version of conda. Your spec was 1.7.1.*, but conda is ignoring the .* and treating it as 1.7.1
done
Solving environment: done

## Package Plan

environment location: /Users/____/anaconda3/envs/myenv

added / updated specs:
- pytorch::pytorch
- torchaudio
- torchvision

The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    gmpy2-2.1.2                |   py39h2da61ea_1         166 KB  conda-forge
    markupsafe-2.1.3           |   py39hdc70f33_1          22 KB  conda-forge
    mkl-service-2.4.0          |   py39h6c40b1e_1          44 KB
    mkl_fft-1.3.8              |   py39h6c40b1e_0         195 KB
    mkl_random-1.2.4           |   py39ha357a0b_0         271 KB
    numpy-1.26.0               |   py39h827a554_0          11 KB
    numpy-base-1.26.0          |   py39ha186be2_0         6.7 MB
    pillow-10.1.0              |   py39hdd30358_0        44.2 MB  conda-forge
    pytorch-2.1.0              |          py3.9_0        84.0 MB  pytorch
    pyyaml-6.0.1               |   py39hdc70f33_1         159 KB  conda-forge
    torchaudio-2.1.0           |         py39_cpu         4.7 MB  pytorch
    torchvision-0.16.0         |         py39_cpu         6.6 MB  pytorch
    ------------------------------------------------------------
                                           Total:       147.0 MB

The following NEW packages will be INSTALLED:

aom                conda-forge/osx-64::aom-3.6.1-he965462_0
blas               pkgs/main/osx-64::blas-1.0-mkl
cairo              conda-forge/osx-64::cairo-1.18.0-h99e66fa_0
dav1d              conda-forge/osx-64::dav1d-1.2.1-h0dc2134_0
expat              conda-forge/osx-64::expat-2.5.0-hf0c8a7f_1
ffmpeg             conda-forge/osx-64::ffmpeg-6.0.0-gpl_h789aacd_105
filelock           conda-forge/noarch::filelock-3.12.4-pyhd8ed1ab_0
font-ttf-dejavu-s~ conda-forge/noarch::font-ttf-dejavu-sans-mono-2.37-hab24e00_0
font-ttf-inconsol~ conda-forge/noarch::font-ttf-inconsolata-3.000-h77eed37_0
font-ttf-source-c~ conda-forge/noarch::font-ttf-source-code-pro-2.038-h77eed37_0
font-ttf-ubuntu    conda-forge/noarch::font-ttf-ubuntu-0.83-hab24e00_0
fontconfig         conda-forge/osx-64::fontconfig-2.14.2-h5bb23bf_0
fonts-conda-ecosy~ conda-forge/noarch::fonts-conda-ecosystem-1-0
fonts-conda-forge  conda-forge/noarch::fonts-conda-forge-1-0
freetype           conda-forge/osx-64::freetype-2.12.1-h60636b9_2
fribidi            conda-forge/osx-64::fribidi-1.0.10-hbcb3906_0
gettext            conda-forge/osx-64::gettext-0.21.1-h8a4c099_0
gmp                conda-forge/osx-64::gmp-6.2.1-h2e338ed_0
gmpy2              conda-forge/osx-64::gmpy2-2.1.2-py39h2da61ea_1
gnutls             conda-forge/osx-64::gnutls-3.7.8-h207c4f0_0
graphite2          conda-forge/osx-64::graphite2-1.3.13-h2e338ed_1001
harfbuzz           conda-forge/osx-64::harfbuzz-8.2.1-h7666e2a_0
icu                conda-forge/osx-64::icu-73.2-hf5e326d_0
jinja2             conda-forge/noarch::jinja2-3.1.2-pyhd8ed1ab_1
lame               conda-forge/osx-64::lame-3.100-hb7f2c08_1003
lcms2              conda-forge/osx-64::lcms2-2.15-hd6ba6f3_3
lerc               conda-forge/osx-64::lerc-4.0.0-hb486fe8_0
libass             conda-forge/osx-64::libass-0.17.1-h80904bb_1
libdeflate         conda-forge/osx-64::libdeflate-1.19-ha4e1b8e_0
libexpat           conda-forge/osx-64::libexpat-2.5.0-hf0c8a7f_1
libglib            conda-forge/osx-64::libglib-2.78.0-hc62aa5d_0
libiconv           conda-forge/osx-64::libiconv-1.17-hac89ed1_0
libidn2            conda-forge/osx-64::libidn2-2.3.4-hb7f2c08_0
libjpeg-turbo      conda-forge/osx-64::libjpeg-turbo-3.0.0-h0dc2134_1
libopus            conda-forge/osx-64::libopus-1.3.1-hc929b4f_1
libpng             conda-forge/osx-64::libpng-1.6.39-ha978bb4_0
libtasn1           conda-forge/osx-64::libtasn1-4.19.0-hb7f2c08_0
libtiff            conda-forge/osx-64::libtiff-4.6.0-h684deea_2
libunistring       conda-forge/osx-64::libunistring-0.9.10-h0d85af4_0
libvpx             conda-forge/osx-64::libvpx-1.13.1-he965462_0
libwebp-base       conda-forge/osx-64::libwebp-base-1.3.2-h0dc2134_0
libxcb             conda-forge/osx-64::libxcb-1.15-hb7f2c08_0
libxml2            conda-forge/osx-64::libxml2-2.11.5-h3346baf_1
llvm-openmp        conda-forge/osx-64::llvm-openmp-17.0.2-hff08bdf_0
markupsafe         conda-forge/osx-64::markupsafe-2.1.3-py39hdc70f33_1
mkl                conda-forge/osx-64::mkl-2023.2.0-hfe8bc8c_50499
mkl-service        pkgs/main/osx-64::mkl-service-2.4.0-py39h6c40b1e_1
mkl_fft            pkgs/main/osx-64::mkl_fft-1.3.8-py39h6c40b1e_0
mkl_random         pkgs/main/osx-64::mkl_random-1.2.4-py39ha357a0b_0
mpc                conda-forge/osx-64::mpc-1.3.1-h81bd1dd_0
mpfr               conda-forge/osx-64::mpfr-4.2.0-h4f9bd69_0
mpmath             conda-forge/noarch::mpmath-1.3.0-pyhd8ed1ab_0
nettle             conda-forge/osx-64::nettle-3.8.1-h96f3785_1
networkx           conda-forge/noarch::networkx-3.1-pyhd8ed1ab_0
numpy              pkgs/main/osx-64::numpy-1.26.0-py39h827a554_0
numpy-base         pkgs/main/osx-64::numpy-base-1.26.0-py39ha186be2_0
openh264           conda-forge/osx-64::openh264-2.3.1-hf0c8a7f_2
openjpeg           conda-forge/osx-64::openjpeg-2.5.0-ha4da562_3
p11-kit            conda-forge/osx-64::p11-kit-0.24.1-h65f8906_0
pcre2              conda-forge/osx-64::pcre2-10.40-h1c4e4bc_0
pillow             conda-forge/osx-64::pillow-10.1.0-py39hdd30358_0
pixman             conda-forge/osx-64::pixman-0.42.2-he965462_0
pthread-stubs      conda-forge/osx-64::pthread-stubs-0.4-hc929b4f_1001
pytorch            pytorch/osx-64::pytorch-2.1.0-py3.9_0
pyyaml             conda-forge/osx-64::pyyaml-6.0.1-py39hdc70f33_1
svt-av1            conda-forge/osx-64::svt-av1-1.7.0-he965462_0
sympy              conda-forge/noarch::sympy-1.12-pypyh9d50eac_103
tbb                conda-forge/osx-64::tbb-2021.10.0-h1c7c39f_1
torchaudio         pytorch/osx-64::torchaudio-2.1.0-py39_cpu
torchvision        pytorch/osx-64::torchvision-0.16.0-py39_cpu
typing_extensions  conda-forge/noarch::typing_extensions-4.8.0-pyha770c72_0
x264               conda-forge/osx-64::x264-1!164.3095-h775f41a_2
x265               conda-forge/osx-64::x265-3.5-hbb4e6a2_3
xorg-libxau        conda-forge/osx-64::xorg-libxau-1.0.11-h0dc2134_0
xorg-libxdmcp      conda-forge/osx-64::xorg-libxdmcp-1.1.3-h35c211d_0
yaml               conda-forge/osx-64::yaml-0.2.5-h0d85af4_2
zlib               conda-forge/osx-64::zlib-1.2.13-h8a1eda9_5

Proceed ([y]/n)? y

Downloading and Extracting Packages:

Preparing transaction: done  
Verifying transaction: done  
Executing transaction: done

python answer

(myenv) _____ ~ % python 
 
Python 3.9.6 (default, Oct 18 2022, 12:41:40)
[Clang 14.0.0 (clang-1400.0.29.202)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

> > > import torch
> > > Traceback (most recent call last):
> > > File "<stdin>", line 1, in <module>
> > > ModuleNotFoundError: No module named 'torch'

conda list

conda list

# packages in environment at /Users/____/anaconda3/envs/myenv:

# 

# Name                    Version                   Build  Channel

aom                       3.6.1                he965462_0    conda-forge
blas                      1.0                         mkl  
boltons                   23.0.0             pyhd8ed1ab_0    conda-forge
brotli-python             1.1.0            py39h840bb9f_1    conda-forge
bzip2                     1.0.8                h0d85af4_4    conda-forge
ca-certificates           2023.7.22            h8857fd0_0    conda-forge
cairo                     1.18.0               h99e66fa_0    conda-forge
certifi                   2023.7.22          pyhd8ed1ab_0    conda-forge
cffi                      1.16.0           py39h18ef598_0    conda-forge
charset-normalizer        3.3.0              pyhd8ed1ab_0    conda-forge
colorama                  0.4.6              pyhd8ed1ab_0    conda-forge
conda                     23.9.0           py39h6e9494a_0    conda-forge
conda-package-handling    2.2.0              pyh38be061_0    conda-forge
conda-package-streaming   0.9.0              pyhd8ed1ab_0    conda-forge
cryptography              41.0.4           py39he8b0a07_0    conda-forge
dav1d                     1.2.1                h0dc2134_0    conda-forge
expat                     2.5.0                hf0c8a7f_1    conda-forge
ffmpeg                    6.0.0           gpl_h789aacd_105    conda-forge
filelock                  3.12.4             pyhd8ed1ab_0    conda-forge
font-ttf-dejavu-sans-mono 2.37                 hab24e00_0    conda-forge
font-ttf-inconsolata      3.000                h77eed37_0    conda-forge
font-ttf-source-code-pro  2.038                h77eed37_0    conda-forge
font-ttf-ubuntu           0.83                 hab24e00_0    conda-forge
fontconfig                2.14.2               h5bb23bf_0    conda-forge
fonts-conda-ecosystem     1                             0    conda-forge
fonts-conda-forge         1                             0    conda-forge
freetype                  2.12.1               h60636b9_2    conda-forge
fribidi                   1.0.10               hbcb3906_0    conda-forge
fsspec                    2023.9.2                 pypi_0    pypi
gettext                   0.21.1               h8a4c099_0    conda-forge
gmp                       6.2.1                h2e338ed_0    conda-forge
gmpy2                     2.1.2            py39h2da61ea_1    conda-forge
gnutls                    3.7.8                h207c4f0_0    conda-forge
graphite2                 1.3.13            h2e338ed_1001    conda-forge
harfbuzz                  8.2.1                h7666e2a_0    conda-forge
icu                       73.2                 hf5e326d_0    conda-forge
idna                      3.4                pyhd8ed1ab_0    conda-forge
jinja2                    3.1.2              pyhd8ed1ab_1    conda-forge
jsonpatch                 1.33               pyhd8ed1ab_0    conda-forge
jsonpointer               2.4              py39h6e9494a_3    conda-forge
lame                      3.100             hb7f2c08_1003    conda-forge
lcms2                     2.15                 hd6ba6f3_3    conda-forge
lerc                      4.0.0                hb486fe8_0    conda-forge
libass                    0.17.1               h80904bb_1    conda-forge
libcxx                    16.0.6               hd57cbcb_0    conda-forge
libdeflate                1.19                 ha4e1b8e_0    conda-forge
libexpat                  2.5.0                hf0c8a7f_1    conda-forge
libffi                    3.4.2                h0d85af4_5    conda-forge
libglib                   2.78.0               hc62aa5d_0    conda-forge
libiconv                  1.17                 hac89ed1_0    conda-forge
libidn2                   2.3.4                hb7f2c08_0    conda-forge
libjpeg-turbo             3.0.0                h0dc2134_1    conda-forge
libopus                   1.3.1                hc929b4f_1    conda-forge
libpng                    1.6.39               ha978bb4_0    conda-forge
libsqlite                 3.43.2               h92b6c6a_0    conda-forge
libtasn1                  4.19.0               hb7f2c08_0    conda-forge
libtiff                   4.6.0                h684deea_2    conda-forge
libunistring              0.9.10               h0d85af4_0    conda-forge
libvpx                    1.13.1               he965462_0    conda-forge
libwebp-base              1.3.2                h0dc2134_0    conda-forge
libxcb                    1.15                 hb7f2c08_0    conda-forge
libxml2                   2.11.5               h3346baf_1    conda-forge
libzlib                   1.2.13               h8a1eda9_5    conda-forge
llvm-openmp               17.0.2               hff08bdf_0    conda-forge
markupsafe                2.1.3            py39hdc70f33_1    conda-forge
mkl                       2023.2.0         hfe8bc8c_50499    conda-forge
mkl-service               2.4.0            py39h6c40b1e_1  
mkl_fft                   1.3.8            py39h6c40b1e_0  
mkl_random                1.2.4            py39ha357a0b_0  
mpc                       1.3.1                h81bd1dd_0    conda-forge
mpfr                      4.2.0                h4f9bd69_0    conda-forge
mpmath                    1.3.0              pyhd8ed1ab_0    conda-forge
ncurses                   6.4                  hf0c8a7f_0    conda-forge
nettle                    3.8.1                h96f3785_1    conda-forge
networkx                  3.1                pyhd8ed1ab_0    conda-forge
numpy                     1.26.0           py39h827a554_0  
numpy-base                1.26.0           py39ha186be2_0  
openh264                  2.3.1                hf0c8a7f_2    conda-forge
openjpeg                  2.5.0                ha4da562_3    conda-forge
openssl                   3.1.3                h8a1eda9_0    conda-forge
p11-kit                   0.24.1               h65f8906_0    conda-forge
packaging                 23.2               pyhd8ed1ab_0    conda-forge
pcre2                     10.40                h1c4e4bc_0    conda-forge
pillow                    10.1.0           py39hdd30358_0    conda-forge
pip                       23.3               pyhd8ed1ab_0    conda-forge
pixman                    0.42.2               he965462_0    conda-forge
pluggy                    1.3.0              pyhd8ed1ab_0    conda-forge
pthread-stubs             0.4               hc929b4f_1001    conda-forge
pycosat                   0.6.6            py39hdc70f33_0    conda-forge
pycparser                 2.21               pyhd8ed1ab_0    conda-forge
pyopenssl                 23.2.0             pyhd8ed1ab_1    conda-forge
pysocks                   1.7.1              pyha2e5f31_6    conda-forge
python                    3.9.18          h07e1443_0_cpython    conda-forge
python_abi                3.9                      4_cp39    conda-forge
pytorch                   2.1.0                   py3.9_0    pytorch
pyyaml                    6.0.1            py39hdc70f33_1    conda-forge
readline                  8.2                  h9e318b2_1    conda-forge
requests                  2.31.0             pyhd8ed1ab_0    conda-forge
ruamel.yaml               0.17.35          py39hdc70f33_0    conda-forge
ruamel.yaml.clib          0.2.7            py39hdc70f33_2    conda-forge
setuptools                68.2.2             pyhd8ed1ab_0    conda-forge
svt-av1                   1.7.0                he965462_0    conda-forge
sympy                     1.12            pypyh9d50eac_103    conda-forge
tbb                       2021.10.0            h1c7c39f_1    conda-forge
tk                        8.6.13               hef22860_0    conda-forge
torchaudio                2.1.0                  py39_cpu    pytorch
torchvision               0.16.0                 py39_cpu    pytorch
tqdm                      4.66.1             pyhd8ed1ab_0    conda-forge
typing_extensions         4.8.0              pyha770c72_0    conda-forge
tzdata                    2023c                h71feb2d_0    conda-forge
urllib3                   2.0.6              pyhd8ed1ab_0    conda-forge
wheel                     0.41.2             pyhd8ed1ab_0    conda-forge
x264                      1!164.3095           h775f41a_2    conda-forge
x265                      3.5                  hbb4e6a2_3    conda-forge
xorg-libxau               1.0.11               h0dc2134_0    conda-forge
xorg-libxdmcp             1.1.3                h35c211d_0    conda-forge
xz                        5.2.6                h775f41a_0    conda-forge
yaml                      0.2.5                h0d85af4_2    conda-forge
zlib                      1.2.13               h8a1eda9_5    conda-forge
zstandard                 0.21.0           py39h5705987_1    conda-forge
zstd                      1.5.5                h829000d_0    conda-forge

I have been tried everything what chat gpt told me. Creating new env with python 3.9
Updated pip, conda, libmamba, github

2

Answers


  1. I think your problem with different version of python, one have been calling and another one is anoconda env where you’ve installed torch

    I recommend to do the next steps and simplify installation(this way works for me perfectly fine on mac os as you’ve mentioned before):

    python3.9 -m venv venv/
    

    then

    source venv/bin/activate
    

    then

    pip install torch torchvision torchaudio
    

    enter image description here

    Login or Signup to reply.
  2. You are not calling the python from your currently active conda env. Notice the python that conda installed is version 3.9.18:

    python                    3.9.18          h07e1443_0_cpython    conda-forge
    

    But what is being called when you write (myenv) _____ ~ % python is another version (3.9.6):

    Python 3.9.6 (default, Oct 18 2022, 12:41:40)
    

    So either:

    1. Your PATH is not correct, which would indicate that your conda did not activate the env correctly. Do echo $PATH and check that the folders of your env are in the front
    2. You have an alias set up for python, something that some tutorials online suggest. type type python and check the output.

    A workaround can be to call ${CONDA_PREFIX}/bin/python and try your import torch there. This should call the python interpreter installed into your currently active env

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search