Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 15461

How to change the root directory of a Python project?

$
0
0

I have a simple Django project (namely the one from this tutorial).

The main part of the tree looks like this:

.├── env├── proj│  ├── proj│  │  ├── __init__.py│  │  ├── settings.py│  │  ├── urls.py│  │  └── wsgi.py│  ├── api│  │  ├── __init__.py│  │  ├── serializers.py│  │  ├── urls.py│  │  └── views.py│  ├── base│  │  ├── __init__.py│  │  ├── admin.py│  │  ├── apps.py│  │  ├── models.py│  │  ├── tests.py│  │  └── views.py|   ├── __init__.py│  └── manage.py└── README.md 

In the tutorial the outer proj folder is the root.
In api/views.py is the following import: from base.models import Item
When I print sys.path in settings.py, it contains /path/to/wrapper/proj.
But I would like my root folder to be one level higher.

This is what I did:

  • go to Settings> Project structure and change content root to /path/to/wrapper
  • append another .parent to BASE_DIR in settings.py
    (now BASE_DIR = Path(__file__).resolve().parent.parent.parent)
  • prepend proj. to imports
    (now from proj.base.models import Item)

But that does not work: ModuleNotFoundError: No module named 'proj.base'
When I print sys.path in settings.py, it still contains /path/to/wrapper/proj.
Where does that actually come from? And how can I change it?

The only effect of the content root in the settings seems to be on syntax highlighting.
Since I changed it, PyCharm considers imports with prepended proj. as correct.

I already use this structure in a different project (see here).
There it works. But I do not see the difference between the two projects.

EDIT: It was recommended in a comment to change the source root.
But that change had no effect (except that the root folder is now blue).
(Apparently the source root is implicitly the content root, unless specified otherwise.)

enter image description here


Viewing all articles
Browse latest Browse all 15461

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>