しゅうせいちゅう

CentOS7にAnaconda(Python 2.7)とpyenvをインストール

python3とかpython2.7とか切り替えを便利にするためにpyenvを入れる
加えて、system由来以外のpythonにはAnacondaでpythonパッケージ管理をさせる
pyenvhttps://github.com/pyenv/pyenv
Anacondahttps://www.anaconda.com/

まずはpyenvをインストール

Python3.6.2 on CentOS7

[root@c ~]# cd src/
[root@c src]# curl -O https://www.python.org/ftp/python/3.6.2/Python-3.6.2.tar.xz
[root@c src]# xz -cd Python-3.6.2.tar.xz | tar xf -
[root@c src]# cd Python-3.6.2
[root@c Python-3.6.2]# 
[root@c Python-3.6.2]# export PATH=/sbin:/bin:/usr/sbin:/usr/bin
[root@c Python-3.6.2]# unset LD_LIBRARY_PATH
[root@c Python-3.6.2]# ./configure --prefix=/usr/local/python36
[root@c Python-3.6.2]# make && make test
 (test.test_dtrace.SystemTapOptimizedTestsでエラー発生)
 
[root@c Python-3.6.2]# make install

Python3.3.6 on CentOS7

[root@c ~]# cd src/
[root@c src]# curl -O https://www.python.org/ftp/python/3.3.6/Python-3.3.6.tar.xz
[root@c src]# xz -cd Python-3.3.6.tar.xz | tar xf -
[root@c src]# cd Python-3.3.6
 
[root@c Python-3.3.6]# ./configure --prefix=/usr/local/python33
[root@c Python-3.3.6]# make && make test
 (make test で test_ssl でエラーが発生)
 
[root@c Python-3.3.6]# make install

pip3

[root@c ~]# cd src/
[root@c src]# curl -O https://bootstrap.pypa.io/get-pip.py
[root@c src]# python3 get-pip.py
 
[root@c src]# which pip3
/usr/local/python33/bin/pip3
[root@c ~]# pip3 install constants

python2.7 CentOS6.4

[root@c8 ~]# wget http://www.python.org/ftp/python/2.7.5/Python-2.7.5.tar.bz2
[root@c8 ~]# bzip2 -cd Python-2.7.5.tar.bz2 | tar xf -
[root@c8 ~]# cd Python-2.7.5
[root@c8 Python-2.7.5]# ./configure
[root@c8 Python-2.7.5]# make
  Python build finished, but the necessary bits to build these modules were not found:
  _bsddb             _sqlite3           _ssl
  _tkinter           bsddb185           bz2
  dbm                dl                 gdbm
  imageop            readline           sunaudiodev
  To find the necessary bits, look in setup.py in detect_modules() for the module's name.
 
(今のままだと使えないモジュールはこんだけあるよ。っと言われる。まぁー使うかもしれないので適用にパッケージを追加してmake)
[root@c8 ~]# yum -y install \
       tk-devel tcl-devel \                  *_tkinterが解消される
       readline-devel     \                  *readlineが解消される
       sqlite-devel       \                  *_sqlite3が解消される
       bzip2-devel        \                  *bz2が解消される
       ncurses-devel      \
       openssl-devel      \                  *_sslが解消される
       gdbm-devel         \                  *dbm,gdbmが解消される
       db4-devel                             *_bsddbが解消される
 
[root@c8 Python-2.7.5]# make  
  Python build finished, but the necessary bits to build these modules were not found:
  bsddb185           dl                 imageop   *まぁこのくらいで
  sunaudiodev
 
[root@c8 Python-2.7.5]# make test
[root@c8 Python-2.7.5]# make altinstall

centos5.x

yum install tk-devel tcl-devel readline-devel sqlite-devel bzip2-devel ncurses-devel gdbm-devel openssl-devel
./configure CFLAGS=-fPIC --enable-unicode --enable-shared --prefix=/usr/local/pyton27
make -j4
http://bugs.python.org/issue14572
vi Modules/_sqlite/connection.c
make
make test

mod_wsgi

[root@c ~]# yum -y install mod_wsgi

インストールされるファイルは

/etc/httpd/conf.modules.d/10-wsgi.conf
/usr/lib64/httpd/modules/mod_wsgi.so
/usr/share/doc/mod_wsgi-3.4
/usr/share/doc/mod_wsgi-3.4/LICENCE
/usr/share/doc/mod_wsgi-3.4/README

である。
次に設定ファイルを用意する

[root@c ~]# vi /etc/httpd/conf.d/wsgi.conf
WSGIScriptAlias /wsgi /var/www/wsgi/hello.wsgi
 
[root@c ~]#

次にコンテンツを用意する

[root@c ~]# mkdir -p /var/www/wsgi
[root@c ~]# vi /var/www/wsgi/hello.wsgi
class WsgiHelloWorld(object):
 
    def __call__(self, environ, start_response):
        start_response('200 OK', [('Content-type', 'text/plain')])
        return ['Hello, world!']
 
application = WsgiHelloWorld()
[root@c ~]#

っで、稼動させるが、config確認してから再起動する

[root@c ~]# apachectl configtest
Syntax OK
[root@c ~]# systemctl restart httpd

*wsgi.confは、1つのURLに対して1つのwsgiスクリプトとなる。。URL毎にwsgi.confを修正するのは面倒かな。.htaccessを使えばhttpdの再起動なしにwsgiスクリプトの追加は可能。もっと楽にするにはSetHandlerやらの出番のような

mod_python

yum install httpd-devel
wget http://archive.apache.org/dist/httpd/modpython/mod_python-3.3.1.tgz
gtar xzvf mod_python-3.3.1.tgz
cd mod_python-3.3.1

vi src/connobject.c
140行目あたり
while ((bytes_read < len || len == 0) &&
    - !(b == APR_BRIGADE_SENTINEL(b) ||
    + !(b == APR_BRIGADE_SENTINEL(bb) ||
        APR_BUCKET_IS_EOS(b) || APR_BUCKET_IS_FLUSH(b))) {

./configure --with-python=/usr/bin/python --with-apxs=/usr/sbin/apxs
make
make install

vi conf.d/mod_python.conf
LoadModule python_module modules/mod_python.so
最新の60件
2025-04-27 2025-04-26 2025-04-25 2025-04-24 2025-04-17 2025-04-15 2025-04-13 2025-04-02 2025-04-01 2025-03-31 2025-03-29 2025-03-28 2025-03-27 2025-03-26 2025-03-23 2025-03-22 2025-03-20 2025-03-17 2025-03-16 2025-03-15 2025-03-06 2025-03-03 2025-03-01 2025-02-18 2025-02-17 2025-02-14 2025-02-12 2025-02-03 2025-02-02 2025-01-27 2025-01-26 2025-01-25 2025-01-24 2025-01-23

edit


トップ   編集 差分 履歴 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2022-03-18 (金) 20:07:24