AttributeError: function 'cluster' not found
Dexter1618 opened this issue · 5 comments
Hi @Dexter1618, thanks for reporting this. Can you post the output from the pip
command you used to install kmeans1d
? This will require uninstalling the package in order to reinstall it.
I've tried replicating the issue you've encountered on Windows, but everything worked okay.
(untitled) C:\untitled>pip install kmeans1d
Collecting kmeans1d
Downloading kmeans1d-0.3.0.tar.gz (6.0 kB)
Building wheels for collected packages: kmeans1d
Building wheel for kmeans1d (setup.py) ... done
Created wheel for kmeans1d: filename=kmeans1d-0.3.0-cp38-cp38-win_amd64.whl size=17216 sha256=7a961a2ca014ab6df20ef6980a3325de59e32e8bc96
b0abd3b3755fccc5ce930
Stored in directory: c:\users\dan\appdata\local\pip\cache\wheels\9c\fb\c0\6d32c3cff8cc25e89b60113f1dac6a7f062dba46c9cbcec4c0
Successfully built kmeans1d
Installing collected packages: kmeans1d
Successfully installed kmeans1d-0.3.0
(untitled) C:\untitled>python
Python 3.8.5 (default, Aug 5 2020, 09:44:06) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import kmeans1d
>>>
>>> x = [4.0, 4.1, 4.2, -50, 200.2, 200.4, 200.9, 80, 100, 102]
>>> k = 4
>>> clusters, centroids = kmeans1d.cluster(x, k)
>>> clusters
[1, 1, 1, 0, 3, 3, 3, 2, 2, 2]
>>> centroids
[-50.0, 4.1, 94.0, 200.5]
@Dexter1618, when you reinstall, can you also pass the --verbose
and --no-cache-dir
flags?
> pip uninstall kmeans1d
> pip install --verbose --no-cache-dir kmeans1d
The output lines that I am interested in are the ones related to building wheels.
Building wheels for collected packages: kmeans1d
Created temporary directory: C:\Users\dan\AppData\Local\Temp\pip-wheel-tno8xvb4
Building wheel for kmeans1d (setup.py) ... Destination directory: C:\Users\dan\AppData\Local\Temp\pip-wheel-tno8xvb4
Running command 'C:\Users\dan\anaconda3\envs\untitled\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\dan\\AppData\\Local\\Temp
\\pip-install-n34vkr0w\\kmeans1d\\setup.py'"'"'; __file__='"'"'C:\\Users\\dan\\AppData\\Local\\Temp\\pip-install-n34vkr0w\\kmeans1d\\setup.py'"'"';f=getattr(tokenize, '"'"
'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d 'C:\Users\dan\AppDa
ta\Local\Temp\pip-wheel-tno8xvb4'
running bdist_wheel
running build
running build_py
creating build
creating build\lib.win-amd64-3.8
creating build\lib.win-amd64-3.8\kmeans1d
copying kmeans1d\core.py -> build\lib.win-amd64-3.8\kmeans1d
copying kmeans1d\__init__.py -> build\lib.win-amd64-3.8\kmeans1d
copying kmeans1d\version.txt -> build\lib.win-amd64-3.8\kmeans1d
running build_ext
building 'kmeans1d._core' extension
creating build\temp.win-amd64-3.8
creating build\temp.win-amd64-3.8\Release
creating build\temp.win-amd64-3.8\Release\kmeans1d
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\bin\HostX86\x64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -IC:\Users\dan\anacond
a3\envs\untitled\include -IC:\Users\dan\anaconda3\envs\untitled\include "-IC:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\ATLMFC\i
nclude" "-IC:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.1\include\um" "-IC
:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\shared" "-IC:\Program Files (x86)\Windows Kits\10\
include\10.0.17763.0\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\winrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\cppwinrt" /EHsc /Tpk
means1d/_core.cpp /Fobuild\temp.win-amd64-3.8\Release\kmeans1d/_core.obj -std=c++11
cl : Command line warning D9002 : ignoring unknown option '-std=c++11'
_core.cpp
kmeans1d/_core.cpp(245): warning C4244: '=': conversion from '_Ty' to 'ulong', possible loss of data
with
[
_Ty=double
]
kmeans1d/_core.cpp(63): warning C4267: 'initializing': conversion from 'size_t' to 'ulong', possible loss of data
kmeans1d/_core.cpp(95): note: see reference to function template instantiation 'void _smawk<T>(const std::vector<ulong,std::allocator<_Ty>> &,const std::vector<_Ty,std::allocat
or<_Ty>> &,const std::function<double (ulong,ulong)> &,std::vector<_Ty,std::allocator<_Ty>> *)' being compiled
with
[
T=double,
_Ty=ulong
]
kmeans1d/_core.cpp(199): note: see reference to function template instantiation 'std::vector<ulong,std::allocator<_Ty>> smawk<double>(const ulong,const ulong,const std::functio
n<double (ulong,ulong)> &)' being compiled
with
[
_Ty=ulong
]
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\bin\HostX86\x64\link.exe /nologo /INCREMENTAL:NO /LTCG /DLL /MANIFEST:EMBED,ID=2 /MANIFE
STUAC:NO /LIBPATH:C:\Users\dan\anaconda3\envs\untitled\libs /LIBPATH:C:\Users\dan\anaconda3\envs\untitled\PCbuild\amd64 "/LIBPATH:C:\Program Files (x86)\Microsoft V
isual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\ATLMFC\lib\x64" "/LIBPATH:C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\lib\x64" "
/LIBPATH:C:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.1\lib\um\x64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\10\lib\10.0.17763.0\ucrt\x64" "/LIBPATH:C:\Program Files (x8
6)\Windows Kits\10\lib\10.0.17763.0\um\x64" /EXPORT:PyInit__core build\temp.win-amd64-3.8\Release\kmeans1d/_core.obj /OUT:build\lib.win-amd64-3.8\kmeans1d\_core.cp38-win_amd64.py
d /IMPLIB:build\temp.win-amd64-3.8\Release\kmeans1d\_core.cp38-win_amd64.lib
Creating library build\temp.win-amd64-3.8\Release\kmeans1d\_core.cp38-win_amd64.lib and object build\temp.win-amd64-3.8\Release\kmeans1d\_core.cp38-win_amd64.exp
Generating code
Finished generating code
installing to build\bdist.win-amd64\wheel
running install
running install_lib
creating build\bdist.win-amd64
creating build\bdist.win-amd64\wheel
creating build\bdist.win-amd64\wheel\kmeans1d
copying build\lib.win-amd64-3.8\kmeans1d\core.py -> build\bdist.win-amd64\wheel\.\kmeans1d
copying build\lib.win-amd64-3.8\kmeans1d\version.txt -> build\bdist.win-amd64\wheel\.\kmeans1d
copying build\lib.win-amd64-3.8\kmeans1d\_core.cp38-win_amd64.pyd -> build\bdist.win-amd64\wheel\.\kmeans1d
copying build\lib.win-amd64-3.8\kmeans1d\__init__.py -> build\bdist.win-amd64\wheel\.\kmeans1d
running install_egg_info
running egg_info
writing kmeans1d.egg-info\PKG-INFO
writing dependency_links to kmeans1d.egg-info\dependency_links.txt
writing top-level names to kmeans1d.egg-info\top_level.txt
reading manifest file 'kmeans1d.egg-info\SOURCES.txt'
writing manifest file 'kmeans1d.egg-info\SOURCES.txt'
Copying kmeans1d.egg-info to build\bdist.win-amd64\wheel\.\kmeans1d-0.3.0-py3.8.egg-info
running install_scripts
C:\Users\dan\anaconda3\envs\untitled\lib\site-packages\wheel\pep425tags.py:80: RuntimeWarning: Config variable 'Py_DEBUG' is unset, Python ABI tag may be incorrect
if get_flag('Py_DEBUG',
creating build\bdist.win-amd64\wheel\kmeans1d-0.3.0.dist-info\WHEEL
creating 'C:\Users\dan\AppData\Local\Temp\pip-wheel-tno8xvb4\kmeans1d-0.3.0-cp38-cp38-win_amd64.whl' and adding 'build\bdist.win-amd64\wheel' to it
adding 'kmeans1d/__init__.py'
adding 'kmeans1d/_core.cp38-win_amd64.pyd'
adding 'kmeans1d/core.py'
adding 'kmeans1d/version.txt'
adding 'kmeans1d-0.3.0.dist-info/METADATA'
adding 'kmeans1d-0.3.0.dist-info/WHEEL'
adding 'kmeans1d-0.3.0.dist-info/top_level.txt'
adding 'kmeans1d-0.3.0.dist-info/RECORD'
removing build\bdist.win-amd64\wheel
done
Created wheel for kmeans1d: filename=kmeans1d-0.3.0-cp38-cp38-win_amd64.whl size=17214 sha256=952bbafdb2ea2c5e63c35d527dcff6a22ed3754601793002c408248ad57bf245
Stored in directory: C:\Users\dan\AppData\Local\Temp\pip-ephem-wheel-cache-n_d30ge5\wheels\9c\fb\c0\6d32c3cff8cc25e89b60113f1dac6a7f062dba46c9cbcec4c0
Successfully built kmeans1d
@Dexter1618, in the C++
code, I was explicitly exporting the cluster
function when compiling with Microsoft Visual Studio on Windows. I believe that this export is required more generally on Windows, even when using other compilers. I've added this more general exporting functionality, which I think will fix the issue you are encountering.
kmeans1d==0.3.1
has the update.
Please try updating kmeans1d
.
> pip install --upgrade kmeans1d
If you're still encountering the issue, please share the --verbose
output that's generated (details in my prior comment), which would be helpful for debugging.
> pip install --verbose --no-cache-dir kmeans1d==0.3.1
I'll mark this issue closed, and will reopen if you're still facing an issue with version 0.3.1
.
Additionally, I've added a GitHub action that can build Python wheels. I've uploaded Windows, macOS, and Linux wheels to PyPI for kmeans1d==0.3.1
. The Linux wheels target a recent ABI (manylinux2014
) that requires a recent version of pip
, but building from source is still available as a fallback (and the necessary compilation tools are usually readily available on Linux distributions).
Hi @dstein64
Thanks for addressing the issue promptly.
0.3.1
works for both on Windows and Ubuntu, at least for me.