installing Cuda 7.5 fails on ubuntu 14.0.4.5 with error driver installation is unable to locate the kernel source

I am trying to install cuda toolkit along with its drivers.
I downloaded the <i>cuda_7.5.18_linux.run</i> and ran these commands to install it :

Ctrl_Alt-F1 :
sudo service lightdm stop
cd to media/username/store/nvidia
sudo sh cuda_7.5.18_linux.run

this failed the first time and told me to reboot.
This is the first log: http://pastebin.com/nRATL0X8 .
if You look at the logs, you can see that all the buildings seem to be going well untill it says :

ERROR: Unable to build the NVIDIA kernel module.

ERROR: Installation has failed.  Please see the file
     
'/var/log/nvidia-installer.log' for details.  You may find

I rebooted and nothing happened
I tried

sudo init 3 
sudo sh cuda_7.5.18_linux.run

and again no luck.
it kept saying :

The driver installation is unable to locate the kernel source. Please
 make sure that the kernel source packages are installed and set up
 correctly. If you know that the kernel source packages are installed
 and set up correctly, you may pass the location of the kernel source
 with the '--kernel-source-path' flag.

So this time I wrote :

hossein@hossein:/tmp$ uname -r
4.4.0-47-generic

and went to usr/scr/ and this is how it looks :

hossein@hossein:/usr/src$ ls
    linux-headers-3.13.0-101          linux-headers-4.4.0-31-generic
    linux-headers-3.13.0-101-generic  linux-headers-4.4.0-47
    linux-headers-4.4.0-31            linux-headers-4.4.0-47-generic

so I did :

sudo sh cuda_7.5.18_linux.run --kernel-source-path=/usr/src/linux-headers-headers-4.4.0-47-generic

which failed again!
and this is the log file :

Using more to view the EULA.
Installing the NVIDIA display driver...
Verifying archive integrity... OK
    
Uncompressing NVIDIA Accelerated Graphics Driver for Linux-x86_64 352.39...........................................................................................................................................................................................................................................................
    
    
    
    Welcome to the NVIDIA Software Installer for Unix/Linux
    
    
    
    Detected 2 CPUs online; setting concurrency level to 2.
    
    License accepted by command line option.
    
    Installing NVIDIA driver version 352.39.
    
    Running distribution scripts
    
      Executing /usr/lib/nvidia/pre-install: [                              ]   0%
      Executing /usr/lib/nvidia/pre-install: [##############################] 100%
    
    
    
    WARNING: One or more modprobe configuration files to disable Nouveau are
    
             already present at:
    
             /etc/modprobe.d/nvidia-installer-disable-nouveau.conf.  Please be
    
             sure you have rebooted your system since these files were written.
    
             If you have rebooted, then Nouveau may be enabled for other
    
             reasons, such as being included in the system initial ramdisk or
    
             in your X configuration file.  Please consult the NVIDIA driver
    
             README and your Linux distribution's documentation for details on
    
             how to correctly disable the Nouveau kernel driver.
    
    
    
    
    
    ERROR: The kernel source path
    
           '/usr/src/linux-headers-headers-4.4.0-47-generic' does not exist. 
    
           Please make sure you have installed the kernel source files for your
    
           kernel and that they are properly configured; on Red Hat Linux
    
           systems, for example, be sure you have the 'kernel-source' or
    
           'kernel-devel' RPM installed.  If you know the correct kernel source
    
           files are installed, you may specify the kernel source path with the
    
           '--kernel-source-path' command line option.
    
    
    
    
    
    ERROR: Installation has failed.  Please see the file
    
           '/var/log/nvidia-installer.log' for details.  You may find
    
           suggestions on fixing installation problems in the README available
    
           on the Linux driver download page at www.nvidia.com.
    
    
    
    The distribution-provided pre-install script failed!  Are you sure you want
    
    to continue? (Answer: Continue installation)
    
    For some distributions, Nouveau can be disabled by adding a file in the
    
    modprobe configuration directory.  Would you like nvidia-installer to
    
    attempt to create this modprobe file for you? (Answer: Yes)
    
    
    
    One or more modprobe configuration files to disable Nouveau have been
    
    written.  For some distributions, this may be sufficient to disable
    
    Nouveau; other distributions may require modification of the initial
    
    ramdisk.  Please reboot your system and attempt NVIDIA driver installation
    
    again.  Note if you later wish to reenable Nouveau, you will need to delete
    
    these files: /etc/modprobe.d/nvidia-installer-disable-nouveau.conf
    
    
    
    Performing CC sanity check with CC="/usr/bin/cc".
    
    Using the kernel source path
    
    '/usr/src/linux-headers-headers-4.4.0-47-generic' as specified by the
    
    '--kernel-source-path' commandline option.
    
    The driver installation is unable to locate the kernel source. Please make sure that the kernel source packages are installed and set up correctly.
    If you know that the kernel source packages are installed and set up correctly, you may pass the location of the kernel source with the '--kernel-source-path' flag.
    
    ===========
    = Summary =
    ===========
    
    Driver:   Installation Failed
    Toolkit:  Installation skipped
    Samples:  Installation skipped
    
    
    Logfile is /tmp/cuda_install_9896.log

What do I do now?
Notice:
I need to say that I just repaired grub an hour ago, my windows 10 and ubuntu got messed up and I had to use boot-repair twice to get it working .
this is the last log in case it may be needed : First_log(messed up): http://paste.ubuntu.com/23543453/, SecondLog(fixed everything): http://paste.ubuntu.com/23543541/

It’s not:

linux-headers-headers

it’s just:

linux-headers

Thanks alot, now I get this error which the full log can be seen here : http://pastebin.com/nCugW1CD :

ERROR: Unable to build the NVIDIA kernel module.
ERROR: Installation has failed.  Please see the file

       '/var/log/nvidia-installer.log' for details.  You may find

       suggestions on fixing installation problems in the README available

       on the Linux driver download page at www.nvidia.com.

The driver installation is unable to locate the kernel source. Please make sure that the kernel source packages are installed and set up correctly.
If you know that the kernel source packages are installed and set up correctly, you may pass the location of the kernel source with the '--kernel-source-path' flag.

===========
= Summary =
===========

Driver:   Installation Failed
Toolkit:  Installation skipped
Samples:  Installation skipped

Logfile is /tmp/cuda_install_3595.log

and this is the nvidia-installer log file : http://pastebin.com/1P2Z7xkE
these are the errors at the very end :

/tmp/selfgz3643/NVIDIA-Linux-x86_64-352.39/kernel/nv-procfs.c: In function ‘nv_procfs_read_registry’:
   /tmp/selfgz3643/NVIDIA-Linux-x86_64-352.39/kernel/nv-procfs.c:362:1: warning: control reaches end of non-void function [-Wreturn-type]
    }
    ^
   make[2]: *** [/tmp/selfgz3643/NVIDIA-Linux-x86_64-352.39/kernel/nv-procfs.o] Error 1
   make[2]: *** Waiting for unfinished jobs....
     if [ "-pg" = "-pg" ]; then if [ /tmp/selfgz3643/NVIDIA-Linux-x86_64-352.39/kernel/nv-usermap.o != "scripts/mod/empty.o" ]; then ./scripts/recordmcount  "/tmp/selfgz3643/NVIDIA-Linux-x86_64-352.39/kernel/nv-usermap.o"; fi; fi;
   make[1]: *** [_module_/tmp/selfgz3643/NVIDIA-Linux-x86_64-352.39/kernel] Error 2
   make[1]: Leaving directory `/usr/src/linux-headers-4.4.0-47-generic'
  NVIDIA: left KBUILD.
  nvidia.ko failed to build!
  make: *** [module] Error 1
-> Error.
ERROR: Unable to build the NVIDIA kernel module.
ERROR: Installation has failed.  Please see the file '/var/log/nvidia-installer.log' for details.  You may find suggestions on fixing installation problems in the README available on the Linux driver download page at www.nvidia.com.

What do I do now?

Try installing 352.99 instead of 352.39:

http://www.nvidia.com/download/driverResults.aspx/105665/en-us

You’ll need to specify your kernel source path as before. If that works, then install the CUDA 7.5 toolkit but select “no” when prompted to install the driver.

sudo sh cuda_7.5.18_linux.run

Thanks alot txbob,
I actually ended up installing the driver separately using ubuntus Aditional Drivers. (installed the 367.57 version) and then ran the cuda7.5 toolkit and as you pointed out, selected no for the driver section, and the rest went just fine.
I however still dont know why it wouldnt install. was it because of me not having a swapdrive.swap file, or my t was just a dependency issue.
Anyway I’m happy its gone.
and I sincerely thank you for your time and help sir. I really do.
God Bless you.

It wouldn’t install because the NVIDIA kernel module compile process was hitting a compile error.

As linux kernels undergo development, various interfaces change from time to time. The NVIDIA GPU driver is tightly integrated with the kernel, and so from time to time these interface changes break the connection with a particular driver, in the form of a compile error.

The warning you pasted into the posting here was not the crux of the issue. The real issue was a compile error that shows up earlier in the log:

/tmp/selfgz3643/NVIDIA-Linux-x86_64-352.39/kernel/nv-procfs.c:561:5: error: void value not ignored as it ought to be
        return seq_puts(s, s->private);

This is arising from the fact that changes were incorporated into the ubuntu linux 4.4 kernel base used in Ubuntu 14.04.5 that were not present in previous 3.xx kernels that were used in previous Ubuntu versions (e.g. 14.04.1). Eventually, the NVIDIA driver engineers figure out these changes/breakages, and fix the interface on our side of the driver kernel module compilation process, so that we avoid the compile errors.

So by using a “newer” driver, whether newer in the 352.xx branch, or newer in the 367.xx branch as you actually used, you are picking up the fix for this compile error, and the rest works after that.

Thanks a billion sir:)
That was a great explanation and I now know what happened.
I appreciate your kind help and time
May God keep you and your beloved ones safe and sound :)