I have a script pycharm_test.py
inside my django app universe
in my Django project Finchin
which imports Cashpool
from my own apps and some further modules from 3rd party stellar_sdk
:
# /Users/jonas/PycharmProjects/Finchin/apps/universe/pycharm_test.py
import sys
sys.path.append("/Users/jonas/PycharmProjects/Finchin")
from apps.cashpool.models import Cashpool # doesn't work
from stellar_sdk.asset import Asset # works
from stellar_sdk.keypair import Keypair # works
def test():
print('test')
test()
Now when i run this script in Pycharm using rightclick/run 'pycharm_test'
it raises
/Users/jonas/PycharmProjects/Finchin/venv/bin/python /Users/jonas/PycharmProjects/Finchin/apps/universe/pycharm_test.py
Traceback (most recent call last):
File "/Users/jonas/PycharmProjects/Finchin/apps/universe/pycharm_test.py", line 1, in <module>
from apps.cashpool.models import Cashpool
ModuleNotFoundError: No module named 'apps.cashpool'; 'apps' is not a package
Note: When I remove from apps.cashpool.models import Cashpool
the script runs properly. So somehow the stellar_sdk
imports work.
When I try
..
from cashpool.models import Cashpool
..
it raises
django.core.exceptions.ImproperlyConfigured: Requested setting INSTALLED_APPS, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
This didn't help and I checked the following:
- all dirs have a
__init__.py
- all apps are included in
settings.py
- sys path looks satisfying
- the interpreter is linked to the venv
# settings.py
from pathlib import Path
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
# print(sys.path)
['/Users/jonas/PycharmProjects/Finchin/apps/universe',
'/opt/homebrew/Cellar/python@3.9',
'/Users/jonas/PycharmProjects/Finchin/apps',
'/Users/jonas/PycharmProjects/Finchin',
'/Applications/PyCharm.app/Contents/plugins/python/helpers/pycharm_display',
'/opt/homebrew/Cellar/python@3.9/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python39.zip',
'/opt/homebrew/Cellar/python@3.9/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9',
'/opt/homebrew/Cellar/python@3.9/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/lib-dynload',
'/Users/jonas/PycharmProjects/Finchin/venv/lib/python3.9/site-packages',
'/Applications/PyCharm.app/Contents/plugins/python/helpers/pycharm_matplotlib_backend']
Dirs: