与setup.py中的功能有关的pip安装抛出错误

时间:2019-02-06 13:52:56

标签: python python-3.x pip attributeerror setup.py

我尝试将我的sdk-python软件包的pip install /Users/me/git/sdk-python/放入我拥有的测试项目中,但出现此错误:

(venv) Pauls-MBP-2:ibm-cos-sdk-python-config-test paulcarron$ python -m pip install /Users/paulcarron/git/ibm-cos-sdk-python-config/
Processing /Users/paulcarron/git/ibm-cos-sdk-python-config
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/private/var/folders/k1/h29nn0z959q0dr6b44kxx_8h0000gn/T/pip-req-build-cmc5fb_p/setup.py", line 24, in <module>
        version=get_version(),
      File "/private/var/folders/k1/h29nn0z959q0dr6b44kxx_8h0000gn/T/pip-req-build-cmc5fb_p/setup.py", line 19, in get_version
        return VERSION_RE.search(init).group(1)
    AttributeError: 'NoneType' object has no attribute 'group'

这是我的setup.py:

#!/usr/bin/env python
import os
import re
import sys

from setuptools import setup, find_packages
# sdk python version check
_valid  =  sys.version_info[:2] == (2, 7) or sys.version_info >= (3,4)
if not _valid:
    sys.exit("Sorry, SDK only supports versions 2.7, 3.4, 3.5, 3.6, 3.7 of python.")


ROOT = os.path.dirname(__file__)
VERSION_RE = re.compile(r'''__version__ = ['"]([a-z0-9.]+)['"]''')


def get_version():
    init = open(os.path.join(ROOT, 'python_sdk', '__init__.py')).read()
    return VERSION_RE.search(init).group(1)


setup(
    name='sdk-python',
    version=get_version(),
    description='SDK for Python',
    long_description=open('README.md').read(),
    author='me',
    url='https://github.company.com/org/sdk-python',
    scripts=[],
    packages=find_packages(exclude=['tests*']),
    include_package_data=True,
    license="Apache License 2.0",
    classifiers=[
        'Development Status :: 5 - Production/Stable',
        'Intended Audience :: Developers',
        'Natural Language :: English',
        'License :: OSI Approved :: Apache Software License',
        'Programming Language :: Python',
        'Programming Language :: Python :: 2.7',
        'Programming Language :: Python :: 3',
        'Programming Language :: Python :: 3.4',
        'Programming Language :: Python :: 3.5',
        'Programming Language :: Python :: 3.6',
        'Programming Language :: Python :: 3.7',
    ],
)

此方法以前有效,但显然已经发生了变化。我只是不确定是什么,并且基于错误,我不知道从哪里开始,除了可能与我的get_version中的setup.py有关。我也不确定鸡蛋参考来自哪里。

2 个答案:

答案 0 :(得分:1)

我试图安装python库转换并遇到相同的问题。

事实证明,python以dos格式存储或提取(在我的RPi上),并且破坏了setup.py中的正则表达式搜索,该正则表达式搜索提取了README和LICENSE之类的东西。

解决方案是下载库档案,将其解压缩,将setuptools扫描的python文件转换为unix格式,创建新档案,然后使用新档案运行sudo pip install。

这是我进行特定库转换的步骤:

function foo(parameter1, parameter2) {
  if (arguments.length > 1) {
    console.log("parameter 2 is " + arguments[1])
  } else {
    console.log("no second parameter")
  }
};
foo("bar");
foo("bar", undefined);

答案 1 :(得分:0)

我已将__version__更新为包含一个_字符,但是get_version包含了[a-z0-9.],这阻止了_字符的使用,因此我将其更改为{ {1}},现在可以安装该软件包了。