3

I'm new to python and I'm having an issue importing a module that imports numpy,PIL and os packages. I'll try and be as clear as possible with my problem

So I have a module lets call it preprocessing.py in which I've written a class to process an image imported from PIL using Image and converting it to a numpy array so the structure looks like the following (note method1 converts a jpg to numpy array)

----- preprocessing.py

import numpy as np
import os 
from PIL import Image

Class process_object:
   method1

Now I want to use this module as follows I want to import process_object from preprocessing.py and use method1 to process an image again imported using Image in PIL. So my script computation.py looks like the following

---computation.py

import os
import numpy as np
from PIL import Image

a = process_image(input)
a.method1()

However, when I do this I get the following error message

ImportError: No module named numpy

Could someone explain to me what is going on and how to fix it? I'd really appreciate an explanation which allows me to understand what is going on under the hood, so I can avoid situations like this. I really appreciate any help! Thanks!!

2
  • 4
    You don't have numpy installed? Commented Oct 31, 2018 at 15:45
  • Do you have numpy package in your python module? Commented Oct 31, 2018 at 15:47

2 Answers 2

1

Check in which version of Python pip is installing numpy. It could be that when pip installs it, it's pointing to a different Python version on your system.

For problems like these, I would recommend using:

https://github.com/pyenv/pyenv-virtualenv

Will handle Python versions for you, so that you can differentiate which packages are being installed.

I will also recommend using PyCharm's Community Edition.

https://www.jetbrains.com/pycharm/download

Excellent tool and lets you create your own environment.

Hope this helps.

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

Comments

0

https://sourceforge.net/projects/numpy/files//NumPy/1.5.0/NOTES.txt/view. This is the support for numpy in Python 3.0. You probably need a newer version of numpy. You can also use:

pip install numpy

or

pip3 install numpy

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.