2.7 setting script doesn't work under 3.4
I have a package with an install script that sets a fine under 2.7, but the install script (using setuptools) fails when run from 3.4:
± python setup.py develop
running develop
Traceback (most recent call last):
File "setup.py", line 45, in <module>
url = "http:www.planetfour.org",
File "/Users/maye/miniconda3/envs/py34/lib/python3.4/distutils/core.py", line 148, in setup
dist.run_commands()
File "/Users/maye/miniconda3/envs/py34/lib/python3.4/distutils/dist.py", line 955, in run_commands
self.run_command(cmd)
File "/Users/maye/miniconda3/envs/py34/lib/python3.4/distutils/dist.py", line 973, in run_command
cmd_obj.ensure_finalized()
File "/Users/maye/miniconda3/envs/py34/lib/python3.4/distutils/cmd.py", line 107, in ensure_finalized
self.finalize_options()
File "/Users/maye/miniconda3/envs/py34/lib/python3.4/site-packages/setuptools-5.7-py3.4.egg/setuptools/command/develop.py", line 50, in finalize_options
File "/Users/maye/miniconda3/envs/py34/lib/python3.4/site-packages/setuptools-5.7-py3.4.egg/setuptools/command/easy_install.py", line 313, in finalize_options
File "/Users/maye/miniconda3/envs/py34/lib/python3.4/site-packages/setuptools-5.7-py3.4.egg/setuptools/package_index.py", line 269, in __init__
File "/Users/maye/miniconda3/envs/py34/lib/python3.4/site-packages/setuptools-5.7-py3.4.egg/pkg_resources.py", line 802, in __init__
File "/Users/maye/miniconda3/envs/py34/lib/python3.4/site-packages/setuptools-5.7-py3.4.egg/pkg_resources.py", line 832, in scan
File "/Users/maye/miniconda3/envs/py34/lib/python3.4/site-packages/setuptools-5.7-py3.4.egg/pkg_resources.py", line 852, in add
TypeError: unorderable types: str() < NoneType()
(py34)-> [1]
What I have tried:
- I am doing this in the same source folder from where I installed version 2.7, is it bad / dangerous? Did I uninstall all * .pyc FWIWs?
- I tried 2to3 if it shows any changes needed in my setup.py script, but it says not required:
± 2to3 setup.py
RefactoringTool: Skipping implicit fixer: buffer
RefactoringTool: Skipping implicit fixer: idioms
RefactoringTool: Skipping implicit fixer: set_literal
RefactoringTool: Skipping implicit fixer: ws_comma
RefactoringTool: No changes to setup.py
RefactoringTool: Files that need to be modified:
RefactoringTool: setup.py
(py34)maye@lunatic|~/Dropbox/src/P4_sandbox on master
Edit as motivated by a comment: The only ordering I can find is the line install_requires
: install_requires = ['pandas> =' + pandas_version] with pandas_version = '0.13.1'
If this is the culprit, how do I get it right in Python 3.4?
Here's the whole setup.py:
import ez_setup
ez_setup.use_setuptools()
import sys
from setuptools import setup, find_packages
from setuptools.command.test import test as TestCommand
pandas_version = '0.13.1'
class PyTest(TestCommand):
def finalize_options(self):
TestCommand.finalize_options(self)
self.test_args = ['-v']
self.test_suite = True
def run_tests(self):
#import here, cause outside the eggs aren't loaded
import pytest
errno = pytest.main(self.test_args)
sys.exit(errno)
setup(
name = "Planet4",
version = "0.1beta2",
packages = find_packages(),
install_requires = ['pandas>='+pandas_version],
tests_require = ['pytest'],
cmdclass = {'test': PyTest},
entry_points={
"console_scripts": [
'p4reduction = planet4.reduction:main',
'plot_p4_imageid = planet4.markings:main',
]
},
#metadata
author = "K.-Michael Aye",
author_email = "kmichael.aye@gmail.com",
description = "Software for the reduction and analysis of Planet4 data.",
license = "BSD 2-clause",
keywords = "Mars Planet4 Zooniverse",
url = "http:www.planetfour.org",
)
source to share
Last line of trace source:
File "/Users/maye/miniconda3/envs/py34/lib/python3.4/site-packages/setuptools-5.7-py3.4.egg/pkg_resources.py", line 852, in add
If you go to that line and start working backwards, you will hopefully find both variables that are being compared - one is str
, the other is None
. The variable None
probably got this path from a failed search.
Figure out why the lookup failed and you can probably fix the problem by changing setup.py
- otherwise you may need to schedule pkg_resources.py
to handle the case of a single variable None
.
Digging into version setuptools
5.7, we find this on the error site:
def add(self, dist):
"""Add `dist` if we ``can_add()`` it and it has not already been added
"""
if self.can_add(dist) and dist.has_version():
dists = self._distmap.setdefault(dist.key, [])
if dist not in dists:
dists.append(dist)
dists.sort(key=operator.attrgetter('hashcmp'), reverse=True)
The last line is an error when sorting occurs dists
.
Used key
- hashcmp
:
@property
def hashcmp(self):
return (
getattr(self, 'parsed_version', ()),
self.precedence,
self.key,
_remove_md5_fragment(self.location),
self.py_version,
self.platform,
)
Which, as you can see, doesn't return None
.
The only thought I left behind is: Do you already have a version installed somewhere in your Python path? If you do this, it is possible that some important piece is missing from the metadata and why you are getting the error.
source to share
I think this error could have caused this behavior:
https://bitbucket.org/pypa/setuptools/issue/137/typeerror-unorderable-types-str-nonetype
In particular, the following error might help others determine if this is their problem (this is used by the manager conda
, but it should be similar to others):
conda create -n test-hash python=3 pip
source activate test-hash
pip install requests
conda install requests
pip install anything # <- fails with str < None
The problem was IIUC that distutils AND setuptools now got confused having more than 1 Python Egg in site packages and couldn't sort
find them correctly, which is the most suitable version to install now.
Two solutions helped me solve this problem:
-
Using setuptools instead of distutils. To do this, in
setup.py
I replacedfrom distutils import setting
from
from setuptools import setup
- Upgrade
setuptools
to the recently released version 14.3, which solves the tricky issue above to reproduce the bug.
I used a package manager conda
for this, but it shouldn't depend on it.
source to share