kobbycoder
kobbycoder

Reputation: 682

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

Upvotes: 13

Views: 26106

Answers (2)

Peter Paul Kiefer
Peter Paul Kiefer

Reputation: 2124

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.

Upvotes: 13

Yalindre Nuwan
Yalindre Nuwan

Reputation: 11

Try to install python again. follow the steps.

installing dependencies:

sudo apt-get install build-essential
sudo apt-get install libreadline-gplv2-dev libncursesw5-dev libssl-dev  libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev

then download python version you want.

cd ~/Downloads/
wget http://python.org/ftp/python/2.7.9/Python-2.7.9.tgz

tar -xvf Python-2.7.9.tgz
cd Python-2.7.9

after extract files

./configure
make
sudo make install

Upvotes: 0

Related Questions