title: django.setup() giving me ModuleNotFoundError: when ran in pycharm
body: <p>I have setup a django project and an app for that project as per below.
  After I changed the model I am able to makemigration and migrate.
  I can run the server and the admin page displays my app as expected.
  I am able to run python manage.py shell, import and manipulate my models in the shell.</p>
  <p>However when I try to import my model from another python file (in pycharm) I am getting an error stating that the module for my app cannot be found.</p>
  <p>OS:</p>
  <pre><code>Distributor ID: LinuxMint
  Description:    Linux Mint 19.3 Tricia
  Release:    19.3
  Codename:   tricia
  </code></pre>
  <p>IDE</p>
  <pre><code>PyCharm 2020.2.3 (Community Edition)
  Build #PC-202.7660.27, built on October 6, 2020
  Runtime version: 11.0.8+10-b944.34 amd64
  VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
  Linux 5.4.0-52-generic
  GC: ParNew, ConcurrentMarkSweep
  Memory: 1871M
  Cores: 8
  Non-Bundled Plugins: Statistic, com.alayouni.ansiHighlight, com.intellij.ideolog, org.toml.lang, ru.meanmail.plugin.requirements, com.jetbrains.plugins.ini4idea
  Current Desktop: X-Cinnamon
  </code></pre>
  <p>Python:</p>
  <pre><code>python 3.6
  </code></pre>
  <p>Django</p>
  <pre><code>Django==3.1.3
  </code></pre>
  <p>I have read the previous related question: <a href="https://stackoverflow.com/questions/47126025/python-django-modulenotfounderror-no-module-named-restaurants">django-modulenotfounderror-no-module-named-restaurants</a> and <a href="https://stackoverflow.com/questions/47362122/django-modulenotfounderror">django-modulenotfounderror</a> but I think my issue is somewhat different.</p>
  <p>I have not moved files around or change folder names, I really tried to keep it as per the tutorial as possible (I even recreate the exat poll app example from django doc and got the same error).</p>
  <p>I guess this has to do with my environment variables not set properly but I am quite novice in all this and I do not fully know understand what I am supposed to check, how am I suppose to check these and finally how these can be fixed. So I would really appreciate a detailed answer if the issue is related to the environment variables. Thank you!</p>
  <p>In pycharm I have several repos used for that project that are saved in a folder and I usually open that folder containing all the repos in pycharm.
  The repo of interest here is called <strong>'static_data'</strong> and it contains the follwing tree:</p>
  <pre><code>├── backend
  │   ├── manage.py
  │   ├── static_data_app
  │   │   ├── admin.py
  │   │   ├── apps.py
  │   │   ├── migrations
  │   │   │   └── 0001_initial.py
  │   │   ├── models.py
  │   │   ├── tests.py
  │   │   ├── tools
  │   │   │   ├── loading.py
  │   │   │   ├── new_expiry.py
  │   │   │   └── setup.py
  │   │   ├── urls.py
  │   │   └── views.py
  │   └── static_data_project
  │       ├── asgi.py
  │       ├── settings.py
  │       ├── urls.py
  │       └── wsgi.py
  ├── __init__.py
  ├── README.md
  └── test.py
  </code></pre>
  <p>I have setup
  static_data_project/settings.py</p>
  <pre><code>INSTALLED_APPS = [
      'static_data_app.apps.StaticDataAppConfig',
      'django.contrib.admin',
      'django.contrib.auth',
      'django.contrib.contenttypes',
      'django.contrib.sessions',
      'django.contrib.messages',
      'django.contrib.staticfiles',
  ]
  </code></pre>
  <p>Then when I try to run static_data/test.py in pycharm, which has the following code in it:</p>
  <pre><code>import os
  import sys
  import django
  
  os.environ['DJANGO_SETTINGS_MODULE'] = 'static_data.backend.static_data_project.settings'
  django.setup()
  
  from static_data.backend.static_data_app.models import Asset
  
  if __name__ == '__main__':
      my_list = list(Asset.objects.all())
      print(my_list)
  
  </code></pre>
  <p>this is what I got
  (reminder that in pycharm, I have all my repos in a certain folder and that repo of interest here is called <strong>'static_data'</strong>)</p>
  <pre><code>/home/[...]/env/bin/python3.6 /home/[...]/static_data/test.py
  Traceback (most recent call last):
    File &quot;/home/[...]/static_data/test.py&quot;, line 6, in &lt;module&gt;
      django.setup()
    File &quot;/home/[...]/env/lib/python3.6/site-packages/django/__init__.py&quot;, line 24, in setup
      apps.populate(settings.INSTALLED_APPS)
    File &quot;/home/[...]/env/lib/python3.6/site-packages/django/apps/registry.py&quot;, line 91, in populate
      app_config = AppConfig.create(entry)
    File &quot;/home/[...]/env/lib/python3.6/site-packages/django/apps/config.py&quot;, line 116, in create
      mod = import_module(mod_path)
    File &quot;/usr/lib/python3.6/importlib/__init__.py&quot;, line 126, in import_module
      return _bootstrap._gcd_import(name[level:], package, level)
    File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 994, in _gcd_import
    File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 971, in _find_and_load
    File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 941, in _find_and_load_unlocked
    File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 219, in _call_with_frames_removed
    File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 994, in _gcd_import
    File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 971, in _find_and_load
    File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 953, in _find_and_load_unlocked
  ModuleNotFoundError: No module named 'static_data_app'
  
  Process finished with exit code 1
  </code></pre>