LoginSignup
0
0

More than 3 years have passed since last update.

WSL で AtCoder 用の環境(Python3)を整える

Last updated at Posted at 2019-05-06

概要

Windows の WSL(Ubuntu)で AtCoder と同じバージョンの Python(3.4.3), numpy(1.8.2), scipy(0.13.3) の環境を構築をするための手引き。

apt で導入できるPython3のバージョンは、AtCoderで利用できるバージョン 3.4.3 ではないので tarball からコンパイルする必要がある。しかし、Ubuntu同梱の openssl のバージョン 1.1.0g と Python 3.4.x の相性が悪いことが知られていて処方が必要。

ざっくりした手順

後から振り返っており かっちりした手順ではないので、疑問等あればコメントください。

  • Step1: WSLの導入
    • ググった通りにやればできる
  • Step2: pyenvの導入
    • pyenv 自体はただの shスクリプトなので前準備は必要ないが git をインストールして clone すると簡単に導入できる。
  • Step3: Python 3.4.3 用インストールスクリプトを実行
    • Pythonをコンパイルするためのパッケージを aptで入れる。
    • pyenv install 3.4.3だと相性の問題でエラーが出るので、StackOverflowで見つけた修正スクリプト(末尾に記載)を使って 3.4.3 をインストールする
  • Step4: AtCoder用のディレクトリを作成
    • 例えば ~/atcoder など
    • pyenv で上記ディレクトリでは 3.4.3 を使うように指示 (pyenv localコマンド)
  • Step5: numpy, scipy の導入
    • 必要なパッケージを apt で入れる
    • sudo apt-get install gcc gfortran python-dev libopenblas-dev liblapack-dev
    • (3.4.3を利用するディレクトリで) pip install numpy==1.8.2pip install scipy==0.13.3
pythonインストールスクリプト.sh
#!/bin/bash -e

# Note by 41semicolon: slightly modified from
# https://stackoverflow.com/questions/50126814/ignoring-ensurepip-failure-pip-requires-ssl-tls-error-in-ubuntu-18-04

# Note: it is a script to solve Ubuntu 18.04 LTS
#       different version of pythons compiling
#       header confliction problems
#
# The idea is got from @JustAnotherArivist
# From URL: https://github.com/pyenv/pyenv/issues/945
#
# The script used in here is with slightly modifications
# to fit many different SSL header versions


# First under your home directory make OpenSSL library
# and extract useful package

mkdir ~/libssl1.0-dev
cd ~/libssl1.0-dev
apt-get download libssl1.0-dev
ar x libssl1.0-dev* data.tar.xz
tar -xf data.tar.xz --strip-components=2


# Second, specifically get your current system's SSL headers
# and make symbolic-links

libcrypto=$(ls /usr/lib/x86_64-linux-gnu/ | grep libcrypto.so......)
libssl=$(ls /usr/lib/x86_64-linux-gnu/ | grep libssl.so......)

ln -s /usr/lib/x86_64-linux-gnu/${libcrypto} ~/libssl1.0-dev/lib/x86_64-linux-gnu
ln -s /usr/lib/x86_64-linux-gnu/${libssl} ~/libssl1.0-dev/lib/x86_64-linux-gnu


# Set your CFLAGS LDFLAGS compile options
# And use pyenv install the python version <3.4.5 or <3.5.3

# Note: it is a one line command
# Please change the version of python that you want to compile
CFLAGS="-I${HOME}/libssl1.0-dev/include -I${HOME}/libssl1.0-dev/include/x86_64-linux-gnu" \
LDFLAGS="-L${HOME}/libssl1.0-dev/lib/x86_64-linux-gnu" \
pyenv install 3.4.3


# Remove tempor libssl1.0-dev direcotory
rm -rf ~/libssl1.0-dev
0
0
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
0
0