LoginSignup
4
5

More than 5 years have passed since last update.

さくらインターネットでPython外部モジュールを使う

Posted at

さくらインターネットでPythonを動かせるようになったら外部モジュールも動かしたいところ。ということでやってみた作業を全部書いておこうかと思いまして。必要ない作業もあるかもしれませんが、そこらはわかりません。考えられ得るすべてをやってみた感じ。

ホームディレクトリの.cshrcに以下を追加

setenv PYTHONPATH ~/lib/python

SSHでログインして、

% mkdir -p ~/.local/lib/python2.7

インストールしたいモジュールはwww直下にtmpとかを作ってその中へ。
例としてRequests-OAuthlibをインスコしてみる。

% cd www
% cd tmp
% cd requests-oauthlib-master
% python setup.py install --user

で、CGIで動かすPythonスクリプト本体のヘッダにおまじないを書く。

#!/usr/local/bin/python
# -*- coding: utf-8 -*-
import sys, codecs
sys.stdout = codecs.getwriter("utf-8")(sys.stdout)
from requests_oauthlib import OAuth1Session
import json
import cgi

print "Content-Type: text/html\n"

これでさくらのレンタルサーバーでもTwitterクライアントが作れるようになりましたとさ。めでたしめでたし・・・。

でもまだbottle動かないの・・・。

4
5
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
4
5