LoginSignup
1
6

More than 5 years have passed since last update.

python製のSlackbotをレンタルサーバーに作って常用する

Last updated at Posted at 2017-11-23

slackで勤怠管理をしてくれる宮本さんbotがあるのを知り、
http://blog.masuidrive.jp/2014/10/19/miyamoto-san/

pythonで何か作れないかということで、

pythonのslackbotライブラリを使って、ロリポップサーバー上にbotを構築・運用したい。

やるべきこと

1.レンタルサーバ上のpython環境の確認(SSH接続)
2.レンタルサーバに合わせたpythonローカル環境の構築
3.レンタルサーバへのslackbotのインストール
4.botの開発

環境

  • OS:mac OS HighSierra (version:10.13.1)
  • エディタ:PyCharm
  • サーバ:ロリポップ スタンダードプラン
  • pyenv

1.レンタルサーバ上のpython環境の確認(SSH接続)

レンタルしているロリポップサーバにはpythonが使えるとあるので、
SSH接続(macターミナルからの接続)を行なって,python -V でversionをチェックする。

ロリポップのSSH接続についてはこちら
ターミナルからの接続方法はこちら

両方ともロリッポップHPへのリンクです。

この通りの方法を使ってSSH接続。

$ ssh user@host -p ****
user@host password: 
[user@host password ~]$ ls
web
[user@host password ~]$ python -V
Python 3.4.1

こんな感じでpythonのバージョンが確認できた。

この段階であとでslackbotのライブラリは、サーバ上で使うのでインストールする

[user@host ~]$ python -m pip install slackbot --user
Downloading/unpacking slackbot
・・・中略・・・
Successfully installed slackbot slacker websocket-client six requests urllib3 certifi idna chardet
Cleaning up...

で無事インストール完了

2.レンタルサーバに合わせたpythonローカル環境の構築

pyenvを使って、python3.4.1を指定して、ローカルのディレクトリ内に仮想環境を構築する。
pyenvはすでにHomebrewでinstall済み

早速作っていく。

\#pythonバージョンを指定して、pyenvでインストール
mac: user ~$ pyenv install 3.4.1
Downloading Python-3.4.1.tar.xz...
-> https://www.python.org/ftp/python/3.4.1/Python-3.4.1.tar.xz
Installing Python-3.4.1...
patching file ./Lib/ssl.py
patching file ./Modules/_ssl.c
Hunk #1 succeeded at 2014 (offset -2 lines).
Hunk #2 succeeded at 4066 (offset -7 lines).

BUILD FAILED (OS X 10.13.1 using python-build 20160602)

Inspect or clean up the working tree at /var/folders/bh/3j77dyv53c90hmmp167zx9p80000gn/T/python-build.20171123161026.4941
・・・後略

となり失敗。
Mac OS X に Python のインストールを行った際にエラー(BUILD FAILED)が出たのでその対応方法。
があったので、この通りxcode-selectをインストール

mac: user ~$ xcode-select --install

するとウィンドウが開き、インストールするか確認を求められるのでインストール

インストール完了後に改めて、

mac: user ~$ pyenv install 3.4.1
Downloading Python-3.4.1.tar.xz...
-> https://www.python.org/ftp/python/3.4.1/Python-3.4.1.tar.xz
Installing Python-3.4.1...
patching file ./Lib/ssl.py
patching file ./Modules/_ssl.c
Hunk #1 succeeded at 2014 (offset -2 lines).
Hunk #2 succeeded at 4066 (offset -7 lines).
ERROR: The Python ssl extension was not compiled. Missing the OpenSSL lib?

Please consult to the Wiki page to fix the problem.
https://github.com/pyenv/pyenv/wiki/Common-build-problems


BUILD FAILED (OS X 10.13.1 using python-build 20160602)

またエラー
エラーメッセージでググると、どうやらOSがHigh Sierraだとエラーになるようだ。
エラーについて
https://qiita.com/ayihis@github/items/25e752dc5201835bb966
https://github.com/pyenv/pyenv/issues/993

以上を踏まえて、

mac: user ~$ CFLAGS="-I$(brew --prefix openssl)/include" LDFLAGS="-L$(brew --prefix openssl)/lib" pyenv install -v 3.4.1
・・・前略、めちゃくちゃ長いメッセージが出る。
Installed Python-3.4.1 to /Users/murase/.pyenv/versions/3.4.1

でやっと、version3.4.1がインストールできた。

ローカルでアプリを開発するディレクトリまで行って

~$ pyenv local 3.4.1
~$ pyenv version
3.4.1 (set by /Users/murase/Programming/peach/.python-version)

これでこのディレクトリ以下ではシステムのpythonではなく、
python 3.4.1を使うことができるようになった。

こんかいはここまで

1
6
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
1
6