ImportError: 没有名为_vectorized的模块

2 投票
1 回答
2099 浏览
提问于 2025-04-18 16:02

我在我的Python和Plone项目中使用Shapely这个包。在packages.cfg文件的eggs部分,我是这样写的来下载shapely的:

[eggs]
main =
      Shapely

在运行bin/buildout的时候,我发现shapely.vectorized有个问题。错误信息大概是这样的:

Numpy or Cython not available, shapely.vectorized submodule not being built.

我为我的Python函数创建了单元测试。当我运行我的文件时,出现了错误。错误的追踪信息是:

Module: shapely.tests.test_validation

Traceback (most recent call last):
File "/home/nirmalsudhir/zope/myProject/eggs/Shapely-1.3.3-py2.7-linux-i686.egg/shapely 
      /tests/__init__.py", line 27, in <module>
from . import test_doctests, test_prepared, test_equality, test_geomseq, \
File "/home/nirmalsudhir/zope/myProject/eggs/Shapely-1.3.3-py2.7-linux-i686.egg/shapely
      /tests/test_vectorized.py", line 3, in <module>
from shapely.vectorized import contains, touches
File "/home/nirmalsudhir/zope/myProject/eggs/Shapely-1.3.3-py2.7-linux-i686.egg/shapely
      /vectorized/__init__.py", line 3, in <module>
from ._vectorized import contains, touches
ImportError: No module named _vectorized

shapely/tests/__init__.py :

import sys
from shapely.geos import geos_version_string, lgeos, WKTWriter
from shapely import speedups

try:
    import numpy
    numpy_version = numpy.version.version
except ImportError:
    numpy = False
    numpy_version = 'not available'


if lgeos.geos_version >= (3, 3, 0):
    WKTWriter.defaults = {}

if sys.version_info[0:2] <= (2, 6):
   import unittest2 as unittest
else:
import unittest

from . import test_doctests, test_prepared, test_equality, test_geomseq // I get error here 

shapely/tests/test_vectorized.py:

from . import unittest, numpy
from shapely.geometry import Point, box, MultiPolygon
from shapely.vectorized import contains, touches

shapely/vectorized/__init__.py:

from ._vectorized import contains, touches

我不知道vectorized出了什么问题。有没有人能帮帮我。

1 个回答

1

你需要安装 Numpy 或 Cython。

在我的情况下,我使用的是虚拟环境,所以我只是执行了:

pip install numpy cython

你的问题没有提供关于你环境的具体信息,所以我不能确定这对你是否有效。

撰写回答