5
6

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.

さくらVPSサーバー上でのPython環境構築

Last updated at Posted at 2017-03-07

環境

CentOS release 6.8

インストールするもの

  • pyenv
  • pip

注意

CentOSのyumはプレインストールされているヴァージョンのPythonでしか動かないみたいです。なので、最新版のPythonをインストールしたらシステムがbreakしちゃうかもしれないのでしない方がいいとのことです。そこで、/usr/local 下にPythonをインストールするという裏技を使うそうです。イカの手順はHow to install the latest version of Python on CentOSに書いてある手順そのままです。

手順

development toolsをダウンロードしなきゃいけないそうです

# Compilers and related tools:
yum groupinstall -y "development tools"
# Libraries needed during compilation to enable all features of Python:
yum install -y zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel expat-devel
# If you are on a clean "minimal" install of CentOS you also need the wget tool:
yum install -y wget

次にPython2と3のソースコードをwgetしてきてそれをコンパイルします

# Python 2.7.13:
wget http://python.org/ftp/python/2.7.13/Python-2.7.13.tar.xz
tar xf Python-2.7.13.tar.xz
cd Python-2.7.13
./configure --prefix=/usr/local --enable-unicode=ucs4 --enable-shared LDFLAGS="-Wl,-rpath /usr/local/lib"
make && make altinstall

# Python 3.6.0:
wget http://python.org/ftp/python/3.6.0/Python-3.6.0.tar.xz
tar xf Python-3.6.0.tar.xz
cd Python-3.6.0
./configure --prefix=/usr/local --enable-shared LDFLAGS="-Wl,-rpath /usr/local/lib"
make && make altinstall

何をしてるのかは分かりませんがこれも一応やっておきました

strip /usr/local/lib/libpython2.7.so.1.0
strip /usr/local/lib/libpython3.6m.so.1.0

続いてpipのインストールですが、そのためのPythonスクリプトがあるようでwgetしてきてそれを実行します。

# First get the script:
wget https://bootstrap.pypa.io/get-pip.py

# Then execute it using Python 2.7 and/or Python 3.6:
python2.7 get-pip.py
python3.6 get-pip.py

これでpip installが使えますね!やったー!

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?