| ページ一覧 | ブログ | twitter |  書式 | 書式(表) |

MyMemoWiki

CentOS6にPython2.7をインストール

提供: MyMemoWiki
2020年2月15日 (土) 07:30時点におけるPiroto (トーク | 投稿記録)による版 (ページの作成:「==CentOS6にPython2.7をインストール== [CentOS][Python] *http://www.petitec.com/2013/04/centos6%E3%81%ABpython2-7%E3%82%92%E5%85%A5%E3%82%8C%E3%82%8B/ *http://…」)
(差分) ← 古い版 | 最新版 (差分) | 新しい版 → (差分)
ナビゲーションに移動 検索に移動

CentOS6にPython2.7をインストール

[CentOS][Python]

インストール

ダウンロード

$ wget http://www.python.org/ftp/python/2.7.5/Python-2.7.5.tar.bz2
$ wget https://www.python.org/ftp/python/2.7.8/Python-2.7.8.tgz

各種ライブラリインストール

  • 必要に応じ、各種ヘッダファイルを事前にインストールしておく。
  • 後で必要な場合、インストール後、Python2.7 をリビルドする
以下のようなエラーとなる
>>> import glib
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named glib

gccが入っていない場合、インストール

# yum install gcc

bzip2-devel

# yum install bzip2-devel

zlib-devel

zlib-devel がインストールされていないと、後のPyPIのインストールで失敗するため、事前に入れておく

# yum install zlib-devel

openssl

SSLが使えるようにしておかないと、PIPのインストールでエラーになる。>>> import ssl でエラーになる場合、インストールされていない

  • opensslの場所を確認、/usr 以下に存在
# whereis openssl
openssl: /usr/bin/openssl /usr/lib/openssl /usr/share/man/man1/openssl.1ssl.gz
openssl-devel のインストール
# yum install openssl-devel
Setup.dist の SSL のコメントを外す
# cd Python-2.7.5
# cd Modules/
# vi Setup.dist

Setup.dist の編集

  • 上記で確認した、SSL=/usr に編集
# Socket module helper for SSL support; you must comment out the other
# socket line above, and possibly edit the SSL variable:
# SSL=/usr/local/ssl
  SSL=/usr
 _ssl _ssl.c \
        -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
        -L$(SSL)/lib -lssl -lcrypto

sqlite

Python をソースからインストールすると sqlite3 とかいろいろモジュールのインポートに失敗する

# yum install -y sqlite-devel.i686

python 本体のインストール

Configure

$ tar xvf Python-2.7.5.tar.bz2 
$ su
# cd Python-2.7.5
# ./configure --prefix=/usr/local

make & install

altinstall を使うこと。make installだと、既存のものと衝突してしまう

# make && make altinstall

確認

  • /usr/local/bin/python2.7 にコマンドがインストールされる
# python2.7
Python 2.7.5 (default, Aug  4 2013, 09:03:22) 
[GCC 4.4.6 20110731 (Red Hat 4.4.6-3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>

PyPI(Python Package Index)

  • Pythonの公式のサードパーティソフトウェアリポジトリ
  • Python WindowsにPIPをインストール

ダウンロードとインストール

# wget https://pypi.python.org/packages/source/d/distribute/distribute-0.6.9.tar.gz
# tar xvf distribute-0.6.9.tar.gz 
# cd distribute-0.6.9
# python2.7 setup.py install

EasyInstallが使えるようになるので、PIPをインストール

# easy_install-2.7 pip

2.7.9、または3.4 からは、pip は同梱されている。pipをセキュアにインストールするには、以下からget-pip.py を入手し、実行

# python2.7 get-pip.py

Django

  • Django インストール 1.5.1

Python IDEをCentOSで利用する

  • Python IDEをCentOSで利用する