Tuesday, November 14, 2017

When terminal is not starting in Ubuntu

Untitled Document.md

When terminal in Ubuntu is not starting

gnome-termial crashes with python 3.6 update.

  • Go to /usr/bin/gnome-terminal
  • Go to the first line and change python3 to python.
  • Install or reinstall the followings

$sudo apt-get install --reinstall python
$sudo apt-get install python3-pyside

Sunday, November 12, 2017

Friday, November 10, 2017

Worth noting fact :

$ sudo apt-get install python3-tk

and

$ sudo apt-get install python3.6-tk

are different. 

If the python system shows "no module named XXX"

you'd better check if it is correctly installed by type in

$ pip3 freeze | grep tkinter

Python: Text file read and write

These are python codes for reading and writing text files:


read and store the lines into list:

def read_and_store(list_path):
with open(list_path) as f:
content = []
for line in f:
line = line.strip().split(' ')
content.append(line)
return content


write the list into a file:

def read_and_write(w_path, list_to_wr):
with open(w_path, "w") as output:
for k, val in enumerate(list_to_wr):
output.write(' '.join(val))
return None

Wednesday, October 21, 2015

Pycaffe installation and trouble shooting

Caffe is a Deep learning framwork from BLVC.
Pycaffe is a Python interface of Caffe framework.
This posting deals with the troubles you might encounter while you are installing Pycaffe.


  1. Caffe install


The like below provides a very detailed installation process. Follow the instructions and install all the dependencies.  




  1. pycaffe install  


But you might have a problem with Ubuntu 14.04 repo.


2.1 make pycaffe


first, go to the directory that Caffe is installed. type this.


$ make pycaffe


2.2 edit ~/.bashrc


PYTHONPATH=${HOME}/python:$PYTHONPATH
2.3 install google protobuff




export PYTHONPATH=${HOME}/python:$PYTHONPATH
export PYTHONPATH="${PYTHONPATH}:/home/inctrl/python"
export PYTHONPATH="${PYTHONPATH}:/home/inctrl/Dropbox/PycharmProjects/caffe-master/python"


2.4 Setup ~/.bashrc as follows


export PYTHONPATH=${HOME}/python:$PYTHONPATH
export PYTHONPATH="${PYTHONPATH}:/home/inctrl/python"
export PYTHONPATH="${PYTHONPATH}:/home/inctrl/Dropbox/PycharmProjects/caffe-master/python"
export PYTHONPATH="${PYTHONPATH}:/usr/lib/python2.7/dist-packages"


PYTHONPATH=${HOME}/python:$PYTHONPATH

JAVA_HOME=/usr/lib/jvm/java
export JAVA_HOME
export PATH=$PATH:/usr/lib/jvm/java-7-openjdk/bin
export JAVA_HOME=/usr/lib/jvm/java-7-openjdk

export PATH=/usr/local/cuda-7.5/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda-7.5/lib64:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda/lib64




3. how to run pycaffe examples with ipython notebook (ipynb)


  • ipython notebook error ?


upgrade it to bradnew version (4.0.0)


  • Tornado Error ?
sudo apt-get remove python-tornado
sudo pip install tornado
  • UsageError: Invalid GUI request u'inline' ?


pycaffe uses matplotlib “inline” feature.
You shoud use “ipython QTconsole”
->ipython qtconsole


qtconsole webpage :


libcuda error shooting :


Thursday, July 16, 2015

CUDA 8.0 and Theano Setup in Ubuntu linux for Deep learning

< CUDA & Theano installation >
TIPS that I’ve realized so far !


4/MAR/2017 Update: updated CUDA 7.5 to CUDA 8.0 and added trouble shooting section.



Before I forget the knowledge and tips from this massive hassle, I think I should write down something right now.


     0. The BEST way to install CUDA&Theano in a nutshell.


  1. Install UBUNTU 14.04. (UBUNTU 16.04)
  2. Download RUN version of CUDA 8.0 toolkit.
  3. Disable Nouveau driver.
  4. Stop X server.
  5. Reboot.
  6. Install full version of CUDA 8.0 toolkit. (Driver, Toolkit, Samples)
  7. Edit .bashrc file to include PATH and LD_LIBRARY_PATH.
  8. Reboot.
  9. Install and update G++/GCC compiler.
  10. Compile CUDA sample and test deviceQuery.  
  11. install Numpy,Scipy,Pip, and Theano
  12. Install OpenBlas.
  13. Make .theanorc file.
  14. Test Theano library.


  1. Install UBUNTU 14.04.


  • Ubuntu is highly recommended for beginners since it has tons of troubleshooting articles on the web. You would find information or guides about Ubuntu easier than any other type of Linux systems.


  • I’m not gonna cover the Installation process of Ubuntu 14.04 here. Instead, you will be able to easily find it by googling it and tons of blog postings are covering Ubuntu installation issues.


  • I also recommend you to install “Anaconda” library. This is one of the easiest way to get all the dependencies that you need to run theano library.


  1. Download RUN version of CUDA 8.0 toolkit.


  • DO NOT download NVIDIA graphics driver from NVIDIA graphics driver download webpage. This will cause a login error. I believe this page (NVIDIA graphics driver download) is solely purposed to support graphic oriented tasks. Forget this page. Don't even click it.


  • Instead of that, refer to this page (CUDA toolkit download). There are two options. You can either select DEB installation or RUN file installation. I recommend RUN file installation because you can choose to opt out of installing the bundle driver and sample files.


  • According to various sources, some people suffer from NVIDIA graphics driver issue so that they should install specific NVIDIA driver which is not included in CUDA toolkit package. However, in my case, that was not the case. Both of my desktop and laptop system didn’t work with seperate driver. Having said that, I metion this issue because some of readers might suffer from this issue. If your system is not working with driver included in CUDA toolkit, refer to this page.


  1. Disable Nouveau driver.


  • I’ve struggled with this issue for ages. The thing is, most of the QNA pages on the web omit this process and I could not find out why does my linux system always show black screen after I reboot the system.


  • This was because of the “Nouveau” driver that crashes with NVIDIA driver. To nip this in the bud before it ruins your mental health, I suggest you a fancy solution with this issue.


  • We have to block Nouveau driver before it crashes with NVIDIA graphics driver. Type the following command.
$ sudo gedit /etc/modprobe.d/blacklist.conf


  • Then, add the following commands to block Nouveau driver.


blacklist nouveau
blacklist lbm-nouveau
options nouveau modeset=0
alias nouveau off
alias lbm-nouveau off

# for other linux distributions
blacklist vga16fb
blacklist rivafb
blacklist nvidiafb
blacklist rivatv


  1. Stop X server.


  • You should kill X server (Ubuntu GUI system) to install graphics related drivers. “ctrl + alt + F1” will lead you to text mode. Type the following command.


$ sudo service lightdm stop


  1. Install full version of CUDA 8.0 toolkit. (Driver, Toolkit, Samples)


  • Go to the folder that you downloaded *.run file. Type the following command.


$ chmod a+x cuda_8.0.44_linux.run
$ sudo ./cuda_8.0.44_linux.run


  • After browsing a long instruction article, you will encounter a few questions as followings. Please carefully read the questions and type your answers as the following.


Do you accept the previously read EULA? (accept/decline/quit): accept
Install NVIDIA Accelerated Graphics Driver for Linux-x86_64 346.46? ((y)es/(n)o/(q)uit): y
Do you want to install the OpenGL libraries? ((y)es/(n)o/(q)uit) [ default is yes ]: n

Do you want to run nvidia-xconfig? This will update the system X configuration file so that the NVIDIA X driver is used. The pre-existing X configuration file will be backed up. This option should not be used on systems that require a custom X configuration, such as systems with multiple GPU vendors. (y)es/(n)o/(q)uit [ default is no ]: n

Install the CUDA 8.0 Toolkit? ((y)es/(n)o/(q)uit): y

Enter Toolkit Location [ default is /usr/local/cuda-8.0 ]: [Enter]

Do you want to install a symbolic link at /usr/local/cuda? ((y)es/(n)o/(q)uit): y

Install the CUDA 8.0 Samples? ((y)es/(n)o/(q)uit): y

Enter CUDA Samples Location [ default is /root ]: [Enter]


  • CAUTION !


DO NOT install OpenGL library. This might cause an error with your graphic driver.  


  1. Reboot.


  • Reboot your system with the following command.


$ sudo reboot


  1. Edit .bashrc file to include PATH and LD_LIBRARY_PATH.


  • If you don’t enroll the directory contains CUDA toolkit, you won’t be able to compile any code based on GPU programming. Add the following commands to ~/.bashrc file.


  • CAUTION : In Ubuntu, there is no file such as ~/.bash_profile. You should edit ~/.bashrc file.


$ sudo gedit ~/.bashrc


  • Once you see the gedit screen, type the following commands, and save it.
export PATH=/usr/local/cuda-8.0/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda-8.0/lib64:$LD_LIBRARY_PATH


  1. Reboot.


  • Reboot your system with the following command.


$ sudo reboot


  1. Install and update G++/GCC compiler.


$ sudo apt-get update
$ sudo apt-get upgrade
$ sudo apt-get install build-essential
$ gcc -v
$ make -v


  1. Compile CUDA sample and test deviceQuery.  


  • This process will check whether  your CUDA library is correctly installed in your Ubuntu system.


~$ cd NVIDIA_CUDA-8.0_Samples
~/NVIDIA_CUDA-8.0_Samples$ make


~/NVIDIA_CUDA-8.0_Samples$ cd bin/x86_64/linux/release
~/release$ ./deviceQuery


  • Another easy way to check out whether your NVIDIA driver is in shipshape manner, you can use the following two commands.


$ nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver Copyright (c) 2005-2016 NVIDIA Corporation Built on Sun_Sep__4_22:14:01_CDT_2016 Cuda compilation tools, release 8.0, V8.0.44

$ nvidia-smi
Tue Jul 14 19:50:26 2015       
+------------------------------------------------------+                       
| NVIDIA-SMI 346.46     Driver Version: 346.46         |                       
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|===============================+======================+======================|
|   0  GeForce 840M        Off  | 0000:0A:00.0     N/A |                  N/A |
| N/A   50C    P0    N/A /  N/A |      6MiB /  2047MiB |     N/A      Default |
+-------------------------------+----------------------+----------------------+
                                                                              
+-----------------------------------------------------------------------------+
| Processes:                                                       GPU Memory |
|  GPU       PID  Type  Process name                               Usage      |
|=============================================================================|
|    0            C+G   Not Supported                                         |
+-----------------------------------------------------------------------------+


  • DO NOT TYPE “sudo apt-get install nvidia-cuda-toolkit”. This command is outdated one and this will lead you to CUDA 5.5 version. And it won’t work either. So, please follow the instruction I’ve written above.


  • You have to be sure with the above two commands. If there is any command that doesn’t pop out the above messages, that indicates that you have a problem with your NVIDIA CUDA driver and compiler.


  1. Install Numpy,Scipy,Pip and Theano


  • Now, we have to install python libraries that is necessary for Theano library. Type the following.


$ sudo apt-get install python-numpy python-scipy python-dev python-pip python-nose g++ git


  • Once you install pip installer, you can easily install Theano library with the following command.


$ sudo pip install Theano


  1. Install OpenBlas.


$ sudo apt-get install libopenblas-dev


  1. Make .theanorc file.


  • “.theanorc” file contains a few configuration for theano library. You should create theanorc file by typing the following command.


$ sudo gedit ~/.theanorc


  • In the Gedit edit window, type the followings and save the file.  


[global]
device=gpu
floatX=float32
root=/usr/local/cuda-8.0
[nvcc]
fastmath = True
[blas]
ldflags = -lopenblas


  1. Test Theano library.
   
  • Go to any directory type the following to make a python file.


$ sudo gedit testing_theano.py


  • Copy and paste this code. Save “testing_theano.py” file.


$ python testing_theano.py


  • If you can get the messages similar to the following messages, Theano library is successfully installed in your computer.


  • Check out if you are getting the message “Using cpu device”. If you get “cpu” message, you should fix your configuration about CUDA and Theano library.
Using gpu device 0: GeForce 840M
[GpuElemwise{exp,no_inplace}(), HostFromGpu(GpuElemwise{exp,no_inplace}.0)]
Looping 1000 times took 1.03167891502 seconds
Result is [ 1.23178029  1.61879349  1.52278066 ...,  2.20771813  2.29967761
 1.62323296]
Used the gpu
CUDA test has been finished


< Trouble Shooting (Updated 4/Mar/2017) >
  • If you are getting a message that says:
"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."
$ sudo apt-get install dkms fakeroot build-essential linux-headers-generic

This was the only command that has solved the problem. 

  •  IF you are getting a message like this: 
"It appears that an X server is running. Please exit X before installation. If you're sure that X is not running, but are getting this error, please delete any X lock files in /tmp."

This means you did not successfully shut down the X. Go back to the step 4 and make sure you surely shut down the X-server(GUI). If you are seeing the Ubuntu GUI, that means you are still having X-server on. 




If you have any question, please mail me to the following address.

When terminal is not starting in Ubuntu

Untitled Document.md When terminal in Ubuntu is not starting gnome-termial crashes with python 3.6 update. Go to /usr/bin/gnome-termi...