[英]Django: use sudo to run server in virtual environment
I got Django set up on my server. 我在服务器上设置了Django。
I have activated my virtual environment and I'm able to run server successfully on port 8000: 我已经激活了虚拟环境,并且能够在端口8000上成功运行服务器:
python manage.py runserver
I would like to use port 80 so I'm able to access (test) my app from outside so I use: 我想使用端口80,以便能够从外部访问(测试)我的应用程序,因此我使用:
sudo python manage.py runserver
But this gives me an error: 但这给我一个错误:
Traceback (most recent call last):
File "manage.py", line 17, in <module>
"Couldn't import Django. Are you sure it's installed and "
ImportError: Couldn't import Django. Are you sure it's installed and available on your PYTHONPATH environment variable? Did you forget to activate a virtual environment?
Can someone please explain why? 有人可以解释为什么吗?
The problem occurs if you create the virtualenv
without the sudo
command, 如果您在不使用
sudo
命令的情况下创建virtualenv
则会出现问题,
virtualenv
is a separate environment available to the user created, virtualenv
是可供创建的用户使用的单独环境,
so if you run python manage.py runserver
without the sudo
command it will run properly, 因此,如果您在不使用
sudo
命令的情况下运行python manage.py runserver
,它将正常运行,
or else install
django
will sudo
right and try sudo python manage.py runserver
否则
install
django
将对sudo
正确并尝试sudo python manage.py runserver
You can try: 你可以试试:
sudo `which python` manage.py runserver
inside your virtualenv to run django from sudo. 在您的virtualenv内部以从sudo运行django。 Hope it helps.
希望能帮助到你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.