run Django server by calling subprocess from another Django project
<p>I have two Django projects, <code>foo</code> and <code>bar</code>, and the structures are shown in the following.</p>

<pre><code>/tmp/foo
  - foo
    - __init__.py
    - settings.py
    - urls.py
    - wsgi.py

/tmp/bar
  - bar
    - __init__.py
    - settings.py
    - urls.py
    - wsgi.py
</code></pre>

<p>I tried to run <code>python3 /tmp/bar/manage.py runserver</code> in <code>foo</code>'s environment but failed.</p>

<pre><code>$ python3 /tmp/foo/manage.py shell

&gt;&gt;&gt; import subprocess
&gt;&gt;&gt; subprocess.call(['python3', '/tmp/bar/manage.py', 'runserver'])

Traceback (most recent call last):
  File "/tmp/bar/manage.py", line 10, in &lt;module&gt;
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python3.4/dist-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python3.4/dist-packages/django/core/management/__init__.py", line 302, in execute
    settings.INSTALLED_APPS
  File "/usr/local/lib/python3.4/dist-packages/django/conf/__init__.py", line 55, in __getattr__
    self._setup(name)
  File "/usr/local/lib/python3.4/dist-packages/django/conf/__init__.py", line 43, in _setup
    self._wrapped = Settings(settings_module)
  File "/usr/local/lib/python3.4/dist-packages/django/conf/__init__.py", line 99, in __init__
    mod = importlib.import_module(self.SETTINGS_MODULE)
  File "/usr/lib/python3.4/importlib/__init__.py", line 109, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "&lt;frozen importlib._bootstrap&gt;", line 2254, in _gcd_import
  File "&lt;frozen importlib._bootstrap&gt;", line 2237, in _find_and_load
  File "&lt;frozen importlib._bootstrap&gt;", line 2212, in _find_and_load_unlocked
  File "&lt;frozen importlib._bootstrap&gt;", line 321, in _call_with_frames_removed
  File "&lt;frozen importlib._bootstrap&gt;", line 2254, in _gcd_import
  File "&lt;frozen importlib._bootstrap&gt;", line 2237, in _find_and_load
  File "&lt;frozen importlib._bootstrap&gt;", line 2224, in _find_and_load_unlocked
ImportError: No module named 'foo'
1
</code></pre>

<p>How can I resolve this?  </p>

<p>(I know this behavior doesn't make sense at all, but this is just for the demonstration purpose only.)</p>