Unlike C language, Python is an interpreted programming language that allows you to execute programs immediately without compiling. It's very convenient, but interpreter-type programming languages run slower than languages that require compilation, such as C. This time, I will introduce a library called Cython that can convert Python to C language files.
Preparing the program is easy, just change the extension of the program file from .py to .pyx
loop.py
for i in range(1000):
print(i)
↓↓↓
loop.pyx
for i in range(1000):
print(i)
If so, the file is ready
Click the link below to download and install Visual Sudio 2019 Click here to go to the Visual Studio 2019 download page (https://visualstudio.microsoft.com/ja/downloads/)
With a command prompt
Command prompt
pip install cython
And press the enter key (return key)
After that, move to the folder with the Python file with the command prompt, and
Command prompt
cythonize loop.pyx
Just type and press the enter key (return key)
Then loop.c will be completed immediately
Thank you for reading this article until the end This time, I introduced how to convert Python files to C language files with Cython. If you have any questions, please leave them in the comments. Thank you very much See you next time