python - 发生异常:ModuleNotFoundError
问题描述
我目前正在尝试学习 Cython,并在此处遵循了教程。
我让它在 Ubuntu(在 vmware 上)中工作,但现在我正试图让它在 Windows 上工作(使用 VSCode)。我把我在 Ubuntu 中创建的所有文件都放到了我的机器上。
当我尝试运行我的 python 文件 testing.py 时,我收到此错误:发生异常:ModuleNotFoundError No module named 'example_cy'
这是 testing.py 的代码
import timeit
cy = timeit.timeit('example_cy.test(5000)', setup = 'import example_cy', number = 1000)
py = timeit.timeit('example_py.test(5000)', setup = 'import example_py', number = 1000)
print(cy, py)
print('Cython is {}x faster'.format(py/cy))
这是 example_cy.pyx 文件
cpdef int test(int x):
cdef int y = 0
cdef int i
for i in range(x):
y += i
return y
example_py.py 文件
def test(x):
y = 0
for i in range(x):
y += i
return y
和 setup.py 代码
from distutils.core import setup
from Cython.Build import cythonize
setup(ext_modules = cythonize('example_cy.pyx'))
解决方案
推荐阅读
- python - 为什么 `while i==50` 不做与 `while i<=50` 相同的事情?
- service-worker - javascript 后台同步 android 电源按钮
- javascript - 处理来自后端的反应数据的最佳方法
- android - 如何将默认工具栏标题文本从@string/app_name 更改为“”,但只更改styles.xml?
- javascript - 错误:无法读取未定义的属性“状态”,努力让前端工作
- python - Errno 13 权限被拒绝 Keras VGG16
- python - 如何在 Seaborn 中绘制几列?
- javascript - 如果通过 UWP JavaScript 按下多个游戏手柄按钮
- ruby-on-rails - 不同 ResourceController 的共享资源
- sql-server - 如何在 Azure Synapse 专用池中监视较旧的查询历史记录和查询计划