PyTorch Cuda with anaconda not available

安稳与你 提交于 2021-01-29 10:37:00

问题


I'm using anaconda to regulate my environment, for a project i have to use my GPU for network training. I use pytorch for my project and i'm trying to get CUDA working.

I installed cudatoolkit, numba, cudnn

still, when i try this command:

torch.cuda.is_available()

I get "False" as output. This is my environment:

# Name                    Version                   Build  Channel
blas                      1.0                         mkl  
bzip2                     1.0.6                h470a237_2    conda-forge
ca-certificates           2018.03.07                    0  
cairo                     1.14.12              he6fea26_5    conda-forge
certifi                   2018.8.24                py35_1  
cffi                      1.11.5           py35he75722e_1  
cloudpickle               0.5.5                    py35_0  
cudatoolkit               9.2                           0    anaconda
cudnn                     7.2.1                 cuda9.2_0    anaconda
cycler                    0.10.0                     py_1    conda-forge
cython                    0.28.5           py35hf484d3e_0    anaconda
dask-core                 0.19.2                   py35_0  
dbus                      1.13.0               h3a4f0e9_0    conda-forge
decorator                 4.3.0                    py35_0  
expat                     2.2.5                hfc679d8_2    conda-forge
ffmpeg                    4.0.2                ha0c5888_1    conda-forge
fontconfig                2.13.1               h65d0f4c_0    conda-forge
freetype                  2.9.1                h6debe1e_4    conda-forge
gettext                   0.19.8.1             h5e8e0c9_1    conda-forge
giflib                    5.1.4                h470a237_1    conda-forge
glib                      2.55.0               h464dc38_2    conda-forge
gmp                       6.1.2                hfc679d8_0    conda-forge
gnutls                    3.5.19               h2a4e5f8_1    conda-forge
graphite2                 1.3.12               hfc679d8_1    conda-forge
gst-plugins-base          1.12.5               hde13a9d_0    conda-forge
gstreamer                 1.12.5               h61a6719_0    conda-forge
harfbuzz                  1.9.0                h08d66d9_0    conda-forge
hdf5                      1.10.2               hc401514_2    conda-forge
icu                       58.2                 hfc679d8_0    conda-forge
imageio                   2.4.1                    py35_0  
intel-openmp              2019.0                      118  
jasper                    1.900.1              hff1ad4c_5    conda-forge
jpeg                      9c                   h470a237_1    conda-forge
kiwisolver                1.0.1            py35h2d50403_2    conda-forge
libedit                   3.1.20170329         h6b74fdf_2  
libffi                    3.2.1                hd88cf55_4  
libgcc-ng                 8.2.0                hdf63c60_1  
libgfortran               3.0.0                         1    conda-forge
libgfortran-ng            7.3.0                hdf63c60_0  
libiconv                  1.15                 h470a237_3    conda-forge
libopenblas               0.3.3                h5a2b251_3  
libpng                    1.6.35               ha92aebf_2    conda-forge
libstdcxx-ng              8.2.0                hdf63c60_1  
libtiff                   4.0.9                he6b73bb_2    conda-forge
libuuid                   2.32.1               h470a237_2    conda-forge
libwebp                   0.5.2                         7    conda-forge
libxcb                    1.13                 h470a237_2    conda-forge
libxml2                   2.9.8                h422b904_5    conda-forge
llvmlite                  0.24.0           py35hdbcaa40_0  
matplotlib                3.0.0            py35h0b34cb6_1    conda-forge
mkl                       2019.0                      118  
mkl_fft                   1.0.6                    py35_0    conda-forge
mkl_random                1.0.1                    py35_0    conda-forge
ncurses                   6.1                  hf484d3e_0  
nettle                    3.3                           0    conda-forge
networkx                  2.1                      py35_0  
ninja                     1.8.2            py35h6bb024c_1  
numba                     0.39.0           py35h04863e7_0  
numpy                     1.15.2           py35h1d66e8a_0  
numpy-base                1.15.2           py35h81de0dd_0  
olefile                   0.46                     py35_0  
openblas                  0.2.20                        8    conda-forge
opencv                    3.4.1            py35h6fd60c2_1  
opencv-python             3.4.3.18                  <pip>
openh264                  1.7.0                         0    conda-forge
openssl                   1.0.2p               h14c3975_0  
pandas                    0.23.4           py35h04863e7_0  
pcre                      8.41                 hfc679d8_3    conda-forge
pillow                    5.2.0            py35heded4f4_0  
Pillow                    5.3.0                     <pip>
pip                       10.0.1                   py35_0  
pixman                    0.34.0               h470a237_3    conda-forge
pthread-stubs             0.4                  h470a237_1    conda-forge
pycparser                 2.19                     py35_0  
pyparsing                 2.2.2                      py_0    conda-forge
pyqt                      5.6.0            py35h8210e8a_7    conda-forge
python                    3.5.6                hc3d631a_0  
python-dateutil           2.7.3                      py_0    conda-forge
pytorch                   0.4.1           py35_py27__9.0.176_7.1.2_2    pytorch
pytz                      2018.5                   py35_0  
pywavelets                1.0.0            py35hdd07704_0  
qt                        5.6.2                hf70d934_9    conda-forge
readline                  7.0                  h7b6447c_5  
scikit-image              0.14.0           py35hf484d3e_1  
scipy                     1.1.0            py35hfa4b5c9_1  
setuptools                40.2.0                   py35_0  
sip                       4.18.1           py35hfc679d8_0    conda-forge
six                       1.11.0                   py35_1    conda-forge
sqlite                    3.25.2               h7b6447c_0  
tk                        8.6.8                hbc83047_0  
toolz                     0.9.0                    py35_0  
torchvision               0.1.9            py35h72e4c6f_1    soumith
tornado                   5.1.1            py35h470a237_0    conda-forge
wheel                     0.31.1                   py35_0  
x264                      1!152.20180717       h470a237_1    conda-forge
xorg-kbproto              1.0.7                h470a237_2    conda-forge
xorg-libice               1.0.9                h470a237_4    conda-forge
xorg-libsm                1.2.2                h8c8a85c_6    conda-forge
xorg-libx11               1.6.6                h470a237_0    conda-forge
xorg-libxau               1.0.8                h470a237_6    conda-forge
xorg-libxdmcp             1.1.2                h470a237_7    conda-forge
xorg-libxext              1.3.3                h470a237_4    conda-forge
xorg-libxrender           0.9.10               h470a237_2    conda-forge
xorg-renderproto          0.11.1               h470a237_2    conda-forge
xorg-xextproto            7.3.0                h470a237_2    conda-forge
xorg-xproto               7.0.31               h470a237_7    conda-forge
xz                        5.2.4                h14c3975_4  
zlib                      1.2.11               ha838bed_2 

My desktop has a NVIDIA GeForce GTX 970 (so it is cuda available) Also for some reason, as you can see here:

My graphics card doesn't show, however when using the

lspci -v

command, i can see my graphics card there. Don't know if that has something to do with it. Anyone knows how i can fix this?


回答1:


FIXED: I installed CUDA seperately, not through anaconda and now it works. If anyone knows why it doesn't work when installing cuda in anaconda, feel free to answer




回答2:


You need to install pytorch "in one go" using https://pytorch.org/get-started/locally/ to construct the anaconda command.

With the standard configuration in anaconda, you get:

conda install pytorch torchvision cudatoolkit=10.2 -c pytorch

(Please always check on https://pytorch.org/get-started/locally/ whether this command is still up to date.)

You seem to need the right cuda version 10.2 package to be aligned with what pytorch can handle. This is what is meant with @RussellGallop's helpful message.

We can see that installing pytorch and cuda separately is not recommended, and that Anaconda installation is recommended, against your answer:

Anaconda is our recommended package manager since it installs all dependencies.

(Note: If in case of problems, you better uninstall all covered packages and apply https://pytorch.org/get-started/locally/ to get the command again, instead of trying to fix it with separate installations. And if you then want to uninstall, you need to use the exactly same command of the installation, but with "conda uninstall" instead. This needed uninstall "in one go" again is another hint at the sensitive installation of pytorch, and that separate installation is risky. See How can l uninstall PyTorch?)




回答3:


Your CUDA install needs to be compatible with your NVidia drivers (which aren't installed by Anaconda). I had a similar thing with Anaconda on Windows. I ignored the torch.cuda.is_available() check and tried to send a model to the GPU with:

device = torch.device("cuda")
model.to(device)

This gave a more helpful message:

The NVIDIA driver on your system is too old (found version 10010).
Please update your GPU driver by downloading and installing a new
version from the URL: http://www.nvidia.com/Download/index.aspx
Alternatively, go to: https://pytorch.org to install
a PyTorch version that has been compiled with your version
of the CUDA driver.


来源:https://stackoverflow.com/questions/53102436/pytorch-cuda-with-anaconda-not-available

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!