mdklatt / cookiecutter-python-app

Cookiecutter template for a Python application project.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

python setup.py install --user is failing (windows / Python 3.4)

vladp opened this issue · comments

Windows 10/ Python 3.4.4 64 bit (WinPython distibution)
Getting an error below. It seems that this function is not working

def version():
    """ Get the local package version.

    """
    path = join("lib", _CONFIG["name"], "__version__.py")
    with open(path) as stream:
        exec(stream.read())
    return __version__

python setup.py install --user

Traceback (most recent call last):
File "setup.py", line 172, in
raise SystemExit(main())
File "setup.py", line 160, in main
_CONFIG["version"] = version()
File "setup.py", line 48, in version
return version
NameError: name 'version' is not defined

It looks like this is due to a difference in the way exec works as a statement in Python 2.7 and a function in Python 3. In Python 3, the variables being exec'd are only visible in the local function scope. I will have to take a deeper look at this.

As a workaround, you can define __version__ in setup.py. The purpose of getting it from __version__.py is so that you only have to set the version number in one place. It is tempting to import the version into setup.py, but importing code into setup.py from the project being installed may cause dependency issues.

Also, keep in mind that the template application does not officially support Python 3, so there may be other compatibility issues.

The setup.py script now works with Python 2 and 3, but the template application itself will still need modification for Python 3, e.g. replacing iteritems() with items() for dicts.

Issue resolved by commit 59f4cd1.