无法在Google AI平台(CMLE)上安装pycocotools

时间:2019-12-03 10:02:44

标签: python cython google-cloud-ml gcp-ai-platform-training pycocotools

在AI平台上安装trainer软件包时出现此错误,

  

回溯(最近一次通话最后一次):文件“”,第1行,在    文件“ /tmp/pip-install-_u8thvm6/pycocotools/setup.py”,行   2,在从Cython.Build中导入cythonize ImportError:否   名为“ Cython”的模块

尽管我在'Cython'中加入了setup.py

setup.py:

import setuptools

NAME = 'trainer'
VERSION = '1.0'
REQUIRED_PACKAGES = [
    'Cython', # Cython, mentioned before pycocotools
    'tensorflow-gpu',
    'google-cloud-storage',
    'gcsfs',
    'pycocotools'
]

setuptools.setup(
    name=NAME,
    version=VERSION,
    packages=setuptools.find_packages(),
    install_requires=REQUIRED_PACKAGES,
    include_package_data=True,
    description='Trainer package')

2 个答案:

答案 0 :(得分:1)

在运行setup.py之前,您需要安装cython。问题在于,cython在构建时需要,而不是在运行时需要,并且无法保证您在install_requires中列出的软件包的安装顺序。因此,当pip尝试安装pycocotools时,它尚未安装cython并中止。

答案 1 :(得分:1)

通过在setup.py中添加这些行,可以解决错误,

import setuptools

# Install cython before setup
import os                                       # <--- This line added
os.system('pip3 install --upgrade cython')      # <--- This line added

NAME = 'trainer'
VERSION = '1.0'
REQUIRED_PACKAGES = [
    'Cython', # Cython, mentioned before pycocotools
    'tensorflow-gpu',
    'google-cloud-storage',
    'gcsfs',
    'pycocotools'
]

setuptools.setup(
    name=NAME,
    version=VERSION,
    packages=setuptools.find_packages(),
    install_requires=REQUIRED_PACKAGES,
    include_package_data=True,
    description='Trainer package')