Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cx_Freeze - ImportError: No module named 'scipy.spatial.ckdtree' #233

Closed
anthony-tuininga opened this issue Jan 20, 2017 · 21 comments · Fixed by #626
Closed

cx_Freeze - ImportError: No module named 'scipy.spatial.ckdtree' #233

anthony-tuininga opened this issue Jan 20, 2017 · 21 comments · Fixed by #626
Assignees

Comments

@anthony-tuininga
Copy link
Collaborator

Originally reported by: Anonymous


exe was build .but,not working error will come


@nickvandewiele
Copy link

Is there a way to temporarily sidestep this error, while a more permanent solution is in the works? E.g. can I manually copy files into a location?

@nickvandewiele
Copy link

Nevermind, simply copying scipy/spatial/ckdtree.py into the frozen subfolder did the trick.

@kai06046
Copy link

I compare the scipy included files under exe build path with my python path, found that there is a file name conflict between cKDTree.cp35-win_amd64.pyd in exe build path and ckdtree.cp35-win_amd64.pyd in my python path. Renaming and then exe can run.

@arjd
Copy link

arjd commented Jun 5, 2017

This is also an issue for me, and it's preventing me from deploying an msi. Is there a way to target the dist folder instead to create an msi?

@arjd
Copy link

arjd commented Jun 17, 2017

Think I found the problem. cx_Freeze looks like it's duplicating this module, the first time with the wrong name; and when it tries to write the second time I suppose the first .pyd won't get overwritten. Yay for Windows not being case-sensitive!!!!

From the modules list from cx_Freeze.finder:

<Module name='scipy.spatial.cKDTree', file='omitting my python path.....\\lib\\site-packages\\scipy\\spatial\\cKDTree.cp36-win32.pyd'>
<Module name='scipy.spatial.ckdtree', file='omitting my python path.....\\lib\\site-packages\\scipy\\spatial\\ckdtree.cp36-win32.pyd'>

There is no cKDTree module. It's only ckdtree. I'm not even sure how it got the capitalized .pyd file cause it doesn't even exist. I did check the module itself just to be thorough and there isn't even a class named cKDTree, only KDTree. The module docstrings do suggest there might be some cKDTree cxx file somewhere but I think those are kept and maintained by the scipy team only as I can't find anything like that.

I wrote a really hanky 5 line workaround to get this thing to work but I'm really not pleased with this solution. My guess is that the root cause is somewhere in the finder.py module with all the hanky _Import helper subfunctions. Not sure why the choice was made to recurse that way but w/e.

@danaukes
Copy link

danaukes commented Jun 26, 2017

this might be a conflict between the cKDTree class and the ckdtree module and how it gets imported in other packages. I see it's used in astropy and sklearn packages as well as from within scipy in several places.

if you don't need ckdtree, then in lib/site-packages/scipy/spatial/init.py, comment out line 94:
from ckdtree import *

@7kbird
Copy link

7kbird commented Nov 30, 2017

I found a simple workaround on windows:

add 'scipy.spatial.cKDTree' to excludes in build_exe options

then the cKDTree.*.pyd will not be copied but the ckdtree.*.pyd is kept in the lib\scipy\spatial of the build folder

@anthony-tuininga
Copy link
Collaborator Author

Is this still relevant for the latest code on the v5.x and master branches? Its possible another bug fix may have corrected this already.

@danaukes
Copy link

danaukes commented Dec 10, 2017 via email

@ghost
Copy link

ghost commented Apr 5, 2018

I just encountered this problem using the 5.1.1 release. I followed @7kbird 's advice about excluding 'scipy.spatial.cKDTree' and that work in my situation.

@Overdrivr
Copy link

I can confirm it too. Workaround from @7kbird works, please note if you're not paying attention like me that the typo is important. scipy.spatial.cKDTree works, scipy.spatial.ckdtree doesn't.

@yucongo
Copy link

yucongo commented Jun 1, 2019

Workaround from @7kbird didnt work in my case. I had to rename cKDTree.cp36-win_amd64.pyd to ckdtree.pyd in the relevant build directory (lib\scipy\spatial).

@marcelotduarte
Copy link
Owner

cx_Freeze 6.1 has just been released.
Assuming this has been resolved.
If you had issues please re-open.

@bryantChhun
Copy link

bryantChhun commented Jan 10, 2020

Sadly, I struggled with exactly this problem today, And then @7kbird 's post works to solve it.

Using version 6.1 on windows 10

@mpetitjean
Copy link

mpetitjean commented Mar 25, 2020

I just came across the same issue today using cx_Freeze 6.1 under Windows 10, and the workaround of @7kbird did the trick.

I suppose we should re-open the issue ?

@marcelotduarte
Copy link
Owner

I'll make a PR for the next release.

@marcelotduarte marcelotduarte self-assigned this Mar 25, 2020
@marcelotduarte marcelotduarte linked a pull request Mar 31, 2020 that will close this issue
@marcelotduarte
Copy link
Owner

Can you test the PR? (only if you have a C compiler)

pip install -U git+https://github.com/anthony-tuininga/cx_Freeze.git@refs/pull/626/head

@marinaPauw
Copy link

Please note, this issue still exists. I find the same issue with none of the workarounds working for me.

@marcelotduarte
Copy link
Owner

@marinaPauw, was your test with cx-freeze 6.1 or current master?
To test with the current master (only if you have a C compiler):
pip uninstall -y cx_Freeze
pip install git+https://github.com/anthony-tuininga/cx_Freeze.git@master

@marinaPauw
Copy link

I was using the latest version available via pip install --upgrade, but it seems the issue had indeed been resolved. I was stuck so long with it I uninstalled python and all the packages and re-installed only the ones I needed for this project and now it seems to work! Despite my having previously reinstalled scipy itself. So probably one of the packages was installed incorrectly or there was a version mismatch somewhere. Either way, I no longer get this error, thanks for your rapid response!

@double0darbo
Copy link

double0darbo commented Jul 2, 2020

I was getting a similar issue on scipy.ndimage:

File "<dir>\Anaconda3\envs\clone37\lib\site-packages\scipy\ndimage\__init__.py", line 151, in <module>
    from .filters import *
  File "<dir>\Anaconda3\envs\clone37\lib\site-packages\scipy\ndimage\filters.py", line 36, in <module>
    from . import _ni_support
ImportError: cannot import name '_ni_support' from 'scipy.ndimage' (<dir>\Anaconda3\envs\clone37\build\exe.win-amd64-3.7\lib\scipy\ndimage\__init__.pyc)

I needed to remove the build files copied over, and then it worked.

However, I am still getting an issue with running the .exe on its own. Inside the command line, it works fine. Once I try clicking on the .exe, it freezes and dies.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.