LoginSignup
6
7

More than 3 years have passed since last update.

xserverにpythonをインストールしてpipを使えるようにする

Posted at

目的

Xserverは管理者権限がないので

  • Python2.7.x /usr/bin/python
  • Python3.4.x /usr/bin/python3.4
  • Python3.6.x /usr/bin/python3.6

が入っているが、パッケージ管理のpipがない&インストールできない

やったこと

Linuxbrewをインストールしてbrewでpythonを入れる

Linuxbrewをインストール

適当なディレクトリで

sh -c "$(curl -fsSL https://raw.githubusercontent.com/Linuxbrew/install/master/install.sh)"

以降 XXXXX は Xserverでの自アカウントと置き換えてください

...
==> Select the Homebrew installation directory
- Enter your password to install to /home/linuxbrew/.linuxbrew (recommended)
- Press Control-D to install to /home/XXXXX/.linuxbrew
- Press Control-C to cancel installation
[sudo] XXXXX のパスワード:

と聞かれるので、 Control-D でアカウント配下のディレクトリにインストールする

しばらくダウンロード、インストールが動く...

インストールが完了すると以下のように Next steps とアドバイスされるのでそのとおり実行していく

==> Next steps:
- Run `brew help` to get started
- Further documentation: 
    https://docs.brew.sh
- Install the Homebrew dependencies if you have sudo access:
    sudo yum groupinstall 'Development Tools'
    See https://docs.brew.sh/linux for more information
- Add Homebrew to your PATH in /home/XXXXX/.bash_profile:
    echo 'eval $(/home/XXXXX/.linuxbrew/bin/brew shellenv)' >> /home/XXXXX/.bash_profile
    eval $(/home/XXXXX/.linuxbrew/bin/brew shellenv)
- We recommend that you install GCC:
    brew install gcc

以下コマンドを実行。
gccはlinuxbrew入れるときに入っているがrecommendしてくれてるので念の為。

echo 'eval $(/home/XXXXX/.linuxbrew/bin/brew shellenv)' >> /home/XXXXX/.bash_profile
eval $(/home/XXXXX/.linuxbrew/bin/brew shellenv)
brew install gcc

Python3系を入れる(マイナーバージョンは今回指定しなかった)

brew install python3

インストールしたら3.8.5が入りました。

$ python3 --version
Python 3.8.5

$ pip3 --version
pip 20.1.1 from /home/XXXXX/.linuxbrew/opt/python@3.8/lib/python3.8/site-packages/pip (python 3.8)

python --version では /usr/bin/pythonのパスに通されるので2.7.x系が表示されます

注意点

.bash_profileを確認すると

PATH=$PATH:$HOME/bin

export PATHeval $(/home/XXXXX/.linuxbrew/bin/brew shellenv)

と PATHとevalに改行がなく次回ログイン時にPATHが効かない状態になる
改行いれてなおしておく

PATH=$PATH:$HOME/bin

export PATH
eval $(/home/XXXXX/.linuxbrew/bin/brew shellenv)
6
7
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
6
7