1

I have the following structure:

edgar_sec
│   ├── __init__.py
│   ├── logs
│   ├── requeriments.txt
│   ├── resources
│   │   ├── __init__.py
│   │   ├── us_states.py
│   │   └── us_stocks_symbol.csv
│   ├── scripts
│   │   ├── __init__.py
│   │   ├── company_info.py
│   │   ├── financial_reports.py
│   │   └── insiders.py
│   └── tests
│       ├── __init__.py
│       ├── company_info_test.py
│       ├── company_info_test2.py
│       └── sec_insiders.py

I want to import us_states.py into company_info_test2.py, so I'm doing import edgar_sec.resources.us_states but I'm getting ModuleNotFoundError: No module named 'edgar_sec' What is wrong?

3
  • Only a guess. Have you tried from edgar_sec.resources import us_states? Commented Jul 6, 2020 at 15:40
  • @nomansland008 same error ModuleNotFoundError: No module named 'edgar_sec' Commented Jul 6, 2020 at 15:43
  • 1
    You might have better luck with kruserr answer. It seems the tests folder is not "seeing" its parent folder. Commented Jul 6, 2020 at 15:47

1 Answer 1

0

Try to put tests outside of package

And also tests don't need to be a package

eg.

edgar_sec
│   ├── __init__.py
│   ├── logs
│   ├── requeriments.txt
│   ├── resources
│   │   ├── __init__.py
│   │   ├── us_states.py
│   │   └── us_stocks_symbol.csv
│   ├── scripts
│   │   ├── __init__.py
│   │   ├── company_info.py
│   │   ├── financial_reports.py
│   │   └── insiders.py
└── tests
    ├── company_info_test.py
    ├── company_info_test2.py
    └── sec_insiders.py

Also I see that the project does not follow a standard approach to packaging python applications.

You may have better luck following this tutorial on packaging your python projects:

https://packaging.python.org/tutorials/packaging-projects/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.