35

I have installed cuda along pytorch with

conda install pytorch torchvision cudatoolkit=10.0 -c pytorch

However, it seems like nvcc was not installed along with it. If I want to use for example nvcc -V, I get the error that nvcc was not found, and that I should install it with sudo apt install nvidia-cuda-toolkit. Can I do this (I dont want to just try and then find out that it is not working/messes up the whole cuda setup). And is this a bug or expected behavior?

I am using Ubuntu 18.04 and have cuda 10.2

talonmies
  • 70,661
  • 34
  • 192
  • 269
Luca Thiede
  • 3,229
  • 4
  • 21
  • 32
  • 3
    The `cudatoolkit` installed using `conda install` is not the same as the CUDA toolkit packaged up by NVIDIA. It is a subset, to provide the needed components for other packages installed by `conda` such as `pytorch`. It's likely that it is all you need if you only need to use pytorch. If you need/want the full CUDA toolkit for some other reason, you can install it using a variety of methods including some variant of the one you indicate, but it will install a separate copy, in another location from what is typically used by conda packages. This all looks like expected behavior to me. – Robert Crovella Jun 06 '19 at 03:12
  • NVIDIA publishes a [CUDA linux install guide](https://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html) which may be useful. It doesn't have conda packages or methods in view, however. – Robert Crovella Jun 06 '19 at 03:14
  • You haven't mentioned if you have a GPU, or what GPU you have, or if you installed a GPU driver, or what GPU driver you installed, but that is all important. The simplest instruction for compatibility is to install the latest driver for your GPU, if you've not already done so. Installing a CUDA toolkit from NVIDIA may install a proper/sufficient driver for you, depending on what exactly you install. Generally, `conda install ...` does not install a GPU driver, in my experience. – Robert Crovella Jun 06 '19 at 03:24
  • An Faster-RCNN implementation I want to use needs nvcc. I do have a gpu, and Pytorch runs flawless otherwise. So the safest bet is to uninistall the conda cudatoolkit and install cuda manually? Do you know of any good installlation script that automates the installation? – Luca Thiede Jun 06 '19 at 07:09
  • I think you will discover that it is harder to get your conda install of pytorch to use a CUDA toolkit other than the one installed by conda. I don't know what the safest bet is; I regularly use a machine that has the cuda toolkit installed by conda and a separate install that I did using the instructions I already provided. That may or may not work for your use case. Versions do matter. Requests for tutorials, scripts, off-site resources are generally off-topic for stack overflow, from what I have seen. – Robert Crovella Jun 06 '19 at 11:49

6 Answers6

26

Met this question when installing cudatoolkit of 10.1 with PyTorch 1.4.

There is a conda-forge package https://anaconda.org/conda-forge/cudatoolkit-dev. After installing this, nvcc as well as other CUDA libraries will be then available at /home/li/anaconda3/envs/<env_name>/pkgs/cuda-toolkit in bin/ and lib/.

Bo Li
  • 569
  • 5
  • 12
9

cudatoolkit that is installed with pytorch is runtime only and does not come with the development compiler nvcc. To get nvcc you need to install cudatoolkit-dev which I believe is available from the conda-forge channel.

Deep Patel
  • 619
  • 7
  • 8
  • From the Nvidia website ( [link](https://docs.nvidia.com/cuda/cuda-installation-guide-microsoft-windows/index.html) ), I see that CUDA packages can be installed selectively. Is it sufficient to only install nvcc? – Juergen Jan 06 '22 at 08:44
  • I haven't tried with selective install but seems okay since the nvcc installation will check for any dependencies beforehand – Deep Patel Jan 06 '22 at 20:24
8

nvidia conda channel is now available: nvidia/cuda and nvcc is in it.

tothedistance
  • 161
  • 2
  • 4
6

You can try

conda install -c conda-forge nvcc_linux-64

Currently this should get you 10.2. Nvidia has its own channel nvidia but the latest version there is 10.1.

ink
  • 4,413
  • 3
  • 14
  • 11
  • 14
    Followed this answer but found out that this seems not solving the problems. The nvcc installed by `nvcc_linux-64` is merely a shell script calling `$(CUDA_HOME)/bin/nvcc` – Bo Li Apr 14 '20 at 05:13
  • as it say in the description of the [package](https://anaconda.org/search?q=nvcc): "A meta-package to enable the right nvcc." not really nvcc – stason Mar 12 '21 at 02:34
  • 1
    People, listen to the guys above my comment: this does NOT install nvcc! It is like a shortcut to nowhere! You will waste time figuring out what is wrong when you don't have nvcc in the first place! – Wok Apr 28 '21 at 13:18
  • This answer is on a good track, I read an article stating the most "robust" way to get NVCC is to install Cuda on host and use conda nvcc_linux-64 to basically make your Env aware of the local installation. See https://towardsdatascience.com/building-a-conda-environment-for-horovod-773bd036bf64 – FreeSoftwareServers Oct 29 '22 at 00:33
4

cudatoolkit-dev package from conda-forge did not work for me. I used the package from HCC with the latest pytorch (v1.9.0) https://anaconda.org/HCC/cudatoolkit.

The command to install cudatoolkit alongside pytorch and torchvision:

conda install pytorch torchvision cudatoolkit=10.2 -c pytorch -c hcc

After the installation, you can check

$ nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2019 NVIDIA Corporation
Built on Wed_Oct_23_19:24:38_PDT_2019
Cuda compilation tools, release 10.2, V10.2.89
Fazil
  • 41
  • 1
0

Check if nvcc is in the folder /usr/local/cuda-10.2/bin Run ./nvcc --version if it exists in that folder

Output looks like this

nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2019 NVIDIA Corporation
Built on Wed_Oct_23_19:24:38_PDT_2019
Cuda compilation tools, release 10.2, V10.2.89

If this is the case, add the folder to your global path variable echo "export PATH=/usr/local/cuda-10.2/bin${PATH:+:${PATH}}" >> ~/.profile

and refresh the profile using source ~/.profile

and reboot your machine.