1

Following my previous question here, I would like to import this C/C++ implementation of sha256 into my python script (Python 3.7.0) and run some performance tests.

From the official documentation it seems that one way of doing this is to use distutil built-in module of python to package this as a new module and then install it so that it becomes importable to any script.

The first step I took was to download the sha256module.c code and save it into my current directory. In the same directory, I then created a setup.py with the following content that python's documentation recommends here.

setup.py:

from distutils.core import setup
from distutils.extension import Extension
setup(name='sha256_test1',
      version='1.0',
      description = 'This is a test sha256 function',
      ext_modules=[Extension('sha256', sources = ['sha256module.c'])],
      )

After creating the setup file, from command prompt and in the same directory as the setup I run python setup.py build. In the first place, I received "Unable to find vcvarsall.bat" error and based on the answer to this question I installed visual studio 2017 community version on my Win10 x64 operating system. The error is gone. But I received errors indicating lack of some other files that seemed necessary for packaging. They are listed as:

hashlib.h
coreconfig.h
pystrhex.h
python.h
structmember.h
tracemalloc.h
clinic/sha256module.c.h

I added them to the current directory and when I run python setup.py build again I get another error saying "note: see declaration of '_PyInitError" which I assumed might be from the lack of __init__.py so I created an empty one but it didn't work.

I am not sure if I am doing this all the way right. What do you think about this procedure?! Am I on the correct direction?! If yes please tell me how to tackle the error and if no please indicate why and where I am doing wrong.

PouJa
  • 180
  • 4
  • 13

0 Answers0