ANTsX / ANTsPy

A fast medical imaging analysis library in Python with algorithms for registration, segmentation, and more.
https://antspyx.readthedocs.io
Apache License 2.0
627 stars 161 forks source link

ANTsPy for Windows #28

Closed dyollb closed 3 years ago

dyollb commented 6 years ago

Hi

I like the idea of using ANTs from Python, i.e. power of Python/numpy with ANTs algorithms. But most of my development is on Windows (Visual Studio 2015). What things would I need to modify to get this to work also on Windows?

it looks like pybind11 is supported for VS 2015 up. ants (proper) builds on Windows, as does ITK/VTK (of course)...

thanks for any guidance. bryn

stnava commented 6 years ago

you would have to try this yourself. please report back if you find anything out.

SGotla commented 5 years ago

Apologies if I'm posting this in the wrong place but I've been trying to compile ANTsPy (v 0.1.6) on a 64 bit windows 7 machine (I'm stuck in the past) with the intention to compile or cythonize some python code that I've written using ANTsPy in Linux. (Note that ANTsPy builds totally fine in Linux using GCC and cmake without any issues). Please note I am a total newbie in C++ and cmake, I haven't seen anyone attempt this but here's what I've found so far so please do take all of this with a grain of salt as you might have a different experience:

These are the steps I've done to get most components built and pybinded:

Configure and build (and install) ITKv5 (see scripts/configure_ITK.sh for the correct branch and configuration options - use cmake and make sure itkreview, mghio etc are configured correctly - again see the shell script for more info)

Execute (it's probably easier to use something like cygwin or ubuntu subsystem if you're on Win10) configure_ANTSpy.sh so that the correct version of ANTs and pybind11 are cloned and the folder structure is taken care of.

Configure and generate a visual studio project for ants/lib, set the build directory to somewhere convenient like ../[antspy_root]/build and try to build the project (ALL_BUILD) or just navigate to the build directory and execute cmake --build .

This is where my experience would probably differ to most and I am very new to C++ so if I do say anything wrong here please do correct me! I did have to do some code tweaking to get this working (this is also probably an ANTs issue for windows as well so this might be relevant if you're struggling to get ANTs working on windows). If you get any lnk1169: multiply defined symbol errors, set /FORCE in your linker options in cmake as this seems mostly due to the certain functions being defined and referred to multiple times (one example I found was with the antsOptionName, antsGetFilePrefix and AntsOptionValue definitions in imath.cxx and imagemathhelper.cxx)

I also had a type conversion issue with CreateTiledMosaic.cxx where the variables lowerBound and upperBound were defined as unsigned long. Again as a C++ newbie, I did a bit of research on how windows deals with unsigned long and the general consensus seems to define these as uint64_t. Changing this allowed me to build this particular component.

Currently the only component that doesn't build is KellyKapowski and I am unsure why... From what I can see, it seems to be due to the "<<" operator used by ITKMacro.h and is related to how DIRECT is called (I think?) using itkDirectImageFilter in KellyKapowski:

Line 268: itkSetMacro( TimePoints, std::vector )

I'm struggling to build this component on ANTs proper as well using superbuild so I'm not entirely sure what's going on here...

stnava commented 5 years ago

thank you for your insights. @adigherman and @muschellij2 have probably worked most on this but in the context of R .... some of the experience should translate.

muschellij2 commented 5 years ago

We can discuss this, but after trying to get ANTs to build on Windows for > 1 year, we have failed. So I'm not that hopeful to help you.

dorianps commented 5 years ago

@muschellij2 did you try MS Visual Studio for the Windows build? I used that 4 years ago but don't remember exactly what I changed to make it work.

SGotla commented 5 years ago

Thanks for reopening the issue and for the responses. So I'm able to get every other component of ANTs to compile (after mostly accounting for Windows specific variable types) with the exception of KellyKapowski.

The offending bit of code seems to be line 268 of itkDiReCTImageFilter.h:

itkSetMacro( TimePoints, std::vector<RealType> );

The compiler error is:

itkDiReCTImageFilter.h(268): error C2679: binary '<<': no operator found which takes a right-hand operand of type 'const std::vector<TElement,std::allocator<_Ty>>' (or there is no acceptable conversion)
          with
          [

TElement=itk::BSplineScatteredDataPointSetToImageFilter<TInputPointSet,TOutputImage>::RealType,
              _Ty=itk::BSplineScatteredDataPointSetToImageFilter<TInputPointSet,TOutputImage>::RealType

          ]

Looking at the definition of itkSetMacro from ITKv5:

#define itkSetMacro(name, type)                     \
  virtual void Set##name (const type _arg)          \
    {                                               \
    itkDebugMacro("setting " #name " to " << _arg); \
CLANG_PRAGMA_PUSH                                   \
CLANG_SUPPRESS_Wfloat_equal                         \
    if ( this->m_##name != _arg )                   \
      {                                             \
      this->m_##name = _arg;                        \
      this->Modified();                             \
      }                                             \
CLANG_PRAGMA_POP                                    \
    }

And the definition of itkDebugMacro:

#define itkDebugMacro(x)                                                \
    {                                                                   \
    if ( this->GetDebug() && ::itk::Object::GetGlobalWarningDisplay() ) \
      {                                                                 \
      std::ostringstream itkmsg;                                        \
      itkmsg << "Debug: In " __FILE__ ", line " << __LINE__ << "\n"     \
             << this->GetNameOfClass() << " (" << this << "): " x       \
             << "\n\n";                                                 \
      ::itk::OutputWindowDisplayDebugText( itkmsg.str().c_str() );      \
      }                                                                 \
    }

Either that or it might be due to how the ANTs parser is handling certain string inputs perhaps?..As commenting out the switch(dimension) lines on 843-863 allows the code to compile:

  switch( dimension )
    {
    case 2:
      {
      return DiReCT<2>( parser );
      }
      break;
    case 3:
      {
      return DiReCT<3>( parser );
      }
      break;
    case 4:
      {
      return DiReCT<4>( parser );
      }
      break;
    default:
      std::cout << "Unsupported dimension" << std::endl;
      return EXIT_FAILURE;
    }

I'm not quite sure why these lines cause compilation to fail on windows. To be fair, I don't have a handle on the ANTs C++ codebase so I've mostly been following the breadcrumbs left by mscv compiler errors.

Thanks again.

stnava commented 5 years ago

this could be an incompatible RealType definition - though technically that should cause issues elsewhere too.

if you think itkSetMacro( TimePoints, std::vector<RealType> ); is really the issue then maybe try removing the macro call and instead explicitly define that function. e.g. ( may not be correct code ):

void SetTimePoints(   std::vector<float> x  ) {
  this->m_TimePoints = x
}

and see if that helps clarify the issue.

SGotla commented 5 years ago

Perfect! That did the trick!

So I had to change the itkSetMacro(TimePoints, std::vector<RealType>) calls in both itkDirectImageFilter.h and itkMaskedSmoothingImageFilter.h.

Thanks a lot for the help!

stnava commented 5 years ago

very good to hear. we would certainly appreciate a bit more documentation of your work to get this to compile ( e.g. push to github your changes ) .... i would also like to know if the tests pass.

SGotla commented 5 years ago

Great! So I've just managed to get ANTsPy completely working on my Windows 7 64bit Python 3.7 setup. A few additional steps I had to do that made things work:

Make sure to install a release version of ITKv5 as for some reason, some of the components were built using a debug configuration, I'm not sure why this happened but it did.... Copy the compiled ITK dll's (that reside in the bin directory) to ants/lib along with the compiled ANTs python extensions (*.pyd files) generated by the visual studio compiler and pybind11. (I didn't bother to automate these steps as I just wanted to get things working....)

Modify setup.py to make sure no additional compilation was done and only the python specific code were being called (i.e. comment out the subprocess calls to cmake) and alter the variable package_data such that:

package_data={'ants':['ants/lib/*.pyd*', 'lib/*.pyd*', 'ants/lib/*.dll', 'lib/*.dll']}

Execute setup.py and hopefully things should work. I had to additionally install the visual c++ 2015 runtimes as I used visual studio 2015 to compile ANTs. I'm guessing one could do the same in visual studio 2017 but with the 2017 runtimes.

I'm happy to write some detailed steps in a few days on how I got this all working including pushing my version up to github. Would making an ANTsPy windows wheel make things easier to install for others?

Could all of the above and prior posts possibly help with making ANTs work on windows as well?

SGotla commented 5 years ago

Nevermind, I got overly excited. So it seems like there are some issues with file name inputs with the C++ core...

File IO seems to work fine and I can convert between ANTs images and numpy arrays, retrieve metadata etc however if I attempt to run an operation on an ANTsImage, for eg:

img2 = ants.iMath(ANTSimage, 'Canny', 1, 5, 12)

I get an error:

file 000000000D8E2D10 does not exist
You may have reached an unimplemented section of code by calling:
iMath 3 000000000FDFE350 Canny 000000000D8E2D10 1 5 12

I'm wondering if this has to do with the differences between unix and windows file paths as I know ANTsPy writes temporary files quite frequently, eg writing transforms to files after antsRegistration...

I have used ANTs proper on linux and osx and I realise that's basically a call to the command line version of imageMath and it is writing the result to "000000000FDFE350". Would this be an issue with the command line parser somewhere converting between string inputs?

SGotla commented 5 years ago

Just an update: seems it was just an issue with windows specific pointer addresses... I just had to alter the the function ptrstr in LOCAL_antsImage.cxx. Probably a better way to do this but this worked:

Original:

std::string ptrstr(py::capsule c)
{
    std::stringstream ss;
    ss << (void const *)c;
    std::string s = ss.str();
    return s;
}

Modified:

std::string ptrstr(py::capsule c)
{
    char buffer[50];
    int n = sprintf(buffer, "0x%p", (void const *)c);
    std::string s(buffer, n);
    return s;
}

With these changes antsRegistration, imageMath etc work in Windows.

stnava commented 5 years ago

Great! Any chance you could contribute a windows branch with these changes?

SGotla commented 5 years ago

Happy to do so, although the build process is very manual, i.e. the user needs to build everything manually (including ITK), but it should be fairly easy to do everything once the windows specific changes to the C++ source are implemented.

I'm happy to also provide python wheels using my build that I've tested on another windows 10 machine if that also helps.

ntustison commented 5 years ago

https://github.com/ANTsX/ANTs/commit/33546717c0c4f02e1968780d987b059b4a68f989

janroden commented 5 years ago

@SGotla That sounds great! I would certainly also be interested in your Windows 10 (64bit) wheels for Python 3.7 and in a Windows branch with your changes, for testing ANTsPy on Windows. Did you encounter any other problems with your version or has everything run smoothly so far? Thanks a lot!

SGotla commented 5 years ago

@janroden No worries, so far I haven't had any problems. I do have the wheels available, unfortunately I won't be able to get to them this weekend. Apologies for that I have been meaning to commit my changes to my ANTsPy fork, I've just never had the time to get around to it!

I'll try to get to it when I'm back at work next week.

Cheers, Sunay

janroden commented 5 years ago

@SGotla, that would be wonderful! Thank you very much for your efforts!

SGotla commented 5 years ago

@janroden I've just rebuilt ANTsPy on my windows machine with changes to LOCAL_antsImage.cxx (see a few posts above) and the most recent version of ANTs. I haven't properly automated the build process yet, however if want to build everything yourself, you can do so by building every component separately (ITK, ANTs and ANTsPy) using VS2015 and above.

If you want to try the wheel: pip install https://github.com/SGotla/ANTsPy/releases/download/0.1.7Win64/antspy-0.1.7-cp37-cp37m-win_amd64.whl

Let me know if it works for you.

janroden commented 5 years ago

@SGotla Thank you very much again! This is great. I will try the wheel this week.

stnava commented 5 years ago

i updated the core ITK and ANTs resources on which ANTsPy is based. both of these repositories recently added some fixes for windows. i am curious if these updates ease the process of building for Windows. Side note: Also added CircleCi support and better timed Travis builds so builds will hopefully pass from now on, unless a bug is introduced.

SGotla commented 5 years ago

@stnava Thanks! ANTs and ITK both build fine on Windows now. The only issue now is with pointer address strings as in https://github.com/ANTsX/ANTsPy/issues/28#issuecomment-453883804

Once I edit that file, everything builds and works fine and I'm able to pass images through python to the antsRegistration backend. But am I right in assuming that breaks linux/osx versions? If so, is it possible to make that bit of code platform independent?

I think once that issue's sorted, ANTsPy should compile fine on windows. There is also a way to use MSVC with mingw/cygwin so one could still run setup.py with the bash files for configuring ITK and ANTs but I haven't tried it: https://devblogs.microsoft.com/cppblog/using-mingw-and-cygwin-with-visual-cpp-and-open-folder/

stnava commented 5 years ago

@muschellij2 and colleagues did the real work on the ITK and ANTs updates for windows.

yes, we can automate the use of your pointer code for windows but i dont know offhand what approach should be used. cmake certainly provides functionality for this. but maybe a simple modification to setup.py would do it as well. For example:

if windows => cp LOCAL_antsImageWindows.cxx to LOCAL_antsImage.cxx 

something like that.

muratmaga commented 5 years ago

We have some interest having ANTs and ANTsPy on windows. Where should we start?

Turns out provided wheel worked for us, which is awesome. Is there a way to get this working on windows 7 as well?

laqua-stack commented 5 years ago

@SGotla Thank you so much for your efforts building it for windows. The 3.7 wheel works also for me. And also thanks to all the contributors. (I think this cannot be stated to often)

Would you mind adding another wheel for Python 3.6 (and maybe also 3.5? ;-)) As far as I understood your approach, it would just be rebuilding in a python=3.6 env, since your (modified) ANTs and ITK are inplace?

SGotla commented 5 years ago

@muratmaga Apologies for my tardiness as I've been quite busy but the wheel I posted was built on my windows 7 machine.

@laqua-stack With all the changes since the posting, ANTs builds fine on Windows. The only change required is the pointer code in LOCAL_antsImage.cxx to make it Windows compatible. As @stnava mentioned, one could have a secondary windows specific LOCAL_antsImage.cxx file and edit setup.py but I've yet to try that!

You should be able to build AntsPy on whatever Python 3 environment you're using once you make the above change to LOCAL_antsImage.cxx. Just remember that Python expects all C++ extensions to be built with VS2015/MSVC140 (I'll endeavor to write some instructions on how to do so in the weekend but it's a fairly straightforward process now that most of the issues have been ironed out).

stnava commented 4 years ago

I just added this:

https://github.com/ANTsX/ANTsPy/commit/f4a6d3e3ba6bc5a4a141fd08ac387548e1458a05

the idea, then, would be that windows builders should be able to do:

git clone ANTsPy
cd ANTsPy
cp .//ants/lib/LOCAL_antsImageWin.cxx .//ants/lib/LOCAL_antsImage.cxx
python3 setup.py install

obviously, we can add a windows version of setup.py as well but before doing that, I would like to know if this works for anyone.

any feedback welcome.

muratmaga commented 4 years ago

Did not work for me:

(base) C:\Users\murat>git clone https://github.com/ANTsX/ANTsPy Cloning into 'ANTsPy'... remote: Enumerating objects: 116, done. remote: Counting objects: 100% (116/116), done. remote: Compressing objects: 100% (82/82), done. Receiving objects: 100% (4351/4351), 91.32 MiB | 9.03 MiB/s, done. Resolving deltas: 100% (2942/2942), done.

(base) C:\Users\murat>cd ANTsPy

(base) C:\Users\murat\ANTsPy>copy ants\lib\LOCAL_antsImageWin.cxx ants\lib\LOCAL_antsImage.cxx Overwrite ants\lib\LOCAL_antsImage.cxx? (Yes/No/All): y 1 file(s) copied.

(base) C:\Users\murat\ANTsPy>python --version Python 3.7.3

(base) C:\Users\murat\ANTsPy>python setup.py install running install running build_py running build_ext Configuring ITK No local ITK installation found... Building ITK now... error: [WinError 193] %1 is not a valid Win32 application

(base) C:\Users\murat\ANTsPy>

Sent from Mailhttps://go.microsoft.com/fwlink/?LinkId=550986 for Windows 10


From: stnava notifications@github.com Sent: Tuesday, October 15, 2019 3:48:13 PM To: ANTsX/ANTsPy ANTsPy@noreply.github.com Cc: muratmaga muratmaga@outlook.com; Mention mention@noreply.github.com Subject: Re: [ANTsX/ANTsPy] ANTsPy for Windows (#28)

I just added this:

f4a6d3ehttps://nam12.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FANTsX%2FANTsPy%2Fcommit%2Ff4a6d3e3ba6bc5a4a141fd08ac387548e1458a05&data=02%7C01%7C%7C339757da87c94cd95e4c08d751c1c32f%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637067764946263771&sdata=req8o9aVOn%2B8GjG5%2B61kHEZrJM5L3ZjFz%2Bpp9bJ0qmo%3D&reserved=0

the idea, then, would be that windows builders should be able to do:

git clone ANTsPy cd ANTsPy cp .//ants/lib/LOCAL_antsImageWin.cxx .//ants/lib/LOCAL_antsImage.cxx python3 setup.py install

obviously, we can add a windows version of setup.py as well but before doing that, I would like to know if this works for anyone.

any feedback welcome.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://nam12.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FANTsX%2FANTsPy%2Fissues%2F28%3Femail_source%3Dnotifications%26email_token%3DAFCMSFGUTJ3CCQI6TWWBRADQOZCC3A5CNFSM4ERKUCJ2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEBKO3LY%23issuecomment-542436783&data=02%7C01%7C%7C339757da87c94cd95e4c08d751c1c32f%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637067764946273775&sdata=rvU9%2FlPBDJe7X7rL%2BQrGOKe%2FEjifMcUQyZ3gtqhHBYU%3D&reserved=0, or unsubscribehttps://nam12.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAFCMSFAIZKYYRSFZME2JZUTQOZCC3ANCNFSM4ERKUCJQ&data=02%7C01%7C%7C339757da87c94cd95e4c08d751c1c32f%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637067764946283803&sdata=Kwow4KK32CXw5tO%2BoQ4ZzoTOGU1v3Xqg1vQ3uliOilA%3D&reserved=0.

SGotla commented 4 years ago

As with most things Windows, there's a bit more manual fiddling to getting this to work:

Assuming cmake is installed, you'll need to install Visual Studio (you could probably get away with MS Build tools, just make sure the compiler "cl.exe" is v14 or above) and the Windows SDK. Python3.7 is built using MSVC14 rather than GCC so any C++ extensions will need to be built using MSVC. I decided to stick with with Visual Studio 2015 and the windows 10 SDKs (seems to work on my win7 x64 machine).

If you inspect setup.py, it's basically running a bunch of bash scripts to build ITK and pull the right ANTs files, so you'll need cygwin (https://www.cygwin.com/) to be able to run these. Windows 10 users would probably be fine with the linux subsystem. We really just need the bash executable to execute the .sh files in the scripts folder.

Add C:\cygwin64\bin to your windows system path (Control Panel -> System -> Advanced -> Environment Variables -- Append to the end of the PATH entry)

Open the MSBuild command prompt as an administrator, this should be installed when you install Visual Studio.

I made some edits on my fork of antsPy to setup.py and scripts/configure_itk.sh to accommodate installation for windows. I'm currently building ANTsPy on my windows 7 64 bit system and so far everything seems to be going smoothly.

Try the following on a MSBuild command prompt:

git clone https://github.com/SGotla/ANTsPy.git
cd ANTsPy
cp .//ants/lib/LOCAL_antsImageWin.cxx .//ants/lib/LOCAL_antsImage.cxx
python setup.py install
stnava commented 4 years ago

thanks for these additional instructions.

stnava commented 4 years ago

@muschellij2 not sure if this is helpful but @SGotla seems to have something working at least in python

muschellij2 commented 4 years ago

If I understand correctly, these are customized copies of the build scripts for ANTsR, right? Also I’d love to see if they could build ANTsPy using the compiler tool chain from R. @adigherman and I will look into it

On Wed, Oct 23, 2019 at 8:13 AM stnava notifications@github.com wrote:

@muschellij2 https://github.com/muschellij2 not sure if this is helpful but @SGotla https://github.com/SGotla seems to have something working at least in python

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ANTsX/ANTsPy/issues/28?email_source=notifications&email_token=AAIGPLVZM7GWKOUBEKLZKVTQQA5WBA5CNFSM4ERKUCJ2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOECBFWEA#issuecomment-545413904, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAIGPLT6EW3RAF7SPR6NE6TQQA5WBANCNFSM4ERKUCJQ .

-- Best, John

JensMunkHansen commented 4 years ago

I managed to build @SGotla 's fork using Visual Studio 2017 on Windows 10. I used the latest version of ITK 5.1 and for this I need to make a few adjustments


ants/lib/CMakeLists.txt:

# Specify which components that are used from ITK

## SETUP ITK ##
find_package(ITK REQUIRED COMPONENTS ITKCommon ITKTransform ITKSmoothing ITKImageIO ITKTransformIO ITKThresholding ITKMathematicalMorphology ITKBinaryMathematicalMorphology ITKAnisotropicSmoothing ITKMetricsv4 ITKRegistrationMethodsv4 ITKIOCSV ITKAntiAlias ITKBiasCorrection ITKClassifiers ITKMarkovRandomFieldsClassifiers ITKConnectedComponents ITKConvolution ITKWatersheds ITKReview GenericLabelInterpolator)

# Some symbols are multiple defined for target iMath
set(new_link_flags "/FORCE:Multiple")
get_target_property(existing_link_flags iMath LINK_FLAGS)
set(new_link_flags "${existing_link_flags} ${new_link_flags}")
set_target_properties(iMath PROPERTIES LINK_FLAGS ${new_link_flags})

setup.py

cmake_args = [
    "-G", "Visual Studio 15 2017 Win64",
    "-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=" + extdir,
    "-DPYTHON_EXECUTABLE=" + sys.executable
]

If this a help to anybody running AntsPy on Windows, here you go
stnava commented 4 years ago

I am just going to repeat the efforts of @JensMunkHansen for those who may not be able to decode the meaning. @JensMunkHansen please proofread if you get a chance.

first, make some minor changes to ants/lib/CMakeLists.txt:

change this line: https://github.com/ANTsX/ANTsPy/blob/f3f0f548a30de8b7983518119e3788800c5dfee4/ants/lib/CMakeLists.txt#L10

to:

find_package(ITK REQUIRED COMPONENTS ITKCommon ITKTransform ITKSmoothing ITKImageIO ITKTransformIO ITKThresholding ITKMathematicalMorphology ITKBinaryMathematicalMorphology ITKAnisotropicSmoothing ITKMetricsv4 ITKRegistrationMethodsv4 ITKIOCSV ITKAntiAlias ITKBiasCorrection ITKClassifiers ITKMarkovRandomFieldsClassifiers ITKConnectedComponents ITKConvolution ITKWatersheds ITKReview GenericLabelInterpolator)

somewhere (not sure where) in the section ## BUILD ANTS LIBRARIES ##https://github.com/ANTsX/ANTsPy/blob/f3f0f548a30de8b7983518119e3788800c5dfee4/ants/lib/CMakeLists.txt#L17

add

# Some symbols are multiple defined for target iMath
set(new_link_flags "/FORCE:Multiple")
get_target_property(existing_link_flags iMath LINK_FLAGS)
set(new_link_flags "${existing_link_flags} ${new_link_flags}")
set_target_properties(iMath PROPERTIES LINK_FLAGS ${new_link_flags})

then in setup.py change this https://github.com/ANTsX/ANTsPy/blob/f3f0f548a30de8b7983518119e3788800c5dfee4/setup.py#L112-L115

to this:

cmake_args = [
    "-G", "Visual Studio 15 2017 Win64",
    "-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=" + extdir,
    "-DPYTHON_EXECUTABLE=" + sys.executable
]
muschellij2 commented 4 years ago

Can this be run on Appveyor to make a binary build based on a set of toolchains?

desserdmi commented 4 years ago

I am just going to repeat the efforts of @JensMunkHansen for those who may not be able to decode the meaning. @JensMunkHansen please proofread if you get a chance.

first, make some minor changes to ants/lib/CMakeLists.txt:

change this line: https://github.com/ANTsX/ANTsPy/blob/f3f0f548a30de8b7983518119e3788800c5dfee4/ants/lib/CMakeLists.txt#L10

to:

find_package(ITK REQUIRED COMPONENTS ITKCommon ITKTransform ITKSmoothing ITKImageIO ITKTransformIO ITKThresholding ITKMathematicalMorphology ITKBinaryMathematicalMorphology ITKAnisotropicSmoothing ITKMetricsv4 ITKRegistrationMethodsv4 ITKIOCSV ITKAntiAlias ITKBiasCorrection ITKClassifiers ITKMarkovRandomFieldsClassifiers ITKConnectedComponents ITKConvolution ITKWatersheds ITKReview GenericLabelInterpolator)

somewhere (not sure where) in the section ## BUILD ANTS LIBRARIES ##

https://github.com/ANTsX/ANTsPy/blob/f3f0f548a30de8b7983518119e3788800c5dfee4/ants/lib/CMakeLists.txt#L17

add

# Some symbols are multiple defined for target iMath
set(new_link_flags "/FORCE:Multiple")
get_target_property(existing_link_flags iMath LINK_FLAGS)
set(new_link_flags "${existing_link_flags} ${new_link_flags}")
set_target_properties(iMath PROPERTIES LINK_FLAGS ${new_link_flags})

then in setup.py change this

https://github.com/ANTsX/ANTsPy/blob/f3f0f548a30de8b7983518119e3788800c5dfee4/setup.py#L112-L115

to this:

cmake_args = [
    "-G", "Visual Studio 15 2017 Win64",
    "-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=" + extdir,
    "-DPYTHON_EXECUTABLE=" + sys.executable
]

HI,

I am trying to install ANTsPy on my Windows 10 system and I have made all changes to setup.py and CMakeLists.txt as described above. I get No local ITK installation found.. Building ITK now.. error: [Winerror2] The system cannot find the file specified

I have installed itk using pip..

Does anybody have an idea of what I have done wrong?

ryancinsight commented 4 years ago

Hello @SGotla and @stnava I have been able to build ITK5.2/Elastix and SimpleITK/SimpleElastix using MSYS2 , ninja, gcc10, and llvm-lld. Using almost the exact same steps as I would on ubuntu and the swig wrappings have worked great. I was wondering if their might be a way to make the setup.py for windows this way as well. When I try it currently I get a win32 error despite them being 64 bit compilations but I get that just running setup.py on windows even if I don't have ITK already built. Any ideas for modifications I can make?

stnava commented 4 years ago

there probably is a way but I don't have a windows machine and have no idea what you would do. eg I don't know what MSYS2 is or how it relates to ANTsPy. must rely on the community to figure it out. Word is that the new windows linux subsystem works well and, in the absence of other advances or your own willingness to figure things out, I would recommend that route.

just note that ANTsPy builds ITK and ANTs as well as its own Cpp via pybind11. so installing itk separately won't help.

if anyone has any progress, we would surely like to know and/or get a pull request for any fixes/recommendations, etc.

stnava commented 3 years ago

very stale; seems like interest/need for this is rapidly reducing.

sarthakpati commented 3 years ago

Any update on this?

muschellij2 commented 3 years ago

PRs are always welcome @sarthakpati, shame or no shame - the issue is closed. Using WSL is also an option: https://docs.microsoft.com/en-us/windows/wsl/install-win10

stnava commented 3 years ago

"must rely on the community to figure it out"

we neither have nor work on windows systems. I would hope that some windows user out there - with some knowledge of windows development tools that we've never even heard of - would commit some effort to helping out.

indeed, a start has been made before (by the community), but interest was very minimal from any real windows developer that could actually get it done.

464hee commented 2 years ago

@janroden I've just rebuilt ANTsPy on my windows machine with changes to LOCAL_antsImage.cxx (see a few posts above) and the most recent version of ANTs. I haven't properly automated the build process yet, however if want to build everything yourself, you can do so by building every component separately (ITK, ANTs and ANTsPy) using VS2015 and above.

If you want to try the wheel: pip install https://github.com/SGotla/ANTsPy/releases/download/0.1.7Win64/antspy-0.1.7-cp37-cp37m-win_amd64.whl

Let me know if it works for you. Thank you very much for your contribution to the windows version of ants.This is available to me.