1

I am receving this error while I am try to run the code (from CMD):

ModuleNotFoundError: No module named 'numbers.hog'; numbers is not a package

enter image description here

Here is the hog.py file code...

from skimage import feature

class HOG:
    def __init__(self, orientations = 9, pixelsPerCell = (8, 8),
        cellsPerBlock = (3, 3), normalize = False):
        self.orienations = orientations
        self.pixelsPerCell = pixelsPerCell
        self.cellsPerBlock = cellsPerBlock
        self.normalize = normalize

def describe(self, image):
    hist = feature.hog(image,
    orientations = self.orienations,
    pixels_per_cell = self.pixelsPerCell,
    cells_per_block = self.cellsPerBlock,
    normalize = self.normalize)

    return hist

...and the main (train.py) which return the error.

from sklearn.svm import LinearSVC
from numbers.hog import HOG
from numbers import dataset
import argparse
import pickle as cPickle


ap = argparse.ArgumentParser()
ap.add_argument("-d", "--dataset", required = True,
    help = "path to the dataset file")
ap.add_argument("-m", "--model", required = True,
    help = "path to where the model will be stored")
args = vars(ap.parse_args())


(digits, target) = dataset.load_digits(args["dataset"])
data = []

hog = HOG(orientations = 18, pixelsPerCell = (10, 10),
    cellsPerBlock = (1, 1), normalize = True)

for image in digits:
    image = dataset.deskew(image, 20)
    image = dataset.center_extent(image, (20, 20))

    hist = hog.describe(image)
    data.append(hist)

model = LinearSVC(random_state = 42)
model.fit(data, target)

f = open(args["model"], "w")
f.write(cPickle.dumps(model))
f.close()

I don't uderstand why it gives me error on module package. numbers is a package, why it don't import it as well (as it seems) ?

enter image description here

UPDATE: tried to put from .hog import HOG and then execute from CMD..It prints:

No module named '__main__.hog'; '__main__' is not a package

Is it crazy ? hog.py is in the main package together with the other files. As you can see, it also contains HOG class.... Can't understand.. Some one can reproduce the error ?

In the IDE console it prints:

usage: train.py [-h] -d DATASET -m MODEL
train.py: error: the following arguments are required: -d/--dataset, -m/--model

This should be correct as soon as it is executed in IDE because the program MUST run in CMD.

UPDATE 2: for who is interested, this is the project https://github.com/VAUTPL/Number_Detection

2
  • Did you try replacing this line "from numbers.hog import HOG" with "from hog import HOG"? Both files are in the same directory after all. Commented Jul 31, 2017 at 9:45
  • It gives me error (red line) writing like this... Commented Jul 31, 2017 at 9:50

3 Answers 3

2



Change from numbers.hog import HOG to from hog import HOG and
change from numbers import dataset to import dataset.

You are already in the "numbers" package so you don't have to precise it again when you import it.
When you type from numbers import dataset, Python will look for a package numbers (inside the actual package) that contains a dataset.py file.

If your train.py was outside the numbers package then you have to put the package name (numbers) before.

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

Comments

0

Important numbers is a python standard package https://docs.python.org/2/library/numbers.html

Check if you are not really importing that package or rename your package to a more specific name.

Also:

It might looks like python doesnt recognize your package.

Open a python shell and write:

import sys
print sys.path

Check if your number path is there.

If it's not there you have to add it.

sys.path.insert(0, "/path/to/your/package_or_module")

10 Comments

Gives me back 'Cannot import name hog'.. but it accept it as a modification of the original "from numbers.hog import HOG"
mm python doesnt recognize your package, I update my answer
I updated my answer. Check if you are not importing python standar number package and rename/add your package to python path
It print the various Python paths and also the "DetectNumbers\numbers" folder/package. I mean, I've already added this project path to the variables main path (of Python..) It's so strange...
I think python is trying to import official number package docs.python.org/2/library/numbers.html. Please rename your package to something else
|
0


Your train.py file is already in the package "numbers", so you don't have to import numbers.

Try this instead:

from hog import HOG

I saw in comment that it gives you "error (red line)".
Can you be more precise, because I don't see errors there.

7 Comments

Excuse me, I am not English and I don't understand "stressed with red lines" and which error ?
s2.postimg.org/ct1fgbund/stressed.jpg ---- it's also possible I am saying it wrong... Ok, underlining..
Just write from hog import HOG, do not import anything else said in other answers or comments (just to see). Can you run your program even if the code is stressed with red lines ? If yes try to do it.
Gives error ---> ModuleNotFoundError: No module named 'numdetect' in CMD, in IDE is usage: train.py [-h] -d DATASET -m MODEL train.py: error: the following arguments are required: -d/--dataset, -m/--model
I don't know what your IDE so I can't help you there. Delete the line "import numdetect" in your code please.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.