Search code examples
pythonmodulesetuptoolsdistutils

What do I need to do to my python code to get it to be a module?


Can someone tell me what I'm doing wrong to package this as a module: https://github.com/xamox/python-zxing.

My setup.py is as follows:

#!/usr/bin/env python

from distutils.core import setup

setup(
    name='zxing',
    version='0.1',
    description="wrapper for zebra crossing (zxing) barcode library",
    url='http://simplecv.org',
    author='Ingenuitas',
    author_email='[email protected]',
    packages=['zxing'],
)

I am trying to do "import zxing". I do setup.py install, puts it in /usr/local/lib/python2.7/dist-packages/, but import zxing doesn't work.

I get the following error:

In [1]: import zxing.zxing
---------------------------------------------------------------------------
ResolutionError                           Traceback (most recent call last)
/home/xamox/<ipython-input-1-9ff7d0755c55> in <module>()
----> 1 import zxing.zxing

/usr/local/bin/zxing.py in <module>()
      3 __requires__ = 'zxing==0.1'
      4 import pkg_resources
----> 5 pkg_resources.run_script('zxing==0.1', 'zxing.py')

/usr/lib/python2.7/dist-packages/pkg_resources.pyc in run_script(self, requires, script_name)
    465         ns.clear()
    466         ns['__name__'] = name
--> 467         self.require(requires)[0].run_script(script_name, ns)
    468 
    469 

/usr/lib/python2.7/dist-packages/pkg_resources.pyc in run_script(self, script_name, namespace)
   1192         script = 'scripts/'+script_name
   1193         if not self.has_metadata(script):
-> 1194             raise ResolutionError("No script named %r" % script_name)
   1195         script_text = self.get_metadata(script).replace('\r\n','\n')
   1196         script_text = script_text.replace('\r','\n')

ResolutionError: No script named 'zxing.py'

Solution

  • Have a look in the stack trace whose URL you showed in a comment:

    /usr/local/bin/zxing.py in <module>()
          3 __requires__ = 'zxing==0.1'
          4 import pkg_resources
    ----> 5 pkg_resources.run_script('zxing==0.1', 'zxing.py')
    

    That indicates that it is trying to load some guff from /usr/local/bin/zxing.py which contains code that's not in your current version e.g. "import pkg_resources". Looks like debris from a previous experiment. Get rid of it.

    Now that you have a clean deck:

    It seems rather pointless having an empty __init__.py and a one-source-file package. I suggest that you delete the __init__.py and remove all traces of other experiments (especially "build" directories). If there is a folder /usr/local/lib/python2.7/dist-packages/zxing, remove it.