[PYTHON] pipsi: use packages without polluting system pip

Introduction

I wanted to use flake8 to check the syntax of Python scripts I didn't want to pip install any packages that I didn't need for my application to work. I introduced it because there was something that looked good when I searched for it.

What is pipsi

mitsuhiko/pipsi

pipsi = pip script installer

What does it do? pipsi is a wrapper around virtualenv and pip which installs scripts provided by python packages into separate virtualenvs to shield them from your system and each other.

In other words: you can use pipsi to install things like pygmentize without making your system painful.

(Roughly summarized) pipsi is a wrapper for virtualenv and pip, by separating the virtual environment from the system. You can install the package without polluting your system.

pipsi installs each package into ~/.local/venvs/PKGNAME and then symlinks all new scripts into ~/.local/bin.

pipsi installs the package under ~ / .local / venvs Generate a symbolic link to the script in ~ / .local / bin.

Introduction

environment

I prepared Debian environment where Python runs locally.

Docker operation


#Download Python image
$ docker pull python:3.5.2

#Start the container and run bash
$ docker run -it {IMAGE ID} /bin/bash

Create a user with sudo privileges for the sake of explanation. (It was necessary to introduce sudo itself, but I will omit it.)

Add hoge user


$ adduser hoge
$ gpasswd -a hoge sudo	

procedure

Execute the curl and python commands according to the README.

pipsi installation


$ curl https://raw.githubusercontent.com/mitsuhiko/pipsi/master/get-pipsi.py | python
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  2805  100  2805    0     0   6466      0 --:--:-- --:--:-- --:--:--  6463
Installing pipsi
You need to have virtualenv installed to bootstrap pipsi.

I got an error because there was no virtualenv. Inevitably, install only virtualenv with pip. (Virtualenv documentation says that local installation is possible, but it was troublesome)

Install virtualenv


$ sudo pip install virtualenv
$ pip list
pip (8.1.2)
setuptools (20.10.1)
virtualenv (15.0.3)

When you're done, run the pipsi install command again.

pipsi installation


$ curl https://raw.githubusercontent.com/mitsuhiko/pipsi/master/get-pipsi.py | python

The installation is successful, but a Warning is displayed.

Warning


Warning:
  It looks like /home/hoge/.local/bin is not on your PATH so pipsi will
  not work out of the box.  To fix this problem make sure to
  add this to your .bashrc / .profile file:

  export PATH=/home/hoge/.local/bin:$PATH

To make it work, add ~ / .local / bin to your PATH. Here, it is executed on the shell, but if it is reflected every time you log in It is necessary to describe in the configuration file as instructed.

Add PATH


$ export PATH=/home/hoge/.local/bin:$PATH
$ echo $PATH
/home/hoge/.local/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games

Now you are ready to go. Install the packages you want to manage using pipsi.

Package installation


$ pipsi install flake8
$ which flake8
/home/hoge/.local/bin/flake8

You can see that it is not included in the system pip.

Check pip


$ pip list
pip (8.1.2)
setuptools (20.10.1)
virtualenv (15.0.3)

Conclusion

Although the number of disposable servers has increased and package management has become a little rough. It seems to be useful when developing in a shared environment. Even if you don't write Python, you can use it to manage tools such as httpie and mycli.

Recommended Posts

pipsi: use packages without polluting system pip
Installing packages with pip3
Use pip with MSYS2
Use pip on Windows
Install packages that cannot use pip in Azure App Service