1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] Python config ImportError

Discussão em 'Python' iniciado por Stack, Julho 11, 2025.

  1. Stack

    Stack Membro Participativo

    I am working on a python project and whose directory structure looks like this,

    SEC-Edgar
    ├── SECEdgar
    │ ├── __init__.py
    │ ├── companylist.txt
    │ ├── crawler.py
    │ ├── crawler.pyc
    │ ├── data.txt
    │ └── test.py
    ├── config.py
    ├── requirements.txt
    └── setup.py


    I am trying to use config module inside crawler.py but it is giving an ImportError.

    Traceback (most recent call last):
    File "SECEdgar/test.py", line 3, in <module>
    from crawler import SecCrawler
    File "/Users/rahul/Code/SEC-Edgar/SECEdgar/crawler.py", line 9, in <module>
    from config import DEFAULT_DATA_PATH
    ImportError: No module named config


    The import statement in crawler.py is

    from config import DEFAULT_DATA_PATH


    I am not able to understand how import works in python, particularly when it comes to different directories like importing from root to base directory.

    Do I need to add __init__.py on root directory also, so that it becomes a package and then use . to import it?

    Is there a better way to handle import or am I missing some fundamentals here?

    Continue reading...

Compartilhe esta Página