Change the installation destination when --user is added to pip

PYTHONUSERBASE When installing with pip, if you add the --user option, it will be installed in the user directory, which is convenient when there is a permission, but I wanted to change the installation destination from the default.

According to pip [^ 1], it follows python's site.USER_BASE, so if you look at the explanation [^ 2] of site.USER_BASE and the explanation [^ 3] of PYTHONUSERBASE,

It seems. So, setting PYTHONUSERBASE or site.USER_BASE will solve the problem.

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())

Recommended Posts

Change the installation destination when --user is added to pip
[PostgreSQL] How to grant superuser authority when the user (role) with superuser authority is 0
Change the standard output destination to a file in Python
[Linux] I want to know the date when the user logged in
When I try to use pip, SSL module is not available.
Build Python environment on Ubuntu (when pip is not the default)
What to do when the value type is ambiguous in Python?
Change the Flyweight pattern to Pythonic (?) (3)
Change the Flyweight pattern to Pythonic (?) (2)
Command installation destination with pip, easy_install
[Python] Change the alphabet to numbers
[Python] What to do when PEP8 is violated in the process of importing from the directory added to sys.path
[Python] When the priority is the same in Priority Queue, it can be acquired in the order in which it was added to the queue.
What to do when the result downloaded via scrapy is in English
When you want to change the HTTP headers of Flask's test client
The day when basic authentication was added to the service operated by flask
What to do when the warning "The environment is in consistent ..." appears in the Anaconda environment
How to automatically notify by phone when the python system is down
What to do when a warning message is displayed in pip list
Is it deprecated to use pip directly?
Script to change the description of fasta
When the target is Ubuntu 16.04 in Ansible
Is the number equivalent to an integer?
Change the destination batfish server of pybatfish
When I tried to change the root password with ansible, I couldn't access it.
Send a direct love email to a new user when a new user joins the Slack team
I want to be notified when the command operation is completed on linux!
What happens to the access log when the website is automatically accessed by selenium-webdriver