在安装Cython后进行pycocotools安装时出现了ModuleNotFoundError: No module named 'Cython'错误。

5

我在尝试在Python 3.6.9环境下安装pycocotools时遇到了问题。

我的电脑是Windows 10上的Ubuntu 18.04。我创建了一个虚拟环境并激活它,然后想要安装软件包,使用了以下命令:

pip install <package> --user

当我安装Cython时,一切正常,但是当我安装pycocotools时:
pip install pycocotools --user

我遇到了以下错误:

Downloading https://files.pythonhosted.org/packages/96/84/9a07b1095fd8555ba3f3d519517c8743c2554a245f9476e5e39869f948d2/pycocotools-2.0.0.tar.gz (1.5MB)
100% |████████████████████████████████| 1.5MB 1.9MB/s
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/tmp/pip-build-mut7_bkf/pycocotools/setup.py", line 2, in <module>
    from Cython.Build import cythonize
ModuleNotFoundError: No module named 'Cython'

----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-mut7_bkf/pycocotools/

我不理解这个错误,因为cython已经安装,而且在安装期间没有出现错误消息。

更新1

当我使用时,问题仍然存在。

python3 -m pip install 

但是,我有一些有趣的东西。在活跃的环境中:

@ : python3 -m pip --version
@ : pip 9.0.1 from /env/lib/python3.6/site-packages (python 3.6)

@ : python3 -m pip install --upgrade pip --user
/env/share/python-wheels/urllib3-1.22-py2.py3-none-any.whl/urllib3/connectionpool.py:860: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
Collecting pip
/env/share/python-wheels/urllib3-1.22-py2.py3-none-any.whl/urllib3/connectionpool.py:860: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
/env/share/python-wheels/urllib3-1.22-py2.py3-none-any.whl/urllib3/connectionpool.py:860: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
Downloading https://files.pythonhosted.org/packages/54/0c/d01aa759fdc501a58f431eb594a17495f15b88da142ce14b5845662c13f3/pip-20.0.2-py2.py3-none-any.whl (1.4MB)
100% |████████████████████████████████| 1.4MB 1.6MB/s
Installing collected packages: pip
Successfully installed pip-20.0.2

@ : python3 -m pip --version
@ : pip 9.0.1 from /env/lib/python3.6/site-packages (python 3.6)

所以,这个包被正确地下载和安装了,但是当我调用它时没有任何变化。我怀疑路径不同,但不知道如何解决。

有人能帮帮我吗?

最好的祝福,

克里斯


请使用 pip3 而不是 pip - Kalana
我使用的是pip3版本20.0.2。我尝试过python3 -m pip,但似乎安装路径和命令行中应用程序调用的路径不同。 - Chris PERE
1个回答

3

正确的安装应该像这样。

pip3 install Cython

pip3 install pycocotools

如果您使用conda环境

conda install -c anaconda cython

conda install -c conda-forge pycocotools
conda install -c conda-forge/label/gcc7 pycocotools     #choose one of these three
conda install -c conda-forge/label/cf201901 pycocotools

更新

如果上述语句不起作用,那么可能是因为您正在使用多个Python版本。因此,在安装任何软件包时,请指定您的Python版本,如下所示。

python3.6 -m pip install cython

如果您在执行这些步骤后遇到任何错误,请将该错误日志添加到您的问题中。

谢谢,但我尝试过这个方法,不起作用。我会在编辑中添加日志。 - Chris PERE
我已经更新了我的答案。请尝试一下并告诉我进展情况。 - Kalana
没什么改变,我也会尝试这个方法,但结果还是一样。 - Chris PERE

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接