By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,127 Members | 1,127 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,127 IT Pros & Developers. It's quick & easy.

distutils problem windows xp python 2.4.2

P: n/a
Hello I tried to combine c++ and python together.
So I follow from this website:
http://kortis.to/radix/python_ext/

I have this code:
# prmodule.c
static PyObject *pr_isprime(PyObject *self, PyObject *args){
int n, input;

if (!PyArg_ParseTuple(args, "i", &input))
return NULL;

if (input < 1) {
return Py_BuildValue("i", 0);
}

n = input - 1;

while (n > 1){
if (input%n == 0) return Py_BuildValue("i", 0);;
n--;
}

return Py_BuildValue("i", 1);
}

static PyMethodDef PrMethods[] = {
{"isprime", pr_isprime, METH_VARARGS, "Check if prime."},
{NULL, NULL, 0, NULL}
};

void initpr(void){
(void) Py_InitModule("pr", PrMethods);
}

and my setup.py file:
from distutils.core import setup, Extension
module = Extension('pr', sources = ['prmodule.c'])
setup(name = 'Pr test', version = '1.0', ext_modules = [module])

------------------------------------
If I run setup build
I've got the following error message
running build
running build_ext
error: The .NET Framework SDK needs to be installed before building
extensions for Python.

I use visual Studio 2005.

Thanks,
pujo

Dec 4 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
aj****@gmail.com wrote:
Hello I tried to combine c++ and python together.
So I follow from this website:
http://kortis.to/radix/python_ext/
....
and my setup.py file:
from distutils.core import setup, Extension
module = Extension('pr', sources = ['prmodule.c'])
setup(name = 'Pr test', version = '1.0', ext_modules = [module])

------------------------------------
If I run setup build
I've got the following error message
running build
running build_ext
error: The .NET Framework SDK needs to be installed before building
extensions for Python.

I use visual Studio 2005.

Thanks,
pujo

You might take a look at:

http://groups.google.com/group/comp....2?dmode=source

it provides code to change your setup code to:
from distutils.core import setup, Extension
module = Extension('pr', sources = ['prmodule.c'])

for attempts in range(2):
try:
setup(name='Pr test',
version='1.0',
ext_modules=[module])
except SystemExit, e: pass # Failure. Patch and try again
else: break # Successful run, no need to retry.

print '*** Apparently a failure:', e.args[0]
print '*** Patching and trying again'
import patch_msvccompiler

--Scott David Daniels
sc***********@acm.org
Dec 4 '05 #2

P: n/a
Hello Scott,

It didn't work with visual studio 5. .Net framework 2.0
Do you have any suggestions?

Thanks,
pujo

Dec 4 '05 #3

P: n/a
aj****@gmail.com wrote:
It didn't work with visual studio 5. .Net framework 2.0
Do you have any suggestions?


"It didn't work" is not very diagnosable.

--Scott David Daniels
sc***********@acm.org
Dec 4 '05 #4

P: n/a
Hello,

It give the same error result:
D:\testprogram\distutils problem>setup build
running build
running build_ext
*** Failed: error: The .NET Framework SDK needs to be installed before
building extensions for Python.
Attempting to patch distutils.msvccompiler and retry:
running build
running build_ext
*** Failed: error: The .NET Framework SDK needs to be installed before
building extensions for Python.
Attempting to patch distutils.msvccompiler and retry:

This is inside my setup.py
#from distutils.core import setup, Extension
#
#module = Extension('pr', sources = ['prmodule.c'])
#setup(name = 'Pr test', version = '1.0', ext_modules = [module])
#

__version__ = '0.3'

from distutils.core import setup, Extension

for attempts in range(2):
try:
setup(name='Pr test', version='1.0',
ext_modules=[Extension('pr', ['prmodule.c'])])
except SystemExit, e:
print '*** Failed:', e.args[0]
else:
break # Successful (avoid the retry)
print 'Attempting to patch distutils.msvccompiler and retry:'

import distutils.msvccompiler

class BatReader(object):
def __init__(self, batch_filename):
self.source = open(batch_filename, 'rU')

def getsets(self):
'''Get all command lines which are "SET" commands.'''
self.source.seek(0)
for line in self.source:
try: command, rest = line.split(None, 1)
except ValueError: continue # Set a=b splits fine
if command.lower() == 'set':
try: key, value = rest.split('=', 1)
except ValueError: continue # breaking a=b;c;d
elif command.lower() == 'path':
key, value = command, rest #path x == set path=x
yield key, value.rstrip()

def paths(self, pathkey):
'''Find the file paths using our getsets methods.'''
keyed = pathkey.upper()
for key, paths in self.getsets():
if key.upper() == keyed:
elements = paths.split(';')
if elements[-1].upper() == keyed.join('%%'):
return elements[: -1]
return elements

class MSVCCompiler(distutils.msvccompiler.MSVCCompiler):
_patho = BatReader(r'C:\Program Files\Microsoft Visual Studio
8\VC\bin\vcvars32.bat') # or vcvars32.bat or ...
def get_msvc_paths(self, path, platform='x86'):
if path == 'library': path = 'lib'
return self._patho.paths(path)

distutils.msvccompiler.MSVCCompiler = MSVCCompiler
# OK, patched it, now go try again.

Yours,
pujo

Dec 5 '05 #5

P: n/a
aj****@gmail.com wrote:
....
*** Failed: error: The .NET Framework SDK needs to be installed before
building extensions for Python.

....
It is so much easier with the actual error messages.

Ah-ha -- you installed the compiler but not the .NET Framework.
You have more downloading and installing to do.

See, for example:
http://www.vrplumber.com/programming/mstoolkit/

--Scott David Daniels
sc***********@acm.org
Dec 5 '05 #6

P: n/a
Hello,

I have .net framework 2.0 because I' already able to run visual studio
express 2005.
Should I install .net framework 1.1 and also ms toolkit ?

Sincerely Yours,
pujo

Dec 6 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.