Hello,
I am entirely new to Cython and C++. When I try to compile the standard prime number generator example with a setup.py file, the cythonPrimes.c file is created, but get the WinError 2 saying that the file could not be found. This is the output:
__________________________________________________________________________________
C:\Users\user\Documents\GitHub\cythonTest>python setup.py build_ext --inplace
running build_ext
building 'cythonPrimes' extension
error: [WinError 2] Het systeem kan het opgegeven bestand niet vinden
__________________________________________________________________________________
It looks to me that there is some problem with the compiler. I have installed Visual Studio Build Tools 2022, which looks like it works fine:
__________________________________________________________________________________
C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools>cl
Microsoft (R) C/C++ Optimizing Compiler Version 19.37.32825 for x86
Copyright (C) Microsoft Corporation. All rights reserved.
usage: cl [ option... ] filename... [ /link linkoption... ]
__________________________________________________________________________________
This is the setup.py file:
__________________________________________________________________________________
from setuptools import setup
from Cython.Build import cythonize
setup(
ext_modules = cythonize("cythonPrimes.pyx", language_level="3"),
)
__________________________________________________________________________________
And cythonPrimes.pyx:
__________________________________________________________________________________
def primes(int amount):
cdef int current_number = 2
cdef int primes_found = 0
cdef int[100000] primes
if amount>100000:
amount = 100000
while primes_found < amount:
for prime in primes[:primes_found]:
if current_number % prime == 0:
break
else:
primes[primes_found] = current_number
primes_found += 1
current_number += 1
primes_as_python_list = [prime for prime in primes[:primes_found]]
return(primes_as_python_list)
__________________________________________________________________________________
I've also created the pyproject.toml file as the cython docs mentioned:
__________________________________________________________________________________
[build-system]
requires = ["setuptools", "wheel", "Cython"]
__________________________________________________________________________________
Is there something in the code or do I have to setup the compiler (I've just downloaded and installed it) to make this work?