2

I have installed some python packages which I am able to access using IDLE and not through command shell window.

Here is the output from IDLE:

Python 2.7.2+ (default, Oct  4 2011, 20:03:08) 
[GCC 4.6.1] on linux2
Type "copyright", "credits" or "license()" for more information.
==== No Subprocess ====
>>> import whoosh

Here is the output from my terminal:

pradeep@ubuntu:~$ python
Python 2.7.2 (default, Nov 28 2011, 23:56:33) 
[GCC 4.6.1] on linux3
Type "help", "copyright", "credits" or "license" for more information.
>>> import whoosh
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named whoosh

How can I point the terminal python to IDLE python packages? Why is terminal showing 'linux3' where as IDLE showing 'linux2'? Please help me with this path issue. thanks.

Update1:

Thanks all. Like most of you guessed, I have two different versions installed.

My Idle Path shows

['/home/pradeep', '/usr/bin', '/usr/local/lib/python2.7/dist-packages/Whoosh-2.3.0-py2.7.egg', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-linux2', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages/PIL', '/usr/lib/python2.7/dist-packages/gst-0.10', '/usr/lib/python2.7/dist-packages/gtk-2.0', '/usr/lib/pymodules/python2.7', '/usr/lib/python2.7/dist-packages/ubuntu-sso-client', '/usr/lib/python2.7/dist-packages/ubuntuone-client', '/usr/lib/python2.7/dist-packages/ubuntuone-control-panel', '/usr/lib/python2.7/dist-packages/ubuntuone-couch', '/usr/lib/python2.7/dist-packages/ubuntuone-installer', '/usr/lib/python2.7/dist-packages/ubuntuone-storage-protocol']

My terminal path shows:

['', '/usr/local/lib/python27.zip', '/usr/local/lib/python2.7', '/usr/local/lib/python2.7/plat-linux3', '/usr/local/lib/python2.7/lib-tk', '/usr/local/lib/python2.7/lib-old', '/usr/local/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/site-packages']

How do I remove the terminal version and install IDLE version in terminal? Thanks.

1
  • You can try to export PYTHONPATH to point to where whoosh is installed also check your LD_LIBRARY_PATH Commented Nov 30, 2011 at 4:28

4 Answers 4

3

You're running two different Python installs, one dated 10/4/2011 and the other dated 11/28/2011. The second one doesn't have whoosh installed.

Your options are:

  1. Look for the version that IDLE uses and run it from the command-line. To find it, turn on IDLE and run import sys; print sys.executable. That will show you the location of the version with the packages installed.

  2. Or you can beef-up your command-line version by installing those same packages at the command-line (i.e. run python setup.py install for the various packages you want to load.

Sign up to request clarification or add additional context in comments.

Comments

3

Packages are searched in all the directories defined in the python path.

So, if the IDLE and terminal are working differently - means they have difference in their python paths.

So,

Try this : (On both IDLE and terminal)

import sys
print sys.path  # this prints the list of directories in the python path.

Compare the list that you get from both and the extra directory in IDLE will be having whoosh

You can add directories to sys.path like this :

import sys
sys.path.append('/home/user/packages')

Now, all packages in /home/user/packages will be available for import.

7 Comments

This generally happens when you have different python installations, so different sys.path and when you install a new package that gets installed to one of your python installations.
This works, but only temporarily (in my experience). setting PYTHONPATH will make terminal always have the modules available.
I know that would be better - but by this I want him to see what's causing the problem.
@YugalJindle, you are right. How do I remove terminal version and make it point to IDLE version. If I use apt-get remove python, I am not sure which version will get deleted?
I would have removed both.. and then reinstalled the one that I wanted to have. That is the best thing when you want to save time from troubleshooting - When there is nothing to loose.
|
1

You need to make sure PYTHONPATH is set correctly in your ~/.profile or /usr/<user-name>/.profile.

For example (this is for OS X, but just find where Python is installed on your machine):

export PYTHONPATH="/usr/local/lib/python2.7/site-package/:$PYTHONPATH"

Only OS X requires the export prefix, and you can check your current path using echo $PYTHONPATH in terminal.

Once you've changed PYTHONPATH to point to your version of python's package folder, you need to force terminal to update the path using this:

source ~/.profile

Then try echo $PYTHONPATH again and make sure it changed. Then you should be set as long as you pointed to the correct directory.

Comments

0

This is due to path issues. I would recommend using virtual envs and pip as standard when working with packages you've imported or obatined externally.

Some great notes here: https://python-guide.readthedocs.org/en/latest/

Hope this helps.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.