Skip to content
Advertisement

How to import package in module

I’m new to Python, and I try to structure my Python application.
Given the following directory structure:

JavaScript

Right now, the application is executed using the following command:

JavaScript

When I try to execute the application using

JavaScript

The following error is raised:

JavaScript

Unit tests are being executed using:

JavaScript

This works fine and without issues. Now, I’m trying to use the import the token / type.py file in the app.py file.

The contents of this file are:

JavaScript

The following import statement is added in the app.py file:

JavaScript

Running the application right now yields the following error:

JavaScript

Any ideas on how this can be fixed?

Advertisement

Answer

app/ itself isn’t a package -since it doesn’t include a __init__ file-. app/ is root of the application, while the package’s path starts with lexer. So, change

JavaScript

to

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement