1

I'm developing a CLI application with Python and I can install it with pip install -e . for an editable install, however this installs it only in the virtual environment. I can't access the CLI from things like Ubuntu's custom keyboard shortcuts, or Thunar's custom keyboard shortcuts.

I can install everything globally instead, but this causes package version conflicts.

How can I expose my CLI globally, in an editable way, while managing dependencies in an isolated environment?

Do I need some wrapper script, manually added to the PATH, or is there a pip option for this?

7
  • 1
    Look at pipx.pypa.io/stable Commented Jun 9 at 6:22
  • In /usr/bin create a symlink to the CLI program in venv. Commented Jun 9 at 6:34
  • You can ‘hack’ in a callable wrapper via symlink into /usr/local/bin yourself, or create an executable script, using your pyproject.toml file. The latter will create the wrapper for you on pip install <myproject>. Commented Jun 9 at 7:06
  • This RealPython tutorial provides an example of how to create an executable script. Commented Jun 9 at 7:14
  • I already have an executable script set up. The problem is it is only exposed within a virtual environment if installed within a virtual environment. Commented Jun 9 at 16:07

1 Answer 1

0

Ignoring the mechanism of installing the program, it sounds like what you're trying to do is run a program in a venv without having that venv activated first.

If that's right, the simplest approach is a shell script to execute the program from within the virtual environment. Something like this:

#!/usr/bin/env bash
exec $HOME/program-venv/bin/the-program "$@"

Then add that shell script to your PATH.

Sign up to request clarification or add additional context in comments.

1 Comment

stackoverflow.com/a/30541898/7976758 There is no need to activate a virtual env in a bash script; running under the proper Python from the venv is enough. I.e., a proper shebang in $HOME/program-venv/bin/the-program or running $HOME/program-venv/bin/python $HOME/program-venv/bin/the-program does the trick because virtual environments are implemented inside Python interpreter, not in activation script. All the activation script does is set $PATH so that $HOME/program-venv/bin/python is in the $PATH.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.