36
33

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.

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())
  1. https://pip.pypa.io/en/stable/reference/pip_install/#cmdoption-user

  2. http://docs.python.jp/2/library/site.html#site.USER_BASE

  3. http://docs.python.jp/2/using/cmdline.html#envvar-PYTHONUSERBASE

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?