Julen
Julen

Reputation: 1144

Python - Install a CLI utility with pip for being usable not just with virtual environments

Suppose a CLI utility published in PyPI, downloadable with pip.

I want to install it for being usable not inside a virtual environment. With a virtual environment, the entrypoint script is being created in the env/bin/ directory. But, installing it with pip with the virtual environment deactivated, it's just being installed in /usr/local/lib/pythonX/dist-packages/<package-name>, and without a <package-name> entrypoint script in the path, so it's not callable.

Is there a possibility to do so?

Upvotes: 0

Views: 780

Answers (2)

Julen
Julen

Reputation: 1144

Thanks to @gnis and @anatoly-techtonik, but I figured out to make it delegate to the setuptools, instead of creating scripts by hand.

It's just a matter of passing a dictionary to setup, console_scripts, which can be exactly the same as entry_points (the one that generates the file in the virtual environment bin/:

setup(
    # rest of setup
    console_scripts={
        'console_scripts': [
            '<app> = <package>.<app>:main'
        ]
    },
)

This will generate an script in /usr/local/bin.

For more info check https://packaging.python.org/distributing/#console-scripts

Upvotes: 1

hyunchel
hyunchel

Reputation: 161

You can always export PYTHON_PATH in your .bash_[profile|rc] file to manipulate which path to look for regardless of your virtual environment.

According to Python documentation on PYTHON_PATH:

The default search path is installation dependent, but generally begins with prefix/lib/pythonversion (see PYTHONHOME above). It is always appended to PYTHONPATH.

An additional directory will be inserted in the search path in front of PYTHONPATH as described above under Interface options. The search path can be manipulated from within a Python program as the variable sys.path.

source: https://docs.python.org/2/using/cmdline.html

Upvotes: 1

Related Questions