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

I installed ubuntu on my laptop and I installed python, after installing python2.7.5, I tried to run the python script in the terminal, but it said the module was not found, I started loading all modules, but the module was not found yet. After upgrading to python2.7.9, it still said the same thing, so I installed a python iddle shell that imports the modules correctly.

Why is this happening? why is it working on python shell but not in terminal. terminal only recognizes modules like sys, os .. and some built-in modules, but not installed. I would appreciate some help. (I just started using Linux)

enter image description here

+3


source to share


2 answers


It seems that your Python shell is using a diffenrent PYTHONPATH than the python you are running in the terminal. You can check that by typing

import sys
print sys.path

      

in both shells and comparing the two outputs. My guess is that the python output file running in the terminal is missing the installed module paths (modules).

you can solve this by specifying PYTHONPATH in your shell:

export PYTHONPATH=...

      

... means all python shell output paths separated by:



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

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

"

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

ls -a $HOME 

      

shows the file (and many others ;-). This is .file..files are hidden in plain ls.

+3


source


Try installing python again. follow these 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 the 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 unpacking files

./configure
make
sudo make install

      

0


source







All Articles