什么是pyximport,应该如何使用? [英] What is pyximport and how should I use it?

查看:711
本文介绍了什么是pyximport,应该如何使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用cython为数学模型生成更快的代码。
我很难编译代码,但是以某种方式设法使用.bat做到了这一点:

I am using cython to generate faster code for a mathematical model. I am having a hard time compiling the code, but somehow I managed to do so using a .bat:

setlocal EnableDelayedExpansion

CALL "C:\Program Files\Microsoft SDKs\Windows\v7.0\Bin\SetEnv.cmd" /x64 /release
set DISTUTILS_USE_SDK=1

C:\Python27\python.exe C:\gcsilve\trunk\myproject\myproject\cythonsetup.py build_ext --inplace

PAUSE

运行正常...

我的问题是关于pyximport。我有其他人使用pyximport.install()编写的旧代码。我无法弄清楚它的作用以及为什么要使用它,因为我已经在自己编译代码了。因此,有人可以用一种非常简单的方式(对于虚拟人)向我解释pyximport的作用吗?

My question is regarding pyximport. I have old code written by someone else that uses pyximport.install(). I couldn't figure out what it does and why I should use it, since I am already compiling the code by myself. So, can someone explain to me in a very simple (for dummies) way what pyximport does?

其他信息:
我有一个使用cython的project1。
我有一个引用project1的project2。

Additional information: I have a project1, using cython. I have a project2, that references project1.

推荐答案

pyximport是Cython的一部分,它代替了Cython。 导入

pyximport is part of Cython, and it's used in place of import in a way.

如果您的模块不需要任何额外的C库或特殊的构建设置,那么您可以使用pyximport模块直接在导入时加载.pyx文件,而无需编写setup.py文件。可以这样使用:

If your module doesn’t require any extra C libraries or a special build setup, then you can use the pyximport module to load .pyx files directly on import, without having to write a setup.py file. It can be used like this:

>>> import pyximport; pyximport.install()
>>> import helloworld
Hello World

直接从 Cython文档

这篇关于什么是pyximport,应该如何使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆