1

I am trying to create a directory upon a package installation. The function to create the directory, by itself, successfully creates it. Additionally, when I run "python3.7 setup.py install", the directory is created.

Why does this not work when using pip though? I don't see any errors. When I added print statements, I do not see them.

I have chosen to use setuptools' 'bdist_egg' function instead of the 'install' function for reasons found in here:

Running custom setuptools build during install

from sys import platform
from setuptools import setup
from os import mkdir, chmod, path
from setuptools.command.bdist_egg import bdist_egg as _bdist_egg

class OverrideInstall(_bdist_egg):

    def run(self):
        _bdist_egg.run(self)

        # create log directory
        log = "/var/log/FOO"
        mode = 0o777
        if not path.exists(log):
            mkdir(log)
            chmod(log, mode)

setup(
    name='cox-nams',
    version='FOO',
    description='FOO',

    <-- output omitted for brevity / security>

    cmdclass={"bdist_egg": OverrideInstall},
)
5
  • 1
    "Why does this not work when using pip?" Because pip doesn't run python setup.py install. You cannot have a post-installation code with pip. Commented Sep 12, 2019 at 22:48
  • 1
    Thanks for the reply. How is it recommended to perform these simple installation tasks? I guess the modules being installed could perform a check and install if they're not there. Is there anyway to do this within pip so that the install and actual code are kept separate? Commented Sep 13, 2019 at 15:20
  • "the modules being installed could perform a check and install if they're not there" Also wouldn't work because such programs seldom run under root and you need to be root to create a directory under /var/log. For system-wide installation you better create a real system package (RPM or DEB). For virtualenv you can do whatever you want but don't touch system directories. Commented Sep 13, 2019 at 17:09
  • 1
    I was trying to mimic a package that is very similar to mine. In fact, I was cutting/pasting from it. github.com/Juniper/jsnapy/blob/master/setup.py . Do you know how they are able to do this and why it is different than what I am doing? There is also an 'install-ubuntu-debian' page they have which shows a 'pip install' as the instructions. Commented Sep 13, 2019 at 18:22
  • 1
    I don't think it does. I just ran pip install jsnappy under a non-root user — the package installed (into a virtualenv), but non of /etc/jsnappy or /var/log/jsnappy was created and no error was reported. Commented Sep 13, 2019 at 20:22

1 Answer 1

1

Apparently not supported with pip install.

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

Comments

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.