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

2024-06-14 10:55:41 发布

您现在位置:Python中文网/ 问答频道 /正文

我在AI平台上安装trainer包时遇到这个错误

Traceback (most recent call last): File "", line 1, in File "/tmp/pip-install-_u8thvm6/pycocotools/setup.py", line 2, in from Cython.Build import cythonize ImportError: No module named 'Cython'

尽管我在setup.py中加入了'Cython'。你知道吗

设置.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')


Tags: installnameinpyimportversionpackagessetup
2条回答

通过在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')

运行前需要安装cython设置.py. 问题是cython是在构建时需要的,而不是在运行时,并且无法保证您在install_requires中列出的软件包的安装顺序。因此,当pip试图安装pycocotools时,它还没有安装cython并中止。你知道吗

相关问题 更多 >