how to connect numpy and Pillow skimage to python3.6.1

Answered

I am getting these errors trying to run a python3 program in itelliJ IDEA.

import numpy as np
ModuleNotFoundError: No module named 'numpy'

from PIL import Image, ImageChops
ModuleNotFoundError: No module named 'PIL'

from skimage.feature import match_template # requires numpy, scipy, and six
ModuleNotFoundError: No module named 'skimage'

All of these have been successfully installed using pip3. I have confirmed the installs using IDLE. Clearly there is more to it than simply installing.

6 comments
Comment actions Permalink

Hi Doug! Please check what project interpreter is used in PyCharm: Settings -> Project -> Project Interpreter. I believe you either install these libraries globally and use a different virtualenv (without them) as a project interpreter or vice versa.

0
Comment actions Permalink

Pavel:

I took a look at my settings, at your suggestion. However, I am not knowledgeable enough to see any problems, unless the problems might be in the packages. If that is the case I need to know how to include them. I'm a rookie so things are not as intuitive yet as they may become. Here are some screenshots from the IntelliJ Ultimate IDEA settings windows. Maybe they will help you explain it to me.







 

0
Comment actions Permalink

Thank you for screenshots Doug!

 

It seems I understood what's happening. You have a Python virtual environment setup as project SDK, it is called "Python 3.6". Python Plugin will use this virtual environment to run scripts and will analyse and highlight your code according to the virtual environment Python version and installed packaged. So far so good.

 

Unfortunately as you noticed there is no numpy or pillow packages installed here (forth screenshot). So when you try to execute "import numpy as np" a logical error arise. That's probably because you have installed the desired packages not inside the virtual environment itself but inside the global system interpreter, e.g. "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6".

 

System interpreter and virtual environments normally do not share installed packages. That's the point of virtualenv environment after all - to give you an ability to have an independent interpreter and a set of packages from your system one. For example you may have a lot of projects with different requirements and you may not want to install them globally so they will "pollute" your system and "clash" with each other.

 

When you open the system terminal and use "pip", "python" and "python3" you are calling system interpreter, one can check it with "which python" command which will return a path to the executable. To use a virtual environment instead you need to "activate" it before. This can be done with source "/Users/westcoasthawk/Python 3.6/bin/activate". Each virtual environment has this special "activate" script. After that you will notice that your terminal prompt will change to something like "(Python 3.6) host:~ user$" which is an indicator of activated virtual environment. Now "pip", "python" and "python3" commands are referring to virtual environment and not to system interpreter. You can check again with "which python" command.

 

Now you can install missing packages with pip once again and they will appear in your virtual environment. Python plugin also provides a more easy way to do this, try "Tools -> Manage Python Packages ..." and a little + button at the bottom. There will be a nice UI to install a desired package.

 

I hope my explanations is not over puzzled. Please feel free to ask any questions!

0
Comment actions Permalink

Pavel:

I believe I may have actually understood you, rookie that I am. I am going to try and follow your instructions and I will let you know.

Thank you for the help so far.

Doug

0
Comment actions Permalink

Pavel:

I think I am getting closer, but as you can see from the first screenshot, I am still not quite there. The fourth screenshot shows the packages in the environment. (thank you for getting me that far) I sent the fifth screenshot to show that finder even shows them where they should be.

I am still missing something.




 

0
Comment actions Permalink

Doug:

 

That was a tricky one. Looks like you are editing default project structure. The purpose of this settings is to be used upon new project creation, so you can specify in advance what SDK to use for new projects and so on.

 

We need to adjust project structure of this specific project you have. Try to click this button:

or File -> Project Structure.

 

0

Please sign in to leave a comment.