0

I'm trying to make use of some parts of the Source code for statsmodels.iolib.summary2. If I try to run the source code in its entirety I'm getting the error:

ModuleNotFoundError: No module named 'main.table'; 'main' is not a package

This is raised after:

from .table import SimpleTable

From the post What does a . in an import statement in Python mean? I'm able to understand why this error is raised conceptually (at best), but I have no Idea how to work around it.

What I've tried:


From the comments we have:

[...] It basically means the current namespace or package directory

This made me think that it was imported from textwrap, but it doesn't seem that way. Since statsmodels is often imported like import statsmodels.api as sm i thought that it would be a similar thing with Simpletable, so I've tried importing it in different ways and with different combinations of statsmodels and statsmodels.compat.collections since these are also used in the beginning of the source:

from statsmodels.compat.python import (lrange, iterkeys, iteritems, lzip,
                                       reduce, itervalues, zip, string_types,
                                       range)
from statsmodels.compat.collections import OrderedDict
import numpy as np
import pandas as pd
import datetime
import textwrap
from .table import SimpleTable
from .tableformatting import fmt_latex, fmt_txt

I've also tried to install SimpleTable (conda), but I think I'm just way off target here, so any suggestions would be great!

vestland
  • 55,229
  • 37
  • 187
  • 305
  • 1
    Typically it means you `PYTHONPATH` needs to be set so that it contains the directory where your project starts. – Alfe Oct 05 '18 at 09:54
  • 1
    i'm guessing you didn't use the entire module then, only importing that script by copying the file into your project folder? if that's the case you need to make sure that scripts can import its own import requirements `.table` from `table.py`, then `table.py` requirements etc, while retaining the same namespace/structure relationship. if i'm mistaken in that guess then you need to edit your post to provide your script namespace/folder structure to keep others from guessing what namespace situation you have. – deadvoid Oct 05 '18 at 10:22
  • @cryptonome, you are 100% right! But does this mean that `table` is a part of statsmodels since `statsmodels.iolib.summary2` is a part of statsmodels and uses `.` to refer to another element 'within' statsmodels? – vestland Oct 05 '18 at 10:29
  • yes, it wasn't importing foreign module. that `.` in front of `.table` is just a notation for relative path, like in linux/bsd path `..` means parent directory, and `.` means the same dir. – deadvoid Oct 05 '18 at 10:44
  • @cryptonome, Maybe I'm just cementing the fact that I'm missing the point completely here, but shouldn't I then be able to import SimpleTable using `import statsmodels.iolib.table.SimpleTable` since it can be found [here](https://www.statsmodels.org/dev/generated/statsmodels.iolib.table.SimpleTable.html), and I've already got StatsModels installed? I guess not since I can't find anyting named SimpleTable in any of the folders where I've got Anaconda3 installed... But how do I proceed here? Further installations? Or copy SimpleTable from the source and run that first? – vestland Oct 05 '18 at 10:54
  • 1
    you can try `from import statsmodels.iolib.table import SimpleTable` if you've already installed statsmodel via python package manager – deadvoid Oct 05 '18 at 10:58
  • @cryptonome, thank you! That seems to be working perfectly (without that first import though like this: `from statsmodels.iolib.table import SimpleTable`) Would you like to write that up as an answer? – vestland Oct 05 '18 at 11:01

1 Answers1

1

Try from statsmodels.iolib.table import SimpleTable instead if you've already installed statsmodel module via pip/conda. It's a class defined inside statsmodels.iolib.table package/file :)

deadvoid
  • 1,270
  • 10
  • 19