1

Importing some files from the sibling folder works fine but for some files especially it fails with no module found errors. I have tried cleaning up the directories with py.cleanup -p to no success

Here is my folder structure:

plugin_template
  scripts
    __init__.py
    client_simulator.py
    main.py
  tests
    __init__.py
    plugin_flow.py
    plugin_template
  twitter_importer
    __init__.py
    data
      __init__.py
      schema.py
    plugin_flow
      __init__.py
      plugin_flow.py
    importer_handler.py
    importer.py

I get the error while in scripts/client_simulator.py when I import like this

from twitter_importer.plugin_flow.plugin_flow import PluginFlow

I don't get any linter errors while importing but running the script raises

Traceback (most recent call last):
  File "scripts/client-simulator.py", line 1, in <module>
    from twitter_importer.plugin_flow.plugin_flow import PluginFlow
ModuleNotFoundError: No module named 'twitter_importer.plugin_flow'

Yet when I import schema like this it works fine

from twitter_importer.data.schema import Account

I am unable to trace what I am missing.

Anjayluh
  • 1,647
  • 1
  • 13
  • 22
  • @mkrieger1 I think my problem is not the imports failing but rather working for some and failing for others especially newer files – Anjayluh Jun 23 '21 at 15:42
  • The reason why it fails in the one example you've shown is explained in the question I've linked. TL;DR, `plugin_template` is not in `sys.path`, but `plugin_template/scripts` is. Solution: run `python3 -m scripts.client-simulator`, not `python3 scripts/client-simulator.py`. [source](https://stackoverflow.com/a/45149450) – mkrieger1 Jun 23 '21 at 15:43
  • In which file is `from twitter_importer.data.schema import Account`, and how is that file executed? – mkrieger1 Jun 23 '21 at 15:48
  • @mkrieger1 I am running both from twitter_importer.data.schema import Account and from twitter_importer.plugin_flow.plugin_flow import PluginFlow in the same file i.e. scripts/client_simulator.py I am executing using python scripts/client-simulator.py – Anjayluh Jun 23 '21 at 15:50
  • Please show a [mre] with the exact (but minimal) file contents of all relevant files (and only those), and the exact command invocation you use. – mkrieger1 Jun 23 '21 at 15:52

0 Answers0