I'm unable to import a Python package. I keep getting the error message "ImportError: No module named name_of_module"

Update: With some help from friends, I hacked together a solution.

First, I ran pip show --files sendwithus from the terminal

This was the output:

Then, I took that “Location” info and manually appended it to the path in the beginning of my code:

import sys
print sys.path

sys.path.append('Users/MacBookAir/anaconda/lib/python2.7/site-packages')

import sendwithus
#the rest of my code

Finally worked!

My original explanation of what I did:


What I’ve done so far:

  1. I used PIP to install a module, sendwithus

  2. When I tried using the package:

    import sendwithus

    #my_code

    I got this error: ImportError: No module named sendwithus

  3. I manually added the path in Komodo (Komodo >> Preferences >> Python >> +)


Komodo >> Preferences


Python



4.Now, Komodo recognizes the package and finds it on the drop-down

5.And yet, I’m still getting the same error.

6.So, I went and tried to append the path using sys.path, thinking maybe it was an issue there.

My code:

import sys
print sys.path
sys.path.append('/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages')

8.No dice. The problem remains.

ImportError: No module named name_of_module

Could it be that Komodo and your terminal were using different Python’s?

I.e. one was using ActivePython, one was using the Mac system Python.

Not sure! How do I check?

In the terminal, type:

which python

and in Komodo, check in the Python preferences page and click on the Use this interpreter menulist - the first Python interpreter is what Komodo uses when it’s set to Find on Path.

Here’s the output:

and

Should I change from “Find on Path” to “user/bin/python” ?

Will that break (or fix) my ability to use PIP?

Sorry if these are noob questions.

Re-reading your answer.

Nevermind, looks like it’s defaulting to “user/bin/python” already since that’s the first one on the list.

It’s best to use the same interpreter (i.e. /Users/Macbook/Air/anaconda/bin/python) in both terminal and Komodo - as that way any python libraries installed by pip on the command line (assuming pip is setup for anaconda/bin/python) should be available to Komodo automatically (for code intelligence and debugging) without having to manually adjust the Python sys.path in your code.

Cheers,
Todd

That makes sense! I get that.

How do I do it? :smile:

Never mind, didn’t see the browse button! :smile:

You got it :smile: