How to fix python module import errors in jenkins
<p>I am having module import errors in Jenkins despite setting my path and python path based on questions here on stack overflow</p>

<p>I have tried this</p>

<p><a href="https://stackoverflow.com/questions/12995809/jenkins-putting-my-python-module-on-the-pythonpath?rq=1">Jenkins: putting my Python module on the PYTHONPATH</a></p>

<p>and this</p>

<p><a href="https://stackoverflow.com/questions/28532467/python-module-import-failure-in-jenkins?rq=1">Python module import failure in Jenkins</a></p>

<p>This same command runs on my local machine without any import issues but fails on Jenkins</p>

<h3>The command</h3>

<pre><code>#!/bin/bash

export PYTHONPATH=$WORKSPACE:$PYTHONPATH
export PATH=$WORKSPACE:$PATH
export DJANGO_SETTINGS_MODULE=myapp.settings.test

echo "Working directory: "
pwd

echo "path: "
echo $PATH

echo "Python path: "
echo $PYTHONPATH


/home/adminuser/.virtualenvs/myapp/bin/python myapp/manage.py jenkins --project-apps-tests  --enable-coverage --settings=myapp.settings.test
</code></pre>

<h3>The build error</h3>

<pre><code>Working directory: 
/var/lib/jenkins/jobs/myapp_QA_TESTS/workspace
path: 
/var/lib/jenkins/jobs/myapp_QA_TESTS/workspace/myapp/apps/:/var/lib/jenkins/jobs/myapp_QA_TESTS/workspace:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games
Python path: 
/var/lib/jenkins/jobs/myapp_QA_TESTS/workspace/myapp/apps/:/home/adminuser/.virtualenvs/myapp/bin:/var/lib/jenkins/jobs/myapp_QA_TESTS/workspace:

-------- USING TEST SETTINGS ------

Traceback (most recent call last):
 ......
    File "/var/lib/jenkins/jobs/myapp_QA_TESTS/workspace/myapp/apps/accounts/models.py", line 18, in &lt;module&gt;
        from apps.registration.tokens.token import GenerateToken
    ImportError: No module named registration.tokens.token
</code></pre>

<h3>My file structure</h3>

<p>overview</p>

<pre><code>myapp/
├── apps
│   ├── __init__.py
│   ├── accounts
│   ├── registration
├── myapp
│   ├── __init__.py
│   ├── celery.py
│   ├── settings
│   ├── urls.py
│   └── wsgi.py
├── manage.py
</code></pre>

<p>view into the module directories</p>

<pre><code>myapp/apps/registration/tokens
├── __init__.py
└── token.py

myapp/apps/accounts/
├── __init__.py
├── models.py
</code></pre>

<p>I have tried even appending the workspace directory and the virtualenv path to both PATH and PYTHONPATH, i also even added the module directory to the PATH and PYTHONPATH</p>

<p>I get the same error when i run the command on the server itself. Could this be caused by the fact that my virtualenv was created by admin user, but now Jenkins is trying to use it, But all packages load</p>

<p>How do I fix this import error, any assistance is appreciated</p>