Reputation: 57196
I am quite confused with how django works. I followed some guides and tested a sample app and got it running on my local dev machine. It works great. But when I moved this sample app to my production server, I got this error:
# cd /var/www/html/helloapp
# python manage.py runserver
Traceback (most recent call last):
File "manage.py", line 8, in <module>
from django.core.management import execute_from_command_line
ImportError: No module named django.core.management
So, during my setup for the sample app, I did this:
$ sudo apt-get install python-django
Then:
$ django-admin startproject helloapp
Then:
$ cd /var/www/html/django-project/helloapp/
Then:
$ python manage.py runserver
Result:
It worked! Congratulations on your first Django-powered page.
So, I transferred the files helloapp/ into my production server:
# cd /var/www/html/helloapp
# python manage.py runserver
Then there is the error:
No module named django.core.management
Do I have to install python-django
in my production server - "globally" as one of my system software in my production server?
What is django.core.management
for actually? There might be many this kind of modules I need to run my app. So are these modules coming from django's "global" then?
If my system broke or I removed python-django
one day, all my django apps will break too?
EDIT:
I got it running with a virtual env instead, but it seems to have problems with gunicorn
:
$ gunicorn helloapp.wsgi
[2017-05-18 22:33:37 +0000] [882] [INFO] Starting gunicorn 19.6.0
[2017-05-18 22:33:37 +0000] [882] [INFO] Listening at: http://127.0.0.1:8000 (882)
[2017-05-18 22:33:37 +0000] [882] [INFO] Using worker: sync
[2017-05-18 22:33:37 +0000] [886] [INFO] Booting worker with pid: 886
[2017-05-18 22:33:37 +0000] [886] [ERROR] Exception in worker process
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/gunicorn/arbiter.py", line 557, in spawn_worker
worker.init_process()
File "/usr/lib/python2.7/dist-packages/gunicorn/workers/base.py", line 126, in init_process
self.load_wsgi()
File "/usr/lib/python2.7/dist-packages/gunicorn/workers/base.py", line 136, in load_wsgi
self.wsgi = self.app.wsgi()
File "/usr/lib/python2.7/dist-packages/gunicorn/app/base.py", line 67, in wsgi
self.callable = self.load()
File "/usr/lib/python2.7/dist-packages/gunicorn/app/wsgiapp.py", line 65, in load
return self.load_wsgiapp()
File "/usr/lib/python2.7/dist-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
return util.import_app(self.app_uri)
File "/usr/lib/python2.7/dist-packages/gunicorn/util.py", line 384, in import_app
__import__(module)
File "/var/www/html/django-project/helloapp/helloapp/wsgi.py", line 12, in <module>
from django.core.wsgi import get_wsgi_application
ImportError: No module named django.core.wsgi
[2017-05-18 22:33:37 +0000] [886] [INFO] Worker exiting (pid: 886)
[2017-05-18 22:33:37 +0000] [882] [INFO] Shutting down: Master
[2017-05-18 22:33:37 +0000] [882] [INFO] Reason: Worker failed to boot.
Upvotes: 1
Views: 1244
Reputation: 6096
Can you confirm you have Django
installed?
sudo pip install django --upgrade
To use virtualenv, first install it
pip install virtualenv
Create a new env (should not be inside the Django project)
virtualenv my_env
Inside this folder, you can activate the env
. bin/activate
Once the env is active, you install django
pip install django
Then go back to the django project and running
python manage.py runserver
should work
Upvotes: 1
Reputation: 779
Yes, you must have django installed on your production server. I personally use virtual environments for this matter, try
sudo apt-get install python-virtualenv
virtualenv env_name
source env_name/bin/activate
Once you have done that you should see the name of your environment written in front of your pwd. This will allow you to install python packages ONLY on that environment. But, of course, you're gonna have to use this in your production server as well...
Upvotes: 1
Reputation: 442
Do I have to install python-django in my production server
Yes, django must be installed on your production server the same way you installed on your development server
Upvotes: 0