Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pip-install Python package into virtual env and have CLI commands accessible in normal shell

For larger Python packages which might interfere with other packages it is recommended to install them into their own virtual environment and some Python packages expose CLI commands to the shell.

Is there a way to pip-install such a package into its own virtual environment, but have the CLI commands accessible from a normal shell without switching beforehand manually to this virtual environment?

Here an example: When I install csvkit via

pip install csvkit

I have the commands csvcut, csvlook, csvgrep and others available in my shell. However if I do not want to install cvskit in my System-Python and install it in a virtual environment, say at ~/venvs/csvkit, I have csvkit only available if I have manually activated the environment csvkit.

Is there a way to create the virtual environment and install csvkit in it, so that the commands like csvcut activate the environment themselves before they run?

like image 999
halloleo Avatar asked Oct 18 '22 14:10

halloleo


1 Answers

A newer tool which still is very well maintained is pipx - Install and Run Python Applications in Isolated Environments. It works similar to pipsi:

  1. First install pipx. (See pipx installation)
  2. Then issue:

    pipx install csvkit
    
  3. Finally make sure pipx's bin directory (normally ~/.local/bin) is in your PATH.

Please note, pipx has additional commands for maintaining and inspecting of the generated venvs - see pipx --help.

like image 129
halloleo Avatar answered Oct 20 '22 10:10

halloleo