2

I am trying to export some environment variables in Unix using .bash_profile

It reads now like this:

export PATH=${PATH}:/usr/local/cuda-6.0/bin/
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/usr/local/cuda-6.0/targets/x86_64-linux/lib/

After that I try to run a python script that uses these variables

python
>>> import theano

And I get this error:

ERROR (theano.sandbox.cuda): nvcc compiler not found on $PATH. Check your nvcc installation and try again.

Then I exit python, re-run manually the first line of .bash_profile and it works.

If I change the order of the exports like this:

export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/usr/local/cuda-6.0/targets/x86_64-linux/lib/
export PATH=${PATH}:/usr/local/cuda-6.0/bin/

And try one more time to import theano from python I get this error:

ERROR (theano.sandbox.cuda): Failed to compile cuda_ndarray.cu: libcublas.so.6.0: cannot open shared object file: No such file or directory
WARNING (theano.sandbox.cuda): CUDA is installed, but device gpu is not available  (error: cuda unavilable)

Which indicates that export LD_LIBRARY_PATH didn't work. I do the same procedure as before, exit python re-run the first line and then it imports correctly.

Adding the first export to the last line of the bash script (exporting twice) makes this first/third export work well but not the second, that is, only the last export is working properly.

I've tried doing echo commmands on the variables and it was printing normally as if they were correctly set, but I'm unable to use them with python. Also, when re-setting them manually that doesn't double export them, but re-re-setting does:

-bash-4.2$ echo $LD_LIBRARY_PATH
:/usr/local/cuda-6.0/targets/x86_64-linux/lib/
-bash-4.2$ export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/usr/local/cuda-6.0/targets/x86_64-linux/lib/
-bash-4.2$ echo $LD_LIBRARY_PATH
:/usr/local/cuda-6.0/targets/x86_64-linux/lib/
-bash-4.2$ export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/usr/local/cuda-6.0/targets/x86_64-linux/lib/
-bash-4.2$ echo $LD_LIBRARY_PATH
:/usr/local/cuda-6.0/targets/x86_64-linux/lib/:/usr/local/cuda-6.0/targets/x86_64-linux/lib/

I've actually solved this issue by re-setting the PATH variable inside the python script, but it bothers me that I can't find the reason why this is happening

Some info:

-bash-4.2$ bash --version
GNU bash, version 4.2.53(1)-release (x86_64-redhat-linux-gnu)
-bash-4.2$ cat /etc/*-release
Fedora release 19 (Schrödinger’s Cat)
3

I see in my crystal ball that you're editing the file on a Windows machine.

Windows and Linux have different ways of representing line breaks. On Linux (like any unix system), a line consists of a series of characters which ends with a line feed (LF = \n = Ctrl+J) character. On Windows, lines are separated by a two-character sequence: carriage return, then line feed (CRLF = \r\n = Ctrl+M Ctrl+J).

Your file contains the export PATH=… command, then CR, LF, and the export LD_LIBRARY_PATH command with no newline at the end. For Linux programs, the same sequence of bytes represents export PATH=… with a CR character at the end, then a line break, then an unfinished line containing export PATH=…. Your shell faithfully executes the first command, which adds a directory to PATH with a name ending in a CR character. Since there is no directory by that name, the change of PATH has no effect. Then the shell treats the partial line as if it was a complete line, which is the intended command to set LD_LIBRARY_PATH.

When you appended the directory the second time, you didn't type a CR character into the command, so the command worked. When you displayed the output, the CR character was interpreted by the terminal to mean “move back to the beginning of the line”. Since you had exactly the same content before and after the CR character, that appeared to print that content once — in fact it was printed twice at the same position.

Edit your Linux configuration files under Linux, or tell your Windows editor to use Linux line endings (most text editors that are less brain-dead than Notepad can do that).

  • I'll have to wait until Monday to confirm this, but it makes perfect sense. Thank you. And yes, I'm using a SSH/SFTP client to run Linux remotely from Windows – gsmafra May 8 '15 at 11:06
0

Please have a look at man bash section FILES where the difference is explained on bash_profile and bashrc:

   ~/.bash_profile
          The personal initialization file, executed for login shells
   ~/.bashrc
          The individual per-interactive-shell startup file

It looks like you are starting a new shell and that the entries you've put in ~/.bash_profile are not used at all.

Try to set the entries in the ~/.bash_rc file instead.

  • I've tried this, it is reading ~/.bash_profile and not ~/.bash_rc – gsmafra May 7 '15 at 15:03
  • And are you logging out and logging in again every time you modify your .bash_profile? – G-Man May 7 '15 at 18:40
  • Yes. (15 characters) – gsmafra May 7 '15 at 20:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.