簡體   English   中英

網站使用默認的python解釋器而不是安裝virtualenv解釋器

[英]website using default python interpreter instead of install virtualenv interpreter

我已經在centos上安裝了python 2.7。

我已經創建並激活了與此解釋器關聯的virtualenv。

我的路徑如下所示:

/home/ec2-user/django-venv/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/opt/aws/bin:/home/ec2-user/bin

當我訪問我的網站時,出現以下錯誤,表明它正在使用舊版本的python:

mod_wsgi (pid=19386): Exception occurred processing WSGI script '/var/www/html/-django//wsgi.py'.
 Traceback (most recent call last):
 File "/var/www/html/-django//wsgi.py", line 23, in <module>
   from django.core.wsgi import get_wsgi_application
 File "/usr/lib/python2.6/site-packages/django/core/wsgi.py", line 2, in <module>
   from django.core.handlers.wsgi import WSGIHandler
 File "/usr/lib/python2.6/site-packages/django/core/handlers/wsgi.py", line 11, in <module>
   from django import http
 File "/usr/lib/python2.6/site-packages/django/http/__init__.py", line 2, in <module>
   from django.http.request import (HttpRequest, QueryDict,
 File "/usr/lib/python2.6/site-packages/django/http/request.py", line 11, in <module>
   from django.conf import settings
 File "/usr/lib/python2.6/site-packages/django/conf/__init__.py", line 9, in <module>
   import importlib
 ImportError: No module named importlib

我這樣創建了virtualenv:

virtualenv --python=/usr/local/bin/python2.7 django-venv

然后,我像這樣激活它:

source django-venv/bin/activate

當我啟動“哪個python”時,我得到以下輸出:

~/django-venv/bin/python

我的Apache httpd.conf條目如下所示:

Alias /static/ /var/www/html/django/shared/static/

<Directory /var/www/html/django/shared/static/>
Order deny,allow
Allow from all
</Directory>


WSGIScriptAlias / /var/www/html/django/wsgi.py
WSGIPythonPath /var/www/html/django

<Directory /var/www/html/django>
<Files wsgi.py>
Order deny,allow
Allow from all
</Files>
</Directory>

但是我仍然得到上面的錯誤,它正在使用舊的python版本2.6

我如何讓我的網站使用指向正確位置的virtualenv?

我只使用manage.py startproject生成的wsgi.py文件,然后將以下內容放入我的httpd conf文件中:

WSGIScriptAlias / /full/path/to/wsgi.py
WSGIPythonPath /full/path/to/django/project:/full/path/to/django-venv/lib/python2.7/site-packages

官方文檔對此進行了介紹

如果僅在外殼程序中運行它,則只會影響該外殼程序會話,甚至在兩次登錄之間都不會持續存在,更不用說會影響任何系統范圍的服務,例如Apache。

通常,您會在wsgi.py中放入一些內容:

activate_this = '/path/to/virtualenv/bin/activate_this.py'
execfile(activate_this, dict(__file__=activate_this))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM