How to set an environment variable on ubuntu 18.04 - tensorflow

According to the deespeech documentation to avoid this error related to tensorflow I have to proceed as follows but I don't know how to set an environment variable. Could you explain me the steps to follow? I use ubuntu 18.04.

You can type TF_FORCE_GPU_ALLOW_GROWTH=true in you terminal before running your program.
You can also add export TF_FORCE_GPU_ALLOW_GROWTH=true in ~/.bashrc and it will load automatically when new terminal will open

Related

Running remote Pycharm interpreter with tensorflow and cuda (with module load)

I am using a remote computer in order to run my program on its GPU. My program contains some code with tensorflow functions, and for easier debugging with Pycharm I would like to connect via ssh with remote interpreter to the computer with the GPU. This part can be done easily since Pycharm has this option so I can connect there. However, tensorflow is not loaded automatically so I get import error.
Note that in our institution, we run module load cuda/10.0 and module load tensorflow/1.14.0 each time the computer is loaded. Now this part is the tricky one. Opening a remote terminal creates another session which is not related to the remote interpreter session so it's not affecting remote interpreter modules.
I know that module load in general configures env, however I am not sure how can I export the environment variables to Pycharm's environment variables that are configured before a run.
Any help would be appreciated. Thanks in advance.
The workaround after all was relatively simple: first, I have installed the EnvFile plugin, as it was explained here: https://stackoverflow.com/a/42708476/13236698
Them I created an .env file with a quick script on python, extracting all environment variables and their values from os.environ and wrote them to a file in the following format: <env_variable>=<variable_value>, and saved the file with .env extension. Then I loaded it to PyCharm, and voila - all tensorflow modules were loaded fine.

Tensorflow Object Detection API - PYTHONPATH unsets itself, when using different terminal

This might be a silly question, but I didn't find anything on the internet. I am trying to run the object_detection API of tensorflow in Windows 10. I've installed all the packages correctly and I've also added the "models" directory to the PYTHONPATH, using windows cmd:
set PYTHONPATH=C:\Program Files\Tensorflow\models
And I also verify that the PYTHONPATH is set correctly, by typing set PYTHONPATH, which gives me this output:
PYTHONPATH=C:\Program Files\Tensorflow\models
Running the following test
python research/object_detection/builders/model_builder_tf2_test.py
I get the output:
Ran 20 tests in 37.331s
OK (Skipped 1)
Which is great. However, If I open another terminal and type
python research/object_detection/builders/model_builder_tf2_test.py
I get the error: ModuleNotFoundError: No Module named official
However, If i type set PYTHONPATH command to verify that the PYTHONPATH is correct I get:
PYTHONPATH=C:\Users\Kohli\AppData\Local\Programs\Python\Python37\Scripts\Tensorflow\models;C:\Users\Kohli\AppData\Local\Programs\Python\Python37\Scripts\Tensorflow\models\official;C:\Users\Kohli\AppData\Local\Programs\Python\Python37\Scripts\Tensorflow\models\research
which is different from the previous terminal output. Moreover, when I open the "Enviroment Variables" tab, I can see that PYTHONPATH exists.
If I add the models directory to PYTHONPATH once again, It will work, but Only for that particular terminal. However, I don't understand why this is happening. Does the "set PYTHONPATH" command creates a virtual environment for that particular terminal or something? How can i permanently add models dir to PYTHONPATH, without typing set PYTHONPATH or os.path.append('path/to/models') ?
Thanks in advance

environment variable not working in Google Code Colab

I am trying to set LD_LIBRARY_PATH in google code colab by following statements:
import os
os.environ['LD_LIBRARY_PATH']='/path/to/library/used/by/my/software'
I can see the environment variable added in the environment variables list, checked by (!printenv), but when my exe tries to access the library stored at LD_LIBRARY_PATH, it is not able to find it.
NotFoundError: library_name.so: cannot open shared object file: No such file or directory
I also tried configuring the environment variables through colab-env package (https://pypi.org/project/colab-env/), but I am facing same issue with this approach also.
Can someone give pointers? Thank you.
You are setting up only in your notebook environment.
To configure in linux environment, you can use this:
!export AWS_SHARED_CREDENTIALS_FILE=<PATH HERE>
But I usually do this:
import os
!export AWS_SHARED_CREDENTIALS_FILE=<PATH HERE>
os.environ['AWS_SHARED_CREDENTIALS_FILE'] = <PATH HERE>
Best solution with Colab is to first copy the executable file to Drive :
!cp /content/gdrive/My\ Drive/Colab\ Notebooks/<FILE> /usr/local/bin.
Then allow to execute it:
!chmod 755 /usr/local/bin/<FILE>.
Courtesy of Medium.

Is it necessary to set the JAVA_HOME variable every time system is restarted?

I have recently formatted my system and installed Ubuntu 16.0.4 and done all necessary setup for running react-native project.But since then every time i restart the system, getting following error,
ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation.
I am setting path by using following command,
export JAVA_Home=/home/syamkishore/Downloads/android-studio/jre
If i do so error will be cleared. But if I restart the system again same error occurs.
Can somebody suggest the permanent solution to set the Java path once forever?
Thank You.
Edit the system Path file /etc/profile
sudo gedit /etc/profile
Add following lines in end
JAVA_HOME=/usr/lib/jvm/jdk1.7.0
PATH=$PATH:$HOME/bin:$JAVA_HOME/bin
export JAVA_HOME
export JRE_HOME
export PATH
Please see below link. It explains how to set the java path permanently.
How to set the java class path?

Pycharm giving error on a script which is working from terminal (Module: Tensorflow)

I was working with the tensorflow(GPU version) module in Pycharm. If I run a script from terminal, it works as expected. However when I run the script from pycharm, it says:
ImportError: libcudart.so.7.5: cannot open shared object file: No
such file or directory
How do I resolve this?
Pycharm interpreter shows tensorflow as a package.
In the terminal, when I check for the version of tensorflow, it was the same as in pycharm (0.10.0rc0)
Looks like your CUDA_HOME or LD_LIBRARY_PATH configured correctly in the console, but not in PyCharm. You can check and compare their values, in console do
echo $CUDA_HOME
echo $LD_LIBRARY_PATH
In PyCharm (say, in your main script):
import os
print(os.environ.get('CUDA_HOME'))
print(os.environ.get('LD_LIBRARY_PATH'))
You can configure them for the given Run Configuration in Environment Variables section.
Better approach would be configuring those environment variables globally, so every process in the system would have an access to them. To do that you have to edit /etc/environment file and add original values, which you got from console.
Here are very similar problems: one, two, three.