2.7安装脚本在3.4下失败

时间:2014-09-16 07:04:53

标签: python-3.x setuptools setup.py

我有一个包含安装脚本的软件包,可以在2.7下安装,但安装脚本(使用setuptools)在运行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]

我尝试了什么:

  • 我在安装2.7版本的同一个源文件夹中执行此操作,是不是很糟/危险?我删除了所有* .pyc FWIW?
  • 如果我在setup.py脚本中显示任何必要的更改,我尝试了2to3,但它说没有必要:
± 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

编辑,由评论推动: 我能找到的唯一排序是install_requires行:     install_requires = ['pandas&gt; ='+ pandas_version] 同     pandas_version ='0.13.1'

如果这是罪魁祸首,那么如何在Python 3.4中正确地做到这一点?

这是整个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",
)

2 个答案:

答案 0 :(得分:1)

追溯的最后一行:

  File "/Users/maye/miniconda3/envs/py34/lib/python3.4/site-packages/setuptools-5.7-py3.4.egg/pkg_resources.py", line 852, in add

如果你去那条线并开始向后工作,你将有希望找到两个被比较的变量 - 其中一个是str,另一个是NoneNone变量可能是从失败的查找中获得的。

找出查找失败的原因,也许您可​​以通过修改setup.py来解决问题 - 否则您可能需要修补pkg_resources.py来处理一个变量为None的情况

深入研究setuptools 5.7版本,我们在错误网站上找到了这个:

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)

最后一行是错误发生的地方 - 正在对dists进行排序。

正在使用的keyhashcmp

@property
def hashcmp(self):
    return (
        getattr(self, 'parsed_version', ()),
        self.precedence,
        self.key,
        _remove_md5_fragment(self.location),
        self.py_version,
        self.platform,
    )

如您所见,您不会返回None


关于我唯一的想法是:你的Python路径中是否已经安装了某个版本?如果你这样做,也许它的元数据缺少一些重要的部分,这就是你收到错误的原因。

答案 1 :(得分:-1)

我认为这个错误可能导致了这种行为:

https://bitbucket.org/pypa/setuptools/issue/137/typeerror-unorderable-types-str-nonetype

特别是,以下错误症状可以帮助其他人确定这是否是他们的问题(使用conda经理,但它应该与其他人类似):

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

问题是,IIUC,distutils和setuptools现在因为在站点包中有超过1个Python Egg而感到困惑,并且在找到现在最适合安装的版本时无法正确sort它们。

两个动作帮助我解决了这个问题:

  1. 使用setuptools而不是distutils。为此,我在setup.py替换了

    来自distutils导入设置

  2. from setuptools import setup
    
    1. setuptools升级到最近发布的版本14.3,该版本解决了上述链接难以重现的错误。
    2. 我正在使用我的conda软件包管理器来执行此操作,但它不应该依赖于此。