Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python modules not found over terminal but on python shell, Linux

I have installed ubuntu on my laptop and i have installed python, after installing python2.7.5 i was trying to run a python script on terminal, but it said module no found, i started to download all the modules but it still said module not found. After upgrading to python2.7.9 it still said same so i installed python iddle shell which is importing the modules correctly.

Why is it happening ? why is it working on the python shell but not on terminal. terminal is only recognizing modules like sys, os.. and some built-in modules but not the installed. I would appreciate the help. (I just started to use linux)

enter image description here

like image 667
kobbycoder Avatar asked May 21 '15 15:05

kobbycoder


1 Answers

It seems that your Python shell uses a diffenrent PYTHONPATH than the python you execute in the terminal. You can verify that by typing

import sys
print sys.path

in both shells and comparing the two outputs. I assume that the installed module path(s) are missing in the output of the python started in the terminal.

you can solve this by defining a PYTHONPATH in your shell:

export PYTHONPATH=...

... means all paths of the python shell's output separated by :

Don't use spaces. If there spaces in one of the paths, surround ... with quotes

export PYTHONPATH="path with spaces:other path:path"

Start python from that terminal where you entered the export command. Try to import your modules. If it works, make the export permanent by appending it in your .profile located in your home directory.

ls -a $HOME 

shows the file (and many others ;-). It is a .file. .files are hidden on a simple ls.

like image 141
Peter Paul Kiefer Avatar answered Oct 09 '22 10:10

Peter Paul Kiefer