LoginSignup
3
3

More than 3 years have passed since last update.

WSL, UbuntuでPython環境構築を楽したい

Last updated at Posted at 2019-03-17

0. 筆者環境

Windows 10 Home 64bit
Ubuntu 18.04 LTS

1. 概要

WSLでUbuntu環境構築してみたので、その際使用したスクリプトを共有する。
このスクリプトでは一般なOS Update~python環境構築までをサポートしているつもり。

2. 本体+使用法

以下を"setup.sh"として任意のディレクトリに保存し、実行する。

setup.sh

#!/bin/bash


# WSL for Ubuntu setup sh
# WSL有効化(PowerShell管理者権限で実行)
# Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux


# 日本に向けてリポジトリ変更
sudo sed -i -e 's%http://.*.ubuntu.com%http://ftp.jaist.ac.jp/pub/Linux%g' /etc/apt/sources.list

# NTP設定(時刻同期)
sudo ln -sf /usr/share/zoneinfo/Asia/Tokyo /etc/localtime
sudo sed -i 's/#NTP=/NTP=ntp.nict.jp/g' /etc/systemd/timesyncd.conf

# Update
sudo apt update
sudo apt full-upgrade -y
sudo apt autoremove -y
sudo apt clean -y

# 日本語化
sudo apt install -y language-pack-ja
sudo apt install -y manpages-ja
sudo update-locale LANG=ja_JP.UTF-8

# Package Install
sudo apt install -y vim-nox git zsh zsh-syntax-highlighting gcc g++ make openssl zlib1g-dev libssl-dev libbz2-dev libreadline-dev libsqlite3-dev vim build-essential curl wget llvm libncurses5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev
sudo apt install -y python3-pip

# 好みで、
# chsh -s /bin/zsh

# pyenv
git clone https://github.com/yyuu/pyenv.git ~/.pyenv
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(pyenv init -)"' >> ~/.bashrc
source ~/.bashrc
pyenv install 3.7.3
pyenv global 3.7.3
pyenv rehash

# pip Update
pip install --upgrade pip
pip3 install --user pipenv
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc
echo 'export PIPENV_VENV_IN_PROJECT=1' >> ~/.bashrc
source ~/.bashrc

# Python 3.7.2
python -V

3
3
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
3
3