3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Debian + Python 3.4 + django1.7 を試す……が

Last updated at Posted at 2014-05-01

振り返ってみるとあまりに馬鹿らしい結末なんですが、一応やったので記録。

やりたかったこと

  • Ubuntu(14.04 LTS)うらやましいなぁ。DebianでもPython 3.4試せないかなぁ
  • ついでにdjango1.7も試してみたいなぁ
  • Debianシステム標準の2系(2.7)は残しておきたいなぁ
  • Debianシステム標準の3系(3.2)も残しておきたいなぁ
  • 特定のdjangoプロジェクトだけPython 3.4でdjango1.7(b3)を使って「わはー」な世界を目指そう
  • Apache2上でバラバラのバージョンで動いたら楽しい!

あるいは「emacsとterminal開いている開発環境本体でとりあえず全部動いていて欲しい」という要望です。

結論から言うと、./manage.py runserverまではいけるものの、mod_wsgiが最後の要望は許してくれません。

参考リンク

作業

  • python3.4.0 をとにかく用意する

  • それをベースにpyvenvを使ってdjango1.7専用世界を作る

  • プロジェクトを作る

  • Apache2のmod_wsgi経由で走らせてわはー

    xbuild/python-install 3.4.0 /opt/python3.4.0
    /opt/python3.4.0/bin/pyvenv /opt/django1.7
    source /opt/django1.7/bin/activate
    (django1.7) > which pip
    /opt/django1.7/bin/pip
    (django1.7) > pip install https://www.djangoproject.com/download/1.7b3/tarball/
    ..
    (django1.7) > pip list
    Django (1.7b3)
    pip (1.5.4)
    setuptools (2.1)
    (django1.7) > cd /opt
    (django1.7) > django-admin.py startproject mysite
    (django1.7) > cd mysite
    (django1.7) > ls
    manage.py mysite
    (django1.7) > ./manage.py syncdb
    ..
    (django1.7) > ./manage.py runserver
    (Visit http://localhost:8000/)

「ここまで動けばとりあえず勝ちだろう。後はapache2の設定だぜ」みたいな気分でいたんですがね。

WSGIDaemonProcess mysite user=www-data group=www-data processes=2 threads=2 \
  maximum-requests=100 umask=0007 \
  python-path=/opt/mysite:/opt/django1.7/lib/python3.4/site-packages
WSGIScriptAlias /mysite  /opt/mysite/mysite/wsgi.py
<Directory /opt/mysite/mysite>
    <Files wsgi.py>
        SetEnv PROCESS_GROUP mysite
        Order deny,allow
        Allow from all
    </Files>
</Directory>    

SQLiteのDBをとりあえずwww-dataから書き込み可能な状態に。

(django1.7) > chmod 777 db.sqlite3
(django1.7) > chmod 777 .
(django1.7) > sudo service apache2 restart

(Visit http://localhost/mysite/admin)

バージョンが本当に3.4になっていることを確信持つためにurls.pyとviews.pyをちょっとだけ変更

urls.py
from django.conf.urls import patterns, include, url
from django.contrib import admin

urlpatterns = patterns('',
    # Examples:
    # url(r'^$', 'mysite.views.home', name='home'),
    # url(r'^blog/', include('blog.urls')),

    url(r'^admin/', include(admin.site.urls)),
    url(r'^$', 'mysite.views.home', name='home'),
)
views.py
from django.http import HttpResponse
import sys

def home(request):
    return HttpResponse(str(sys.version_info), content_type="text/plain")

結果

(venv activate済で) ./manage.py runserverから走らせると

sys.version_info(major=3, minor=4, micro=0, releaselevel='final', serial=0)

apache2 + mod_wsgiで走らせると

sys.version_info(major=3, minor=2, micro=3, releaselevel='final', serial=0)

にょろーん…… (libapache2-mod-wsgi-py3 を入れてないと、ここが 2.7系を示すアレになってさらにショックが大きい)

apache2のログは全てを語っている。

[Thu May 01 17:01:31 2014] [notice] Apache/2.2.22 (Debian) mod_auth_tkt/2.1.0 PHP/5.4.4-14+deb7u9 mod_ssl/2.2.22 OpenSSL/1.0.1e mod_wsgi/3.3 Python/2.7.3 configured -- resuming normal operations
[Thu May 01 17:04:01 2014] [notice] caught SIGTERM, shutting down
[Thu May 01 17:04:02 2014] [warn] mod_wsgi: Compiled for Python/3.2.2rc1.
[Thu May 01 17:04:02 2014] [warn] mod_wsgi: Runtime using Python/3.2.3.

そこか orz

mod_wsgiを複数持つとかは多分有り得ないので、Apacheも別途持たなければならないとかいうことに。
そこまでやるならdockerとかkvmとか使うよな。
ただ、そうやってOS分裂させると、設定ファイルも四方八方に分裂するので、最初の要望からは程遠いということに。

追記

tornado + apacheからのリバースプロキシではどうかというアイディアいただきました。ここまでトルネードを知らなかった事実に身震いが

いやしかしxbuildもpyenvも今日知ったもんだからな。仕方ないな。

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?