How to install python package in local environment as a general user

I don't have administrator privileges (root), but I install the python package in my local environment.

Confirmed in the following raw environment.

$ docker run  --rm -i -t docker.io/centos:7.3.1611 /bin/bash
//It has python, but no pip command.
$ python -V
Python 2.7.5
$ pip
-bash: pip: command not found

//First, prepare the pip command
$ curl -O https://bootstrap.pypa.io/get-pip.py
$ python get-pip.py --user

//When you execute the above command,.Install + path is added to local
$ ll ~/.local/bin/pip
-rwxrwxr-x 1 ymko ymko 201 Jul 15 03:58 /home/ymko/.local/bin/pip
$ echo $PATH
/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/ymko/.local/bin:/home/ymko/bin

//It disappears when you log off, so add it
$ echo "export PATH=$HOME/.local/bin:\$PATH" >> ~/.bashrc

//Error that cannot be written in the system area when trying to install as it is
$ pip install bottle
IOError: [Errno 13] Permission denied: '/usr/lib/python2.7/site-packages/bottle.pyc'

// --Install locally as user
$ pip install bottle --user
Collecting bottle
Installing collected packages: bottle
Successfully installed bottle-0.12.13

//Also in the module search path.Contains local stuff
$ python
Python 2.7.5 (default, Nov  6 2016, 00:28:07)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-11)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> print(sys.path)
['', '/usr/lib64/python27.zip', '/usr/lib64/python2.7', '/usr/lib64/python2.7/plat-linux2', '/usr/lib64/python2.7/lib-tk', '/usr/lib64/python2.7/lib-old', '/usr/lib64/python2.7/lib-dynload', '/home/ymko/.local/lib/python2.7/site-packages', '/usr/lib64/python2.7/site-packages', '/usr/lib/python2.7/site-packages']

I made a script because it is troublesome every time

pip_user_install.sh


#!/bin/bash

curl -O https://bootstrap.pypa.io/get-pip.py
python get-pip.py --user
grep .local/bin ~/.bashrc
if [ $? != 0 ]; then
    echo "export PATH=$HOME/.local/bin:\$PATH" >> ~/.bashrc
fi

Also refer to

Install python package in offline environment -Qiita

Recommended Posts

How to install python package in local environment as a general user
[Python] How to save the installed package and install it in a new environment at once Mac environment
How to develop in a virtual environment of Python [Memo]
How to access environment variables in Python
How to install a package using a repository
How to get a stacktrace in python
How to create a Python virtual environment (venv)
How to clear tuples in a list (Python)
How to install Python
How to embed a variable in a python string
How to create a JSON file in Python
How to install python
Install the python package in an offline environment
How to notify a Discord channel in Python
[Python] How to draw a histogram in Matplotlib
How to output "Ketsumaimo" as standard output in Python
How to run GUI programs such as tkinter in Python environment on WSL2
[Python] How to create a local web server environment with SimpleHTTPServer and CGIHTTPServer
How to set up a Python environment using pyenv
How to build a Django (python) environment on docker
How to display DataFrame as a table in Markdown
How to make a Python package using VS Code
How to use jupyter lab in Windows 10 local environment
How to execute a command using subprocess in Python
How to build a Python environment on amazon linux 2
How to install poetry (error handling) in zsh environment
[2020.8 latest] How to install Python
How to install Python [Windows]
How to develop in Python
How to use python multiprocessing (continued 3) apply_async in class with Pool as a member
How to install NPI + send a message to line with python
How to build a new python virtual environment on Ubuntu
How to slice a block multiple array from a multiple array in Python
How to import NoteBook as a module in Jupyter (IPython)
A story about how to specify a relative path in python.
How to import a file anywhere you like in Python
How to define multiple variables in a python for statement
A note on how to load a virtual environment in PyCharm
I tried "How to get a method decorated in Python"
How to get the last (last) value in a list in Python
How to register a package on PyPI (as of September 2017)
How to get a list of built-in exceptions in python
How to build a python2.7 series development environment with Vagrant
How to import NoteBook as a module in Jupyter (IPython)
Explaining how to make LINE BOT in the world's easiest way (2) [Preparing a bot application in a local environment with Django in Python]
How to install python using anaconda
How to write a Python class
[Python] How to do PCA in Python
[Linux] How to install a package on a server that does not have a network environment (standalone)
How to collect images in Python
How to use SQLite in Python
How to create a Conda package
install tensorflow in anaconda + python3.5 environment
How to use Mysql in python
How to wrap C in Python
How to use ChemSpider in Python
How to use PubChem in Python
How to handle Japanese in Python
How to determine the existence of a selenium element in Python
How to install OpenCV on Cloud9 and run it in Python
How to pass arguments to a Python script in SPSS Modeler Batch