AttributeError: Extension instance has no attribute '__version__'
Question: Here is the script..

    
    
    from distutils.core import setup, Extension
    
    nmap = Extension('nmap',sources = ['nmap/nmap.py', 
                               'nmap/__init__.py', 'nmap/example.py'])
    
    from nmap import *
    
    setup (
        name = 'python-nmap',
        version = nmap.__version__,
        author = 'Alexandre Norman',
        author_email = 'norman@xael.org',
        license ='gpl-3.0.txt',
        keywords="nmap, portscanner, network, sysadmin",)
    

... and i got this error:

    
    
    Traceback (most recent call last):
      File "C:\Python27\nmap.py", line 6, in <module>
        from nmap import *
      File "C:\Python27\nmap.py", line 17, in <module>
        version = nmap.__version__,
    AttributeError: Extension instance has no attribute '__version__'
    


Answer: There are a number of problems here.

  1. Your `nmap` package isn't an extension, it's a pure-Python package; don't create an `Extension` object for it. Python extension are written in [C or C++](http://docs.python.org/2/extending/building.html).

  2. You're trying to access `nmap.__version__`, presumably because you defined that variable in `nmap/__init__.py`, but `nmap` here is that `Extension` object you created; it's trying to access the variable from the wrong thing.

  3. Even if you remove the `Extension` object, you still wouldn't be able to access `nmap.__version__`, because you imported your package incorrectly; you meant to use `import nmap`.

  4. You never actually pass your package to `setup`, so `distutils` won't know about it. There are a few examples of how to do that [in the documentation](http://docs.python.org/2/distutils/examples.html#pure-python-distribution-by-package).

The [`distutils` documentation](http://docs.python.org/2/distutils/index.html)
is pretty big, but it's a good idea to read through all of it at least once.

