0

I have a django website setup and configured in a python virtual environment (venv) on Ubuntu and all is working fine. Now in order to to run my server on port80 I need to use "sudo" which does not execute in the context of the virtual environment, raising errors (i.e no module named django ...)

Is there a way to get "sudo" to execute in the context of the python virtual environment?!

AmirGh
  • 65
  • 9

4 Answers4

3

No, you don't need to do this. You shouldn't be trying to run the development server on port 80; if you're setting up a production environment, use a proper server.

Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895
  • what do you mean by proper server? was trying to have sudo execute the python for a certain virtual environment (having access to packages not available outside that virtual environment). Is a gunicorn or uwsgi http serving server for example not proper in your book? – AmirGh Jun 16 '16 at 09:00
  • It is, but it still shouldn't be serving on port 80. You need a reverse proxy like nginx. – Daniel Roseman Jun 16 '16 at 09:13
1

As @DanielRoseman said you should not be using the Django development server in production.

But if you need to run the development server on port 80 you have to reference the use the virtual environment python executable directly.

sudo ../bin/python manage.py runserver localhost:80
James Fenwick
  • 2,190
  • 1
  • 20
  • 30
-1

This should be the solution. Even tho I really don't recomment doing this. If you need sudo within Python you are probably on a wrong way.

Community
  • 1
  • 1
Nex
  • 421
  • 1
  • 4
  • 17
-1

this did the trick:

$ sudo -- sh -c './venv-bin-path/activate; gunicorn <params> -b 0.0.0.0:80'
AmirGh
  • 65
  • 9