# Django settings modules not found? ModuleNotFoundError

**URL:** https://travis-ci.community/t/django-settings-modules-not-found-modulenotfounderror/4681
**Category:** Python
**Created:** [August 11, 2019, 9:11am UTC](https://travis-ci.community/t/django-settings-modules-not-found-modulenotfounderror/4681 "2019-08-11T09:11:21Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Matthias84](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/matthias84/32/2498_2.png) [@Matthias84](https://travis-ci.community/u/Matthias84)
#### Post date: [August 11, 2019, 9:11am UTC](https://travis-ci.community/t/django-settings-modules-not-found-modulenotfounderror/4681/1 "2019-08-11T09:11:21Z")

</div>

Hi, at my first contact with CI I run into troubles while setting up an test coverage analysis. My local test runs fine within it’s virtualenv:  
`coverage run manage.py test --settings papersquirrel.settings.ci .`

But when I setup travis, I get an error:

> ModuleNotFoundError: No module named ‘papersquirrel.settings.ci’

I tried various options and constellations, but it seems that I didn’t understand some aspects of the python path ☹

My project looks like:

```
├── manage.py
├── papersquirrel
│ ├── __init__.py
│ ├── __pycache__
│ ├── settings
│ │ ├── base.py
│ │ ├── ci.py
│ │ ├── example.py
│ │ ├── __init__.py
│ │ └── __pycache__
│ ├── urls.py
│ └── wsgi.py
├── readme.md
├── requirements.txt
├── res
├── squirrel
│ ├── admin.py
│ ├── apps.py
│ ├── forms.py
│ ├── __init__.py
│ ├── management
│ │ └── commands
│ ├── migrations
│ │ ├── __init__.py
│ │ └── __pycache__
│ ├── models.py
│ ├── __pycache__
│ ├── templates
│ │ └── squirrel
│ ├── tests
│ │ └── basic-html.html
│ ├── tests.py
│ ├── urls.py
│ ├── utils.py
│ └── views.py
├── static 

```

My .travis.yml is like this:

```auto
...
env:
  -DJANGO=2.2 DB=sqlite3
  - DJANGO_SETTINGS_MODULE='papersquirrel.settings.ci'

# install requirements
install:
  - pip install -r requirements.txt
  - pip install coveralls

# To run tests
script:
  - coverage run --source=./ manage.py test --settings=papersquirrel.settings.ci
...

```

Can anybody with more env experience pls. point me to my misunderstanding?

---

<div class="post-metadata">

### Author: ![native-api](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/native-api/32/430_2.png) [@native-api](https://travis-ci.community/u/native-api)
#### Post date: [August 11, 2019, 5:23pm UTC](https://travis-ci.community/t/django-settings-modules-not-found-modulenotfounderror/4681/2 "2019-08-11T17:23:18Z")

</div>

My guess is: you need to add the current directory to Python path:

```auto
- export PYTHONPATH="$(pwd)"
- coverage <etc>

```

As per

> <https://stackoverflow.com/questions/6416424/why-does-my-python-not-add-current-working-directory-to-the-path>

you are running `manage.py` through `coverage` – a wrapper over a Python script. So the directory where that wrapper is located is added to `sys.path` instead of the current directory.

---

<div class="post-metadata">

### Author: ![Matthias84](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/matthias84/32/2498_2.png) [@Matthias84](https://travis-ci.community/u/Matthias84)
#### Post date: [August 12, 2019, 4:34pm UTC](https://travis-ci.community/t/django-settings-modules-not-found-modulenotfounderror/4681/3 "2019-08-12T16:34:00Z")

</div>

Unfortunatly, this doesn’t seem to solve my problem 🙁  
I added

> ```
> before_install:
> - export PYTHONPATH=$PYTHONPATH:$(pwd) 
> 
> ```

and checked the variable via echo. It looks good and includes the directory of my project. Also just invoking `python manage.py test` results in this issue …

I also tried to rollout the repo on another server to avoid bugs due local artifacts, but also on that server everything works fine.  
Sorry, but any further ideas?

> **[GitHub - Matthias84/papersquirrel: read-it-later clone for easy selfhosting](https://github.com/Matthias84/papersquirrel)**
>
> read-it-later clone for easy selfhosting. Contribute to Matthias84/papersquirrel development by creating an account on GitHub.

---

<div class="post-metadata">

### Author: ![native-api](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/native-api/32/430_2.png) [@native-api](https://travis-ci.community/u/native-api)
#### Post date: [August 12, 2019, 5:55pm UTC](https://travis-ci.community/t/django-settings-modules-not-found-modulenotfounderror/4681/4 "2019-08-12T17:55:05Z")

</div>

Well, debugging is the further idea. It’s always the same:

- Identify the exact place in the code where the error manifests itself
- Examine the program’s state at that moment to find out which of the values is wrong
- Track the wrong value back to its origin

You can insert debug printing into files if you know how to do that on the fly, or [request debug mode for your project](https://docs.travis-ci.com/user/running-build-in-debug-mode/#enabling-debug-mode) and edit the code by hand or run it under debugger.

---

<div class="post-metadata">

### Author: ![Matthias84](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/matthias84/32/2498_2.png) [@Matthias84](https://travis-ci.community/u/Matthias84)
#### Post date: [August 17, 2019, 5:38am UTC](https://travis-ci.community/t/django-settings-modules-not-found-modulenotfounderror/4681/5 "2019-08-17T05:38:37Z")

</div>

Well, 40+ builds later and trying different ideas, but I didn’t solved the problem yet and I’m close to give up 😭

First I just try to run only the testsuites itself, but n  
All in all, this seems to be a problem with the [import path](https://docs.djangoproject.com/en/2.2/topics/settings/#designating-the-settings), but I checked, that the project root folder and the settings subfolder are on the paths:

```
$ echo $PATH

/home/travis/virtualenv/python3.6.7/bin:/home/travis/bin:/home/travis/.local/bin:/usr/local/lib/jvm/openjdk11/bin:/opt/pyenv/shims:/home/travis/.phpenv/shims:/home/travis/perl5/perlbrew/bin:/home/travis/.nvm/versions/node/v8.12.0/bin:/home/travis/.rvm/gems/ruby-2.5.3/bin:/home/travis/.rvm/gems/ruby-2.5.3@global/bin:/home/travis/.rvm/rubies/ruby-2.5.3/bin:/home/travis/gopath/bin:/home/travis/.gimme/versions/go1.11.1.linux.amd64/bin:/usr/local/maven-3.6.0/bin:/usr/local/cmake-3.12.4/bin:/usr/local/clang-7.0.0/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin:/home/travis/.rvm/bin:/home/travis/.phpenv/bin:/opt/pyenv/bin:/home/travis/.yarn/bin:/home/travis/build/Matthias84/papersquirrel:/home/travis/virtualenv/python3.6.7/bin:/home/travis/bin:/home/travis/.local/bin:/usr/local/lib/jvm/openjdk11/bin:/opt/pyenv/shims:/home/travis/.phpenv/shims:/home/travis/perl5/perlbrew/bin:/home/travis/.nvm/versions/node/v8.12.0/bin:/home/travis/.rvm/gems/ruby-2.5.3/bin:/home/travis/.rvm/gems/ruby-2.5.3@global/bin:/home/travis/.rvm/rubies/ruby-2.5.3/bin:/home/travis/gopath/bin:/home/travis/.gimme/versions/go1.11.1.linux.amd64/bin:/usr/local/maven-3.6.0/bin:/usr/local/cmake-3.12.4/bin:/usr/local/clang-7.0.0/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin:/home/travis/.rvm/bin:/home/travis/.phpenv/bin:/opt/pyenv/bin:/home/travis/.yarn/bin:/home/travis/build/Matthias84/papersquirrel:/home/travis/build/Matthias84/papersquirrel/papersquirrel/settings 

python -c 'import sys; print(sys.path)'

['', '/home/travis/build/Matthias84/papersquirrel', '/home/travis/build/Matthias84/papersquirrel/papersquirrel/settings', '/home/travis/virtualenv/python3.6.7/lib/python36.zip', '/home/travis/virtualenv/python3.6.7/lib/python3.6', '/home/travis/virtualenv/python3.6.7/lib/python3.6/lib-dynload', '/opt/python/3.6.7/lib/python3.6', '/home/travis/virtualenv/python3.6.7/lib/python3.6/site-packages']

```

If I skip the `--settings`parameter, the suite runs as expected, but of course it doesn’t has the right settings to do it’s job.  
I also tried different other approaches, that say it’s a problem of the travis virtualenv or to find my module itself:

- switch to `python3`
- invoke via `python -m`
- create **init**.py at root folder
- try only settings.ci instead
- rename project folder to uniqe name

Any help would be appreciated 😕

---

<div class="post-metadata">

### Author: ![native-api](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/native-api/32/430_2.png) [@native-api](https://travis-ci.community/u/native-api)
#### Post date: [August 17, 2019, 10:15am UTC](https://travis-ci.community/t/django-settings-modules-not-found-modulenotfounderror/4681/6 "2019-08-17T10:15:02Z")

</div>

[A check of file structure and `sys.path` at the time of import](https://travis-ci.org/native-api/papersquirrel/builds/573080606) shows…

… that the 2nd check was unnecessary. There’s no `./papersquirrel/settings/ci.py`. Apparently, you forgot to commit it…

* * *

Update: the link above is now dead. This is what I did there, roughly:

```auto
script:
  - |-
    python -m pdb <path-to-coverage> <args> <<!
    b <faulty_file:faulty_line_that_does_the_import>
    c
    import sys,os
    os.system("ls -Rl")
    p sys.path
    c
    q
    !

```

---

<div class="post-metadata">

### Author: ![Matthias84](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/matthias84/32/2498_2.png) [@Matthias84](https://travis-ci.community/u/Matthias84)
#### Post date: [August 17, 2019, 8:00pm UTC](https://travis-ci.community/t/django-settings-modules-not-found-modulenotfounderror/4681/7 "2019-08-17T20:00:38Z")

</div>

God damnit, you are right! 🦸 My .gitignore blocked the settings file and my test on another server was with a custom local settings file …  
Sometimes it’s the most basic things … thank you very much!
