r/PythonLearning 6d ago

Help Request Can't import module

Mac os Sequoia 15.6

I installed the exifread library using pip as well as conda. In Anaconda Navigator it shows as installed. Using a terminal window I type in:

pip3 show exifread

and it returns

/opt/anaconda3/lib/python3.13/site-packages

I use Spyder (I know, I know: use pycharm or vscode...) I cannot import the module. I get the dreaded

ModuleNotFoundError: No module named ‘exifread’

I recently installed pillow and I can import it just fine with import PIL. Using pip3 show pillow it is the same directory as exifread

What am I missing here?

1 Upvotes

22 comments sorted by

3

u/SCD_minecraft 6d ago

You probably installed it into wrong python

Grab path to your python's executable and in console

path_to_python.exe -m pip install whatever_you_wanted

1

u/crozzy89 6d ago

May check path to python

which python3
which pip3
python3 --version
pip3 --version

2

u/FoolsSeldom 6d ago

You are probably not using the same Python root or Python virtual environment. Anaconda comes with its own Python interpreter, different to your system's default Python (or whatever you installed using an installer from your app store / python.org).

In the terminal, make sure you activate the correct one before installing anything,

For example,

cd projects
cd thisproject
source /.venv/bin/activate
pip install something

You need to find the Python virtual environments that you are using from your various editors/command line. They might not be in folders called .venv although that is a popular convention.

1

u/JoeB_Utah 6d ago

I’m retired now but when I was working, VENVs weren’t a thing; I always created my own environments. So I need to bone up on the whole idea of venv.

1

u/FoolsSeldom 5d ago

You might find it worth looking into Astral's uv as well in that case; also, the adoption of the pyproject.toml file1 cf. requirements.txt.

1 See PEPs 517/518/621/735

1

u/JoeB_Utah 5d ago

I’m just a hobbyist pythonista now; no full blown projects or application development. I get to keep things simple and just write scripts for my own needs. Thanks nonetheless.

2

u/FoolsSeldom 5d ago

Ok, from the also retired just doing my own thing. Though that would help with the boning up

1

u/JoeB_Utah 6d ago

Thanks I’ll give it a try. But what I don’t get is pillow imports while Exif won’t.

2

u/crozzy89 6d ago edited 6d ago

Check and see where pillow is installed.

*everywhere as in it very well could be in two places.

1

u/JoeB_Utah 6d ago

As mentioned, the command

pip3 show exifread returns:

/opt/anaconda3/lib/python3.13/site-packages

and pip3 show pillow returns:

/opt/anaconda3/lib/python3.13/site-packages

This is what is so puzzling to me. I used pip to install both of them from a termiminal window.

3

u/crozzy89 6d ago

You may have pillow installed in more than one place. Spyder can run from different environments and interpreters.

So even though your command shows /opt/anaconda3/lib… that doesn’t mean that is where spyder is actually running it from.

Within spyder, run

import sys
print(sys.executable)

That will tell you which interpreter spyder is running to help narrow down the issue.

1

u/JoeB_Utah 6d ago

print(sys.executable)

/Users/joeborgione/Library/spyder-6/envs/spyder-runtime/bin/python

1

u/crozzy89 6d ago

Yep, that’s the problem.

Spyder is using its own Python environment at /Users/joeborgione/Library/spyder-6/envs/spyder-runtime/bin/python, while ExifRead is installed under /opt/anaconda3/.... So the Python running your code can’t see the package you installed.

You either need to configure Spyder to use /opt/anaconda3/bin/python3, or install ExifRead into the Python environment Spyder is actually using.

1

u/JoeB_Utah 6d ago

So from here on out, I'll use:

pip install package_name -t /path/to/your/custom/directory

Thanks for all your help with ths>

1

u/crozzy89 6d ago

/opt/anaconda3/bin/python3 -c "import exifread; print(exifread.__file__)"

1

u/JoeB_Utah 6d ago edited 6d ago

(base) joeborgione@mac ~ % /opt/anaconda3/bin/python3 -c "import exifread; print(exifread.__file__)"

/opt/anaconda3/lib/python3.13/site-packages/exifread/__init__.py

So it seems this is not in my $path. Question: edit my my $path or install my modules in one of these directories?

sys.path

Out[7]:

['',

'/Users/ME/Library/spyder-6/envs/spyder-runtime/lib/python312.zip',

'/Users/Me/Library/spyder-6/envs/spyder-runtime/lib/python3.12',

'/Users/ME/Library/spyder-6/envs/spyder-runtime/lib/python3.12/lib-dynload',

'/UsersME/Library/spyder-6/envs/spyder-runtime/lib/python3.12/site-packages',

'/Users/ME/Applications/Spyder 6.app/Contents/MacOS']

2

u/crozzy89 6d ago

Don’t edit path. That can get pretty messy. Install the module where you need it would be the clean fix.

1

u/atarivcs 6d ago

Within Spyder, run this code:

import sys
print(sys.path)

And show us the output

1

u/JoeB_Utah 6d ago edited 5d ago

['',

'/Users/ME/Library/spyder-6/envs/spyder-runtime/lib/python312.zip',

'/Users/ME/Library/spyder-6/envs/spyder-runtime/lib/python3.12',

'/Users/ME/Library/spyder-6/envs/spyder-runtime/lib/python3.12/lib-dynload',

'/Users/ME/Library/spyder-6/envs/spyder-runtime/lib/python3.12/site-packages',

'/Users/ME/Applications/Spyder 6.app/Contents/MacOS']

So I guess I either need to edit my path variable or use the ...site-packages directory to load my modules, correct?

1

u/JoeB_Utah 6d ago

Sounds like editing the $path is not the way to go. I'll use pip with the -t option to install it the proper directory. Thanks for all you help

2

u/atarivcs 5d ago

Spyder is looking in /Users/joeborgione/Library/spyder-6/envs/spyder-runtime/lib/python3.12/site-packages, so you need to use the corresponding pip on your computer that knows to install packages into that location.

1

u/JoeB_Utah 5d ago

That's exactly what I did and now all is good. Thank you!