0

我正在使用 Azure Databricks 运行我的 python 代码。为此,我想要导入来自 COCO 的图像数据集;我为此安装了 pycocotools API。但是,当我尝试导入库时,出现错误“找不到名为“pycocotools”的模块。我无法弄清楚我到底在哪里做错了。这是我用来安装 API 的代码

%sh
pip install "git+https://github.com/philferriere/cocoapi.git#egg=pycocotools&subdirectory=PythonAPI"

这是我得到的输出

DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support
Requirement already satisfied: pycocotools from git+https://github.com/philferriere/cocoapi.git#egg=pycocotools&subdirectory=PythonAPI in /usr/local/lib/python2.7/dist-packages (2.0)

当我尝试导入库时,

import pycocotools

这就是错误。

ImportError: No module named 'pycocotools'

请帮我解决一下这个。

4

1 回答 1

0

如果你在 Conda 中工作,你可以按照下面的步骤来安装、导入和使用这个库。

### Enter the below in your Conda Command Prompt ###
# Create a new environment
conda create -n <envName>
# Activate the environment
conda activate <envName>
# Install cython
pip install cython
# Install git
conda install -c anaconda git
# Install pycocotools from this GitHub rep
pip install git+https://github.com/philferriere/cocoapi.git#egg=pycocotools^&subdirectory=PythonAPI

此外,我最近写了一篇关于探索和操作 COCO 数据集的完整文章。看看吧。

于 2020-05-06T14:23:50.500 回答