Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get rid of pyximport

Tags:

cython

spyder

I'm trying to use Cython. I use setup.py and build as opposed to letting pyximport do this. However, every time I import my module it seems pyximport is called. Pyximport fails to build and everything crashes.

I use Spyder. I do not have a single reference to pyximport in my project, but Spyder does not seem to care and keeps calling pyximprot.

I called my program from the command window (outside Spyder) and it ran just fine.

How can i get rid of the call to pyximport? Or is something else going on?

import c_result
Traceback (most recent call last):

  File "<ipython-input-2-3e92d1c50179>", line 1, in <module>
    import c_result

  File "C:\Users\xxx\AppData\Local\Continuum\Anaconda3\lib\site-packages\pyximport\pyximport.py", line 458, in load_module
language_level=self.language_level)

  File "C:\Users\xxxR\AppData\Local\Continuum\Anaconda3\lib\site-packages\pyximport\pyximport.py", line 231, in load_module
raise exc.with_traceback(tb)

  File "C:\Users\xxx\AppData\Local\Continuum\Anaconda3\lib\site-packages\pyximport\pyximport.py", line 215, in load_module
inplace=build_inplace, language_level=language_level)

  File "C:\Users\xxx\AppData\Local\Continuum\Anaconda3\lib\site-packages\pyximport\pyximport.py", line 191, in build_module
reload_support=pyxargs.reload_support)

  File "C:\Users\xxx\AppData\Local\Continuum\Anaconda3\lib\site-packages\pyximport\pyxbuild.py", line 102, in pyx_to_dll
dist.run_commands()

  File "C:\Users\xxx\AppData\Local\Continuum\Anaconda3\lib\distutils\dist.py", line 955, in run_commands
self.run_command(cmd)

  File "C:\Users\xxx\AppData\Local\Continuum\Anaconda3\lib\distutils\dist.py", line 974, in run_command
cmd_obj.run()

  File "C:\Users\xxx\AppData\Local\Continuum\Anaconda3\lib\site-packages\Cython\Distutils\old_build_ext.py", line 185, in run
_build_ext.build_ext.run(self)

  File "C:\Users\xxx\AppData\Local\Continuum\Anaconda3\lib\distutils\command\build_ext.py", line 339, in run
self.build_extensions()

  File "C:\Users\xxx\AppData\Local\Continuum\Anaconda3\lib\site-packages\Cython\Distutils\old_build_ext.py", line 192, in build_extensions
ext.sources = self.cython_sources(ext.sources, ext)

  File "C:\Users\xxx\AppData\Local\Continuum\Anaconda3\lib\site-packages\Cython\Distutils\old_build_ext.py", line 327, in cython_sources
self.mkpath(os.path.dirname(target))

  File "C:\Users\xxx\AppData\Local\Continuum\Anaconda3\lib\distutils\cmd.py", line 338, in mkpath
dir_util.mkpath(name, mode, dry_run=self.dry_run)

 File "C:\Users\xxx\AppData\Local\Continuum\Anaconda3\lib\distutils\dir_util.py", line 74, in mkpath
"could not create '%s': %s" % (head, exc.args[-1]))

ImportError: Building module c_result failed: ["distutils.errors.DistutilsFileError: could not create 'C:\\Windows\\system32\\config\\systemprofile': Kan ikke opprette en fil når filen allerede finnes\n"]
like image 498
mortysporty Avatar asked Sep 26 '17 09:09

mortysporty


1 Answers

The problem appeared in Spyder because the package's initialization actually loads pyximport and calls pyximport.install(), in the file utils/site/sitecustomize.py.

Other have complained about it on GitHub:

  • spyder issue #5299
  • spyder issue #5087

A solution that is not elegant (will not survive updates of spyder, for instance) but that should work is to manually edit the sitecustomize.py file in your spyder installation and remove the section under if HAS_PYXIMPORT:

like image 182
Pierre de Buyl Avatar answered Sep 28 '22 09:09

Pierre de Buyl