Closed 1rdsk1 closed 1 year ago
Hi @1rdsk1 I am only now aware of this problem. On Linux it gives no errors. Try to have a look here. https://stackoverflow.com/questions/7508803/how-do-i-import-function-from-pyx-file-in-python Let me know if it works.
Thanks. I added a first cell with: import pyximport pyximport.install()
Unfortunately that led to a different error below which makes little sense to me apart from possibly "FutureWarning: Cython directive 'language_level' not set". I have FMNM running in ubuntu fine and so this is more for info in case you can spot the issue?
DistutilsExecError Traceback (most recent call last) ~\anaconda3\lib\distutils_msvccompiler.py in compile(self, sources, output_dir, macros, include_dirs, debug, extra_preargs, extra_postargs, depends) 411 try: --> 412 self.spawn(args) 413 except DistutilsExecError as msg:
~\anaconda3\lib\distutils_msvccompiler.py in spawn(self, cmd) 517 os.environ['path'] = self._paths --> 518 return super().spawn(cmd) 519 finally:
~\anaconda3\lib\distutils\ccompiler.py in spawn(self, cmd) 909 def spawn(self, cmd): --> 910 spawn(cmd, dry_run=self.dry_run) 911
~\anaconda3\lib\distutils\spawn.py in spawn(cmd, search_path, verbose, dry_run) 37 elif os.name == 'nt': ---> 38 _spawn_nt(cmd, search_path, dry_run=dry_run) 39 else:
~\anaconda3\lib\distutils\spawn.py in _spawn_nt(cmd, search_path, verbose, dry_run) 79 cmd = executable ---> 80 raise DistutilsExecError( 81 "command %r failed with exit status %d" % (cmd, rc))
DistutilsExecError: command 'C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\cl.exe' failed with exit status 2
During handling of the above exception, another exception occurred:
CompileError Traceback (most recent call last) ~\anaconda3\lib\site-packages\pyximport\pyximport.py in load_module(name, pyxfilename, pyxbuild_dir, is_package, build_inplace, language_level, so_path) 213 module_name = name --> 214 so_path = build_module(module_name, pyxfilename, pyxbuild_dir, 215 inplace=build_inplace, language_level=language_level)
~\anaconda3\lib\site-packages\pyximport\pyximport.py in build_module(name, pyxfilename, pyxbuild_dir, inplace, language_level) 185 from . import pyxbuild --> 186 so_path = pyxbuild.pyx_to_dll(pyxfilename, extension_mod, 187 build_in_temp=build_in_temp,
~\anaconda3\lib\site-packages\pyximport\pyxbuild.py in pyx_to_dll(filename, ext, force_rebuild, build_in_temp, pyxbuild_dir, setup_args, reload_support, inplace) 101 obj_build_ext = dist.get_command_obj("build_ext") --> 102 dist.run_commands() 103 so_path = obj_build_ext.get_outputs()[0]
~\anaconda3\lib\distutils\dist.py in run_commands(self) 965 for cmd in self.commands: --> 966 self.run_command(cmd) 967
~\anaconda3\lib\distutils\dist.py in run_command(self, command) 984 cmd_obj.ensure_finalized() --> 985 cmd_obj.run() 986 self.have_run[command] = 1
~\anaconda3\lib\site-packages\Cython\Distutils\old_build_ext.py in run(self) 185 --> 186 _build_ext.build_ext.run(self) 187
~\anaconda3\lib\distutils\command\build_ext.py in run(self) 339 # Now actually compile and link everything. --> 340 self.build_extensions() 341
~\anaconda3\lib\site-packages\Cython\Distutils\old_build_ext.py in build_extensions(self) 194 # Call original build_extensions --> 195 _build_ext.build_ext.build_extensions(self) 196
~\anaconda3\lib\distutils\command\build_ext.py in build_extensions(self) 448 else: --> 449 self._build_extensions_serial() 450
~\anaconda3\lib\distutils\command\build_ext.py in _build_extensions_serial(self) 473 with self._filter_build_errors(ext): --> 474 self.build_extension(ext) 475
~\anaconda3\lib\distutils\command\build_ext.py in build_extension(self, ext) 527 --> 528 objects = self.compiler.compile(sources, 529 output_dir=self.build_temp,
~\anaconda3\lib\distutils_msvccompiler.py in compile(self, sources, output_dir, macros, include_dirs, debug, extra_preargs, extra_postargs, depends) 413 except DistutilsExecError as msg: --> 414 raise CompileError(msg) 415
CompileError: command 'C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\cl.exe' failed with exit status 2
During handling of the above exception, another exception occurred:
ImportError Traceback (most recent call last)
Thanks @1rdsk1 , I don't have access to Windows so I can't test. Hope your comment can help other users in some way.
i'm new to python,and i'm very interested in this programe, i use jupyter notebook on a macbookpro. i confront with the same problem,too. can not 'from functions.cython.cython_functions import SOR', Error: No module named 'functions.cython.cython_functions' it seems it can not import " cython_functions.pyx" . and " cython_Heston.pyx", how to import ".pyx" into jupyter notebook? i tried many ways , including: import pyximport pyximport.install() but it didn't work
ModuleNotFoundError: No module named 'functions.cython.cython_Heston'
after trying so many times,i made it work by this "https://cython.readthedocs.io/en/latest/src/quickstart/build.html".
3.again , after trying so many times,i made it work on Windows. U need to install a "Build Tools for Visual Studio 2015 or 2017 or 20xx (version xxxxx)" from "https://visualstudio.microsoft.com/zh-hant/visual-cpp-build-tools/", so that the Windows can compile the ".pyx" document.
Thanks to you @lan-slot for making this solution available.
Thanks to @lan-slot ,I solve the problem in windows. You need to run "...\functions\cython\setup.py" in your terminal or cmd, then you will get the "cython_functions.cp38-win_amd64" and other required files. See https://cython.readthedocs.io/en/latest/src/quickstart/build.html
Hi @lan-slot, I have the same problem ("'from functions.cython.cython_functions import SOR', Error: No module named 'functions.cython.cython_functions'") with my MacBook Pro, and I have tried so many times, but I'm still having the trouble, could you help me?
I decided to create a local package that compiles cython during installation. This should solve many problems, and the user is not required anymore to compile cython by himself.
Hi, on my new windows 10 laptop, I installed all packages in requirements.txt and ran the cython build. Following your response to another issue I also installed visualcppbuildtools_full.exe.
(FMNM) C:\Users\x\Documents\FMNM>cd functions/cython (FMNM) C:\Users\x\Documents\FMNM\functions\cython>python setup.py build_ext --inplace running build_ext running build_ext (FMNM) C:\Users\x\Documents\FMNM\functions\cython>
When I run the imports at the start of 1.4 SDE - Heston model in Anaconda Jupyter, I get following error:
ModuleNotFoundError Traceback (most recent call last)