0

I am looking at this script:

https://github.com/gboeing/osmnx/blob/master/osmnx/stats.py

On line 15, there is this:

from .simplify import clean_intersections

I tried to import it but got this message:

ModuleNotFoundError: No module named '__main__.simplify'; '__main__' is not a package

I tried to search for the package on conda, I couldn't find anything.

How do I proceed?

I get a similar message for lines 16-20, eg:

from .utils import log

returns:

ModuleNotFoundError: No module named '__main__.utils'; '__main__' is not a package

william3031
  • 1,653
  • 1
  • 18
  • 39
  • 2
    That is not a script. You are not supposed to run it like a script. You are having this problem because you're trying to run it like a script. – user2357112 Nov 15 '18 at 23:22
  • So what do I do then? Sorry, I am new to this. – william3031 Nov 15 '18 at 23:23
  • 1
    Install OSMnx, `import osmnx`, and do whatever task you wanted to use OSMnx to do. – user2357112 Nov 15 '18 at 23:25
  • There are instructions on the website. – user2357112 Nov 15 '18 at 23:26
  • I already have osmnx installed and imported. I have already defined the street network. I am trying to run this to calculate the stats. – william3031 Nov 15 '18 at 23:26
  • So what does `__main__` refer to? – william3031 Nov 15 '18 at 23:27
  • @SuperShoot I did look at that one, but I thought that my problem was different. But maybe it is because I don't know what `__main__` is referring to. – william3031 Nov 15 '18 at 23:29
  • Here is python doc for `__main__` https://docs.python.org/3/library/__main__.html – SuperShoot Nov 15 '18 at 23:29
  • Thanks. So do you know why it doesn't work in my instance? Do you know how I can fix it? Because I don't. – william3031 Nov 15 '18 at 23:31
  • But basically, as far as python is concerned, the module that you are executing from the command line is called `__main__`, not the name of the module. Any module that you import into the module that you execute from within is called whatever it's filename is. – SuperShoot Nov 15 '18 at 23:31
  • Yep, that is library code, not application code. It's not made to be executed from within the module that it is defined in. In another module do `from osmnx.stats import basic_stats` (for example, but import whatever function you want). – SuperShoot Nov 15 '18 at 23:32
  • If you understand the answers to this question: https://stackoverflow.com/questions/14132789/relative-imports-for-the-billionth-time you'll have it covered. – SuperShoot Nov 15 '18 at 23:33
  • Thanks. Will read. – william3031 Nov 15 '18 at 23:37
  • 1
    The comments here seem to answer this question pretty thoroughly. I want to add that if you're interested in working with OSMnx, you first might want to read through the installation instructions, documentation, and examples here: https://osmnx.readthedocs.io/en/latest/ – gboeing Nov 19 '18 at 17:38

0 Answers0