I have a small project that requires a third-party module that's rarely updated (once every other year or so) and not maintained by any package management system. The context, here, is cognitive science & research, the third party module is for linking proprietary hardware to custom scripting, in the house project, potentially, may end up seeing wider (eventually open source) use within cog. psych so I want to plan for distribution.

Can anyone poke holes in or thumbs up this approach:

#!/usr/bin/env python

from distutils.core import setup

    import third_party_package
    install_packages = ['in_house_package']
except ImportError:
    print "Warning: 'third_party_package' not found in PYTHON_PATH, installing version in_house_package v. <VERSION>"
    install_packages = ['in_house_package', 'in_house_package.third_party_package']

    version = '0.1', 
    description = 'A framework for building psychological experiments in Python', 
    author = 'me', 
    author_email = 'my_address', 
    url = 'a local git', 
    requires = ['numpy']
  • \$\begingroup\$ Do you have any plans of moving to python3 in the future? \$\endgroup\$ – shuttle87 Dec 13 '14 at 23:04
  • \$\begingroup\$ For this project, no, alas; the third_party_package is critical and will, almost certainly, never be updated to Python 3. \$\endgroup\$ – Jonline Dec 15 '14 at 13:42

A few small comments:

  1. The error message looks wrong to me.

    This is what the logic looks like to me:

    if (third party package is installed):
        install(in-house package)
        install(in-house package)
        install(in-house variant of third-party package)

    but the printed warning tells me that the in-house package isn’t installed. Shouldn’t it tell me the third-party package isn’t installed?

  2. An ImportError doesn’t necessarily mean a module isn’t installed.

    It just indicates any error when the module was imported. For example, if I have a file foo.py that contains:

    import bar

    and no module bar.py, I get an ImportError when trying to import foo, even though the foo file exists:

    >>> import foo
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "foo.py", line 1, in <module>
        import bar
    ImportError: No module named bar

    You can jump through hoops with import tools, or check the error message of the ImportError. That may or may not be something worth worrying about; just remember that this edge case is there.

  3. Trivial nitpicks.

    • I’m sure this is just an artefact of posting on CR, and it isn’t actually called in_house_package, but you’ve misspelt it in the error message.
    • When specifying keyword arguments to a function (such as setup()), it’s common to omit the spaces around the equals sign.
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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