LoginSignup
36
33

More than 5 years have passed since last update.

pipに--userをつけた時のインストール先を変える

Last updated at Posted at 2016-02-08

PYTHONUSERBASE

pipでinstallするとき--userオプションをつけるとユーザーディレクトリにインストールしてくれて権限の都合とかがある時便利なのだが、そのインストール先をデフォルトから変えたくなった。

pipさん曰く1、pythonのsite.USER_BASEに従っているそうなのでsite.USER_BASEの説明2PYTHONUSERBASEの説明3を見ると、

  • デフォルトでは~/.local~/Library%APPDATA%になっている
  • 環境変数PYTHONUSERBASEで設定できる

ようだ。
というわけで、PYTHONUSERBASEsite.USER_BASEを設定すれば解決。

export PYTHONUSERBASE=/home/username/local
pip
#!/home/username/local/bin/python

# -*- coding: utf-8 -*-
import re
import sys
import site

from pip import main

if __name__ == '__main__':
    site.USER_BASE = "/home/username/local"

    sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
    sys.exit(main())
36
33
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
36
33