How to change/set compiler option for weave inline function
Robert
rxjwg98 at gmail.com
Sun Dec 27 14:08:44 EST 2015
Hi,
I want to run a few C code inside Python on Windows 7, 64-bit PC, Canopy 1.5.2.2785. I made a few trials, but I forget the detail commands I made on compiler setting. One thing I remember is that I added one file: distutils.cfg, whose content is: [build]
compiler=mingw32
And another thing I did was an option to msvc for the compiler, but I don't remember where the file was.
Now, it always search for 'msvccompiler', though I think it should use mingw32, as the following:
import scipy.weave
In [16]: weave.test()
Running unit tests for scipy.weave
NumPy version 1.9.2..................................S.SSS....SSSSSS.................................................................................................
NumPy is installed in C:\Users\jj\AppData\Local\Enthought\Canopy\User\lib\site-packages\numpy
SciPy version 0.16.1
SciPy is installed in C:\Users\jj\AppData\Local\Enthought\Canopy\User\lib\site-packages\scipy
Python version 2.7.6 | 64-bit | (default, Sep 15 2014, 17:36:35) [MSC v.1500 64 bit (AMD64)]
nose version 1.3.4
----------------------------------------------------------------------
Ran 146 tests in 5.652s
OK (SKIP=10)
Out[16]: <nose.result.TextTestResult run=146 errors=0 failures=0>
In [17]: a = 1
In [18]: weave.inline('printf("%d\\n",a);',['a'])
No module named msvccompiler in numpy.distutils; trying from distutils
objdump.exe: C:\Users\jj\AppData\Local\Enthought\Canopy\User\python27.dll: File format not recognized
Looking for python27.dll
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-18-90fb916ec9e2> in <module>()
----> 1 weave.inline('printf("%d\\n",a);',['a'])
C:\Users\rj\AppData\Local\Enthought\Canopy\User\lib\site-packages\scipy\weave\inline_tools.pyc in inline(code, arg_names, local_dict, global_dict, force, compiler, verbose, support_code, headers, customize, type_converters, auto_downcast, newarr_converter, **kw)
364 type_converters=type_converters,
365 auto_downcast=auto_downcast,
--> 366 **kw)
367
368 function_catalog.add_function(code,func,module_dir)
C:\Users\jj\AppData\Local\Enthought\Canopy\User\lib\site-packages\scipy\weave\inline_tools.pyc in compile_function(code, arg_names, local_dict, global_dict, module_dir, compiler, verbose, support_code, headers, customize, type_converters, auto_downcast, **kw)
494 # setting. All input keywords are passed through to distutils
495 mod.compile(location=storage_dir,compiler=compiler,
--> 496 verbose=verbose, **kw)
497
498 # import the module and return the function. Make sure
C:\Users\jj\AppData\Local\Enthought\Canopy\User\lib\site-packages\scipy\weave\ext_tools.pyc in compile(self, location, compiler, verbose, **kw)
371 success = build_tools.build_extension(file, temp_dir=temp,
372 compiler_name=compiler,
--> 373 verbose=verbose, **kw)
374 if not success:
375 raise SystemError('Compilation failed')
C:\Users\jj\AppData\Local\Enthought\Canopy\User\lib\site-packages\scipy\weave\build_tools.pyc in build_extension(module_path, compiler_name, build_dir, temp_dir, verbose, **kw)
277 environ = copy.deepcopy(os.environ)
278 try:
--> 279 setup(name=module_name, ext_modules=[ext],verbose=verb)
280 finally:
281 # restore state
C:\Users\jj\AppData\Local\Enthought\Canopy\User\lib\site-packages\numpy\distutils\core.pyc in setup(**attr)
167 new_attr['distclass'] = NumpyDistribution
168
--> 169 return old_setup(**new_attr)
170
171 def _check_append_library(libraries, item):
C:\Users\jj\AppData\Local\Enthought\Canopy\App\appdata\canopy-1.5.2.2785.win-x86_64\lib\distutils\core.pyc in setup(**attrs)
150 if ok:
151 try:
--> 152 dist.run_commands()
153 except KeyboardInterrupt:
154 raise SystemExit, "interrupted"
C:\Users\jj\AppData\Local\Enthought\Canopy\App\appdata\canopy-1.5.2.2785.win-x86_64\lib\distutils\dist.pyc in run_commands(self)
951 """
952 for cmd in self.commands:
--> 953 self.run_command(cmd)
954
955 # -- Methods that operate on its Commands --------------------------
C:\Users\jj\AppData\Local\Enthought\Canopy\App\appdata\canopy-1.5.2.2785.win-x86_64\lib\distutils\dist.pyc in run_command(self, command)
970 cmd_obj = self.get_command_obj(command)
971 cmd_obj.ensure_finalized()
--> 972 cmd_obj.run()
973 self.have_run[command] = 1
974
C:\Users\jj\AppData\Local\Enthought\Canopy\User\lib\site-packages\numpy\distutils\command\build_ext.pyc in run(self)
92 verbose=self.verbose,
93 dry_run=self.dry_run,
---> 94 force=self.force)
95 self.compiler.customize(self.distribution)
96 self.compiler.customize_cmd(self)
C:\Users\jj\AppData\Local\Enthought\Canopy\User\lib\site-packages\numpy\distutils\ccompiler.pyc in new_compiler(plat, compiler, verbose, dry_run, force)
560 raise DistutilsModuleError(("can't compile C/C++ code: unable to find class '%s' " +
561 "in module '%s'") % (class_name, module_name))
--> 562 compiler = klass(None, dry_run, force)
563 log.debug('new_compiler returns %s' % (klass))
564 return compiler
C:\Users\jj\AppData\Local\Enthought\Canopy\User\lib\site-packages\numpy\distutils\mingw32ccompiler.pyc in __init__(self, verbose, dry_run, force)
89 # 1. Check for import library on Windows. Build if it doesn't exist.
90
---> 91 build_import_library()
92
93 # Check for custom msvc runtime library on Windows. Build if it doesn't exist.
C:\Users\jj\AppData\Local\Enthought\Canopy\User\lib\site-packages\numpy\distutils\mingw32ccompiler.pyc in build_import_library()
376 arch = get_build_architecture()
377 if arch == 'AMD64':
--> 378 return _build_import_library_amd64()
379 elif arch == 'Intel':
380 return _build_import_library_x86()
C:\Users\jj\AppData\Local\Enthought\Canopy\User\lib\site-packages\numpy\distutils\mingw32ccompiler.pyc in _build_import_library_amd64()
397 % (out_file, dll_file))
398
--> 399 generate_def(dll_file, def_file)
400
401 cmd = ['dlltool', '-d', def_file, '-l', out_file]
C:\Users\jj\AppData\Local\Enthought\Canopy\User\lib\site-packages\numpy\distutils\mingw32ccompiler.pyc in generate_def(dll, dfile)
276 break
277 else:
--> 278 raise ValueError("Symbol table not found")
279
280 syms = []
ValueError: Symbol table not found
How can I set correctly to use inline C code?
Thanks
More information about the Python-list
mailing list