简体   繁体   中英

Running python code through Cython with command line arguments

I have a Python code that uses two command line arguments. I am using linux terminal for all command line tasks. Now I am trying to use Cython to speed up my Python code. For that I have compiled the Python code to C using build_ext module by creating this setup.py file:

setup.py

from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext
setup (
cmdclass = {'build_ext': build_ext } ,
ext_modules = [
Extension ("myCode", ["myCode.py"]) ,
])

And then compiling my Python code into C using:

python setup.py build_ext -i

The following were generated:

[file]myCode.c
[file]myCode.so
[folder]build
--[folder]temp.linux-x86_64-2.7
----[file]myCode.o

I want to run the generated file with command line arguments. Till now in Python I was using the usual command

>> python myCode.py arg1 arg2

I am very new to Cython, infact I started using it to address the inherent speed issue of Python after code level algorithm optimization. I need inputs on which files to run, and how to run the converted C code and with command line arguments. Thanks in advance.

As mentioned you compiled a Python module. So to call from Linux you have to write a .py script that imports your compiled module and does any calculations needed. Then you can run it with your typical Linux command.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM