I have a project where the main directory is called app. I've add an __init__.py at the root of app and there is a config.py also at the root.
However, when I try to call import app.config or from app import config in the examples.simple_schema.consumer.py or examples.simple_schema.producer.py directory and run the scripts therein I get the error ModuleNotFoundError: No module named 'app'.
├── README.md
├── app
│ ├── __init__.py
│ ├── config.py
│ ├── examples
│ └── simple_schema
│ ├── __init__.py
│ ├── consumer.py
│ └── producer.py
├── requirements.txt
Related
Based from a project with the following structure:
.
└── src/
├── main.py
├── PackageA/
│ ├── __init__.py
│ ├── logic.py
│ ├── SubPackageA1/
│ │ ├── __init__.py
│ │ └── util.py
│ └── SubPackageA2/
│ ├── __init__.py
│ └── otherUtil.py
└── PackageB/
├── __init__.py
└── helpers.py
Project structure
It would be possible to import in the file helpers.py the package otherutil.py?
All the combinations I tried until now fail.
If your program is executed from main.py the import in helpers.py should work like this:
from PackageA.SubPackageA2 import otherUtil
Yes, I checked it, main.py:
from PackageB import helpers
print(helpers.HELPERS_UTIL)
otherUtil.py:
OTHER_UTIL = 'test'
helpers.py
from PackageA.SubPackageA2 import otherUtil
HELPERS_UTIL = otherUtil.OTHER_UTIL
Hello I am trying to develop a few tests with python in order to do this I have the following folder structure:
.
├── Pipfile
├── Pipfile.lock
├── src
│ ├── adapters
│ │ ├── __init__.py
│ │ ├── orm.py
│ │ └── repository.py
│ ├── app.py
│ ├── bootstrap.py
│ ├── db.py
│ ├── domain
│ │ ├── __init__.py
│ └── settings.py
└── test
├── conftest.py
├── __init__.py
├── integration
│ ├── test_orm.py
│ └── test_repository.py
├── pytest.ini
└── unit
├── test_account.py
├── test_client.py
├── test_commerce.py
└── test_move.py
The pytest.ini contains:
[pytest]
pythonpath = src
The tests are launched with the following command:
python -m pytest -s -v test/
The problem is about import, in the conftest.py I have the following code:
import pytest
from sqlalchemy.orm import clear_mappers
from adapters.orm import start_mappers
#pytest.fixture
def mappers():
start_mappers()
yield
clear_mappers()
The line from adapters.orm import start_mappers fails if I doesn't set src before like this from src.adapters.orm import start_mappers
but if do that, the file inside orm module fails, because it has the relative import:
from domain import Move, Account, Client, Commerce
instead of
from src.domain import Move, Account, Client, Commerce
but if I use this, of course, another thing fails, and the idea is not to use src. suffix in the src code.
So how can I solve this, in order to avoid installing src as a python package, or fill all folders with init.py or put src. in all places?
Thanks.
I have this structure for my project:
├── Dockerfile
├── app
│ ├── __init__.py
│ ├── __pycache__
│ ├── config
│ ├── database
│ ├── logging.py
│ ├── main.py
│ ├── routers
│ ├── services
│ ├── static
│ ├── templates
│ ├── utils
│ └── worker
├── k6.js
├── poetry.lock
├── prestart.sh
├── pyproject.toml
├── pytest.ini
└── run.py
Inside app, I have this worker folder that I also open as a kind of separate project.
├── __init__.py
├── database
│ ├── __init__.py
│ └── conn.py
├── engine
│ ├── __init__.py
│ ├── core
│ ├── data
│ ├── main.py
│ └── utils
├── main.py
├── poetry.lock
├── pyproject.toml
└── run.sh
The issue that I have when I open worker project which uses code from upper directory, pylance gives me an error of an import that could not be resolved. However, this code runs fine and perfect.
I created .vscode/settings.json for the worker project and add these options:
"python.analysis.extraPaths": ["../../app"],
"python.autoComplete.extraPaths": ["../../app"]
But I am still getting these errors! How can I fix this?
These paths fixed my issue:
"python.analysis.extraPaths": ["${workspaceFolder}\\..\\.."],
"python.autoComplete.extraPaths": ["${workspaceFolder}\\..\\.."]
I'm working on a flask project which has the following structure:
└──app
├── __init__.py
└── main
├── __init__.py
├── service
│ └── __init__.py (empty file)
│ └── requests_service.py
├─── model
│ └── __init__.py (empty file)
│ └── models.py
└─── util
└── __init__.py (empty file)
└── dto.py
└── requirements.txt
└── .gitignore
IN THE __init__.py INSIDE THE APP FOLDER
from app.main.service.requests_service import RequestsManager
Result:
ModuleNotFoundError: No module named 'app'
In the dto.py inside the util folder
from app.main.model.models import News
Result:
ModuleNotFoundError: No module named 'app'
Basically every module I try to import results in the same error, shown above. I feel like this should be an easy fix, but can't get me head around it. Any help?
This is my structure,I have a django project named kkpro
in kkpro,I have a django app called myapp .
And a scrapy project called project1 inder the kkpro/scrapy/music
├── kkpro
├── manage.py
├── savepage.py
├── myapp
│ ├── __init__.py
│ ├── models.py
│ ├── tests.py
│ └── views.py
└── kkpro
├── __init__.py
├── settings.py
├── urls.py
└── wsgi.py
│── ── scrapy
│ ├──music
│ ├──project1
│ ├── scrapy.cfg
│ ├──project1
│ ├── __init__.py
│ ├── items.py
│ ├── pipelines.py
│ ├── settings.py
this is my project1/settings.py
import sys, os
path_django_site = os.path.join(os.path.dirname(__file__), "../../../../")
sys.path.append(path_django_site)
os.environ['DJANGO_SETTINGS_MODULE'] = 'kkpro.settings'
import save_page
in my computer it works well to used kkpro setting,
but when I deploy to aws eb , import save_page has error
I edit to from kali import save_page. still has error ImportError: cannot import name save_page
What should I do ?
Please help me,thank you very much