0

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?

Julen
  • 1,024
  • 1
  • 13
  • 29

2 Answers2

1

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

Community
  • 1
  • 1
hyunchel
  • 161
  • 2
  • 13
1

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

Julen
  • 1,024
  • 1
  • 13
  • 29
  • 1
    Feel free to add your answer to https://stackoverflow.com/questions/874521/python-install-script-to-system and make it more readable. I believe both questions are about the same. ) – anatoly techtonik Mar 21 '17 at 17:48
  • Thanks for your suggestion, I will! Cheers – Julen Mar 21 '17 at 17:52