Ivan Davidov
Ivan Davidov

Reputation: 823

python path during development of a package

Let's say my project structure looks like this:

app/
    main.py
    modules/
        __init__.py
        validation.py
        configuration.py

modules package contains reusable code. main.py executes main application logic.

When I try this in main.py

from modules import validation

I get an error which says that import inside of the validation failed. Validation tries to import configuration and I get 'no module named configuration'

I am using Anaconda distribution on windows.

What is the best way of handling PYTHONPATH during development of the package ?

Is there a way to utilize virtualenv (or conda env) in order to get package, that is in development,on the PYTHONPATH without changing sys.path from the code ?

What is the preferred practice when developing a package ?

I've also tried adding modules (folder) package to the lib/site-packages but it still didn't work.

Upvotes: 4

Views: 519

Answers (1)

Mike Müller
Mike Müller

Reputation: 85482

Change your import in validation.py to:

from . import configuration

This is needed for Python 3 but also works with Python 2.

Upvotes: 1

Related Questions