13

I'm trying to create a package of my own. The package is very simple, it has one python module and one bash script. I wan both of them to be installed under /usr/local/bin so that they can be directly executed.

Here's my setup.py file:

from setuptools import setup

setup(
    name='deploy',
    .
    .
    .
    install_requires=['pyyaml', 'cot', 'jsonschema'],
    entry_points={
        'console_scripts': [
            'cloud_config = cloud_config:main',
        ],
    },
    scripts=['deploy.sh'],
)

Here's excerpt from output of pip install ...:

running install_scripts
    copying build/scripts-2.7/deploy.sh -> /usr/local/lib/python2.7.10/bin
    changing mode of /usr/local/lib/python2.7.10/bin/deploy.sh to 755
    Installing cloud_config script to /usr/local/lib/python2.7.10/bin

With this, I'm not able to invoke either the python or the bash script directly.

Any ideas?

Edit: I'm running the pip on Ubuntu 16.04.1 machine. Just tried to install the same package on a Ubuntu 14.04 machine and behavior is as expected. cloud_config.py and deploy.sh both get installed to /usr/local/bin and I can invoke both from anywhere on the system.

3
  • 2
    Ubuntu heavily patches pip; I'm not surprised they changed behaviour here too. Commented Feb 14, 2017 at 9:35
  • That's absurd @MartijnPieters. How does one go about creating a package that installs properly on all platforms?
    – ronakg
    Commented Feb 14, 2017 at 17:52
  • I've just tried to create a package based on your setup.py and deploy to clean Ubuntu 16.04 Vagrant box - all works fine. If you would provide more information it might help to reproduce the issue. Maybe something with versions? Which version of setuptools do you use for assembly? Which are the pip and setuptools on target machine?
    – Tim
    Commented Feb 20, 2017 at 16:59

5 Answers 5

3
+25

Two options I can think of, first,check that pip is pointing in the right place. So try:

which python

mine says:

/usr/bin/python

yours will be different, change the path accordingly to then make sure the PATH is properly set, so:

export PATH=/usr/bin/python:${PATH}

Reinstall pip and try again. Failing that, a workaround might be to not use pip in this instance and try:

python setup.py install

which will use your default python path (not pip) and should install to:

/usr/local/bin 
1
  • Mine also says /usr/bin/python. See my answer below to see what worked. I still have no idea why default pip doesn't work.
    – ronakg
    Commented Feb 21, 2017 at 4:30
1

Try:

pip install --install-option="--prefix=$PREFIX_PATH" package_name

e.g.

pip install --install-option="--prefix=/usr/local/bin" pyFooBar
2
  • Aren't entries under entry_points -> console_scripts supposed to be installed in the PATH so they're callable from anywhere?
    – ronakg
    Commented Feb 12, 2017 at 0:50
  • According to this documentation for python packaging - python-packaging.readthedocs.io/en/latest/…
    – ronakg
    Commented Feb 12, 2017 at 1:03
1

Finally I got it to work. I had to remove the pip package that was installed by apt.

sudo apt remove python-pip

And then install pip again according to instructions on their website - https://pip.pypa.io/en/stable/installing/.

wget https://bootstrap.pypa.io/get-pip.py
sudo python get-pip.py

Looks like pip from Ubuntu's default repository is not same as one distributed by pypi.

1

I also found I could install a package and it appeared to be successful, but the entry_points scripts weren't in my PATH. Turned out that pip silently failed to install them.

Try running setup.py install directly. Doing that showed me access errors when trying to install the scripts into /usr/local/bin even though pip install -e . showed no errors. (See more about using -e.)

The solution to my problem was to use --prefix:

pip install --prefix ~/apps -e .

And ~/apps/bin is in my $PATH. To install to /usr/local/bin, you'd either have to change its permissions or run pip as root.

0

console_scripts does not work with old versions of pip. pip 10.0.1 is too old. pip 19.0.3 is sufficiently new.

Not the answer you're looking for? Browse other questions tagged or ask your own question.