0

my setup.py file looks like

$ cat setup.py 
from setuptools import setup
 
setup(
     name='user1-hello-world',
     version='0.20', 
     scripts=['user1-hello-world'] ,
     data_files=[('/usr/sbin/',['user1-bin2'])]
)

I have 1 python script (user1-hello-world) and 1 elf binary file(user1-bin2)

$ ls
user1-hello-world user1-bin2 setup.py

build and uploading using twine like:

 python3 setup.py sdist bdist_wheel
 python3 -m twine upload --repository testpypi dist/*

After uploading the files to test.pypi.org. Installing via pip show the files under home dir.

/home/user/.local/bin/user1-hello-world
/home/user1/.local/lib/python3.8/site-packages/user1_hello_world-0.20.dist-info/*
/home/user1/.local/lib/python3.8/site-packages/usr/sbin/user1-bin2

I was hoping to install user1-bin2 under /usr/sbin like /usr/sbin/user1-bin2. How to achieve this? thanks for any pointers.

webminal.org
  • 44,948
  • 37
  • 94
  • 125

1 Answers1

0

First, set the install location by editing $HOME/.pip/pip.conf to

[global]
target=usr/sbin

or just using --target usr/sbin

Then, because the usr/sbin folder requires root rights, don't forget to add a sudo (on linux):

sudo pip install your-package
Banana
  • 2,295
  • 1
  • 8
  • 25
  • thanks! I think above suggestion is similar to `pip install --target /some/path` . I'm looking for solution with `setup.py` file. I read `data_files` options should work but in my case it didnt :( – webminal.org Aug 12 '20 at 14:51
  • @webminal.org Ah, I think --target works the same as doing it in the config file. So you want your package to be auto-installed in this special folder? – Banana Aug 12 '20 at 14:53
  • Yes, I want `user1-bin2` to be present at `/usr/sbin/user1-bin2` – webminal.org Aug 12 '20 at 15:45
  • Interesting when I install using `pip` its placed on `/usr/sbin/user1-bin2` but I get this location `/home/user1/.local/lib/python3.8/site-packages/usr/sbin/user1-bin2` while using pip3. – webminal.org Aug 12 '20 at 15:45
  • 1
    @webminal.org I guess its not possible to force the install location as a package creaator, because the user should be able to decide on their own. – Banana Aug 13 '20 at 14:58