I've written a python file and am trying to import it but it's not recognized. The file was saved as gentleboost_c_class.c in C:\User\apps\My documents. I tried to import it like this:

import gentleboost_c_class as gbc

But I get this error:

NameError: name 'gentleboost_c_class' is not defined

gentleboost_c_class.py begins like this:

from sklearn.externals.six.moves import zip
import numpy as np
import statsmodels.api as sm
class GentleBoostC:

.....

It compiles fine. Both files are in the same folder. What am I doing wrong?

有帮助吗?

解决方案

You're getting a NameError, not an ImportError.

So it seems to me that you import your module as gbc, but later try to refer to it as gentleboost_c_class.

If you import the module with

import gentleboost_c_class as gbc

that means it will be available under the global name gbc, but not as gentleboost_c_class.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top