Jonathan Teo Joon Yue
Jonathan Teo Joon Yue

Reputation: 95

Cannot import module after installed by pip

I have already installed my wanted module from pip by using pip install but when i open up a program in idle and put import menu it says module not found what did i do wrong, im using python 3.7 and have the latest version of pip.

Upvotes: 2

Views: 15799

Answers (4)

Kai
Kai

Reputation: 1

Step 1: figure out what paths are included in current notebook session

import sys
print(sys.path)

Step 2: figure out where your package is installed

!pip show YOUR_PACKAGE

Make your the path in Step 2 is included in Step 1 list. If not, try:

!pip install --target=d:\some\path\thats\in\step1\list YOUR_PACKAGE

Upvotes: 0

Jacob2309
Jacob2309

Reputation: 91

Just in case someone is meeting a similar problem to mine. Pay attention to the case of the package. In my case, the package is called 'shapely'. And I installed it through

pip install Shapely

But you have to import as

import shapely

Upvotes: 0

Jingnan Jia
Jingnan Jia

Reputation: 1299

I met the same problem, but in my case the package is created by myself. So this answer applyes to the custom packages. See Why customer python package can not be imported? for details.

Upvotes: 0

Sarah Strand
Sarah Strand

Reputation: 119

Python looks for its modules and packages in $PYTHONPATH. You'll need to figure out if the __init__.py module of the package you'd like to use is in python's path. To find out whether it is in python's path, run:

    import sys
    print(sys.path)

within python.

To add the path to your module, run:

sys.path.append("/path/to/your/package_or_module")

and you should be set.

Upvotes: 4

Related Questions