4

I am creating a Windows EXE using cx_freeze, Python3 and the Scipy installation from lfd.uci.edu. Upon running the exe, I receive the error: ImportError: cannot import name nonlin.

The Scipy file line this references, in site-packages\scipy\optimize_root.py: from . import nonlin.

I can load a console with Python, and successfully run import scipy.optimize.nonlin. Adding scipy.optimize.nonlin to my setup.py includes doesn't solve the problem.

nonlin.py is located in the optimize directory in my scipy install, and its corresponding location as a compiled file in the library file cx_freeze generates.

Turtles Are Cute
  • 3,200
  • 6
  • 30
  • 38
  • Can you show the output from freezing it? – Thomas K Sep 25 '13 at 17:57
  • The full file is here (long): [link](http://tlar.crappyfiles.com/nonlin_error.txt) Line 791: 'm scipy.optimize.nonlin C:\Python33\lib\site-packages\scipy\optimize\nonlin.py' I do notice no nonlin.pyd in the 'Copying' section around line 1170. No idea if it should be there, and the file's not in my Python install. – Turtles Are Cute Sep 25 '13 at 21:24
  • 1
    Nope, it's a .py file, not a .pyd, so it will be copied into the zip file, as you found. I'm not sure, but it might be having trouble with the relative import syntax. Are you using the latest version of cx_Freeze? We'll hopefully have a new version for you to try soon. – Thomas K Sep 26 '13 at 23:53
  • I'm using cx_Freeze 4.3.1. Looking forward to the new version. I'm currently trying to install the [dev version](https://bitbucket.org/anthony_tuininga/cx_freeze/get/default.zip), and fighting with mingw. – Turtles Are Cute Sep 27 '13 at 01:35
  • Any word on when to expect the new version? Do you know if there are Windows binaries of the current dev version floating around? – Turtles Are Cute Sep 29 '13 at 15:20
  • 1
    Hopefully in the next week or two - there's a problem with setuptools that we'll need to work around first. Sorry, AFAIK no-one builds binaries of dev versions. – Thomas K Sep 29 '13 at 17:08

3 Answers3

1

I had the same trouble, but nonlin was imported in "/scipy/optimize/init.py" file. It is marked as "# Deprecated namespaces, to be removed in v2.0.0". You can just comment the string in file, where import nonlin is. It worked for me.

stchern
  • 11
  • 1
1

The reason I'm backing to this thread is that recently a friend of mine asked for help around this issue.

Given that, here is the same solution approach: Circular dependency while executing cx_Freeze result

In the setup script, just add the package failure references as below:

packages = ["scipy.optimize", "scipy.integrate", ...] 
0

I've had a lot of issues with cx_Freeze and Scipy. The only thing I really found to work was to either add the missing module to the "includes" option or to manually add the needed files to the "include_files" option.

This link helped me with interpolation. https://bitbucket.org/anthony_tuininga/cx_freeze/issue/43/import-errors-when-using-cx_freeze-with

{"includes": ["scipy.special._ufuncs_cxx"],
 "include_files": [(python_exe_path+"/Lib/site-packages/scipy/sparse/sparsetools/_csr.pyd",
                    "_csr.pyd") ],
}

This isn't exactly the same problem for you, but it may help you find the needed files to include them properly. "includes" didn't work for you, so you could manually add it with "include_files" or "zip_includes" depending on where it is searching for your file.

{"zip-include": (python_exe_path+"/Lib/site-packages/scipy/optimize/nonlin.py, 
                 "scipy/optimize/nonlin.py")}
justengel
  • 6,132
  • 4
  • 26
  • 42