ModuleNotFoundError: No module named 'authorizations'

How can I import a folder using Python in Spyder ?

I currently have the following structure of dir

Gestao
|
|_ Aplicacao
    |
    |_ Autorizacoes

In script

import pandas as pd
import imaplib
import email
import autorizacoes

I can import all libraries except "authorizations". Using Visual Code does not return the error I am getting now.

import autorizacoes

ModuleNotFoundError: No module named 'autorizacoes'

When using Spyder the way to import a folder is different, is there any other way?

Author: Brenda Xavier, 2019-03-21

1 answers

See if it works like this:

1) Create the initial structure (the commands below are for linux)

$ mkdir -p gestao/aplicacao/autorizacoes

2) Create the files __init__.py

$ touch gestao/__init__.py
$ touch gestao/autorizacoes/__init__.py

3) in the permissions folder create and edit a file with the name hello.py and add the following content:

def hellow():
    return 'Hello World!'

4) in the root folder, create the file sayhello.py with the following content:

from aplicacao.autorizacoes.hello import hellow

With the command tree vc you can see the string:

$ tree
.
├── aplicacao
│   ├── autorizacoes
│   │   ├── hello.py
│   │   └── __init__.py
│   └── __init__.py
└── sayhello.py

5) run sayhello.py on the Command:

$ python sayhello.py 

The output should be:

Hello World!

Edited
Reviewing the code in your question, it is not clear if authorizations is a package or a module, if you have doubts about whether it is a package and/or a module, see this answer here in STOpt. In the example code of your question, vc does: import autorizacoes, but if authorizations is a package (a package can be summarized as a directory containing modules), vc should do: import autorizacoes.nome_do_modulo

 1
Author: Sidon, 2019-03-27 21:40:37