cmdstanr icon indicating copy to clipboard operation
cmdstanr copied to clipboard

OneDrive issues on Windows maybe because $HOME shouldn't be used on Windows

Open jgabry opened this issue 2 years ago • 9 comments

@rok-cesnovar @andrjohns We're seeing more Windows installation issues related to OneDrive folders. On the forum @WardBrian suggested that maybe we need to change how we're setting the default install location on Windows:

If I had to guess, these users have %HOME% set to the one drive location, and cmdstanr is using it. Note that this is bad practice on cmdstanr’s part, %HOME% is not one of the standard environment variables on Windows so it can be set to more or less anything (or nothing at all!) unless R is stepping in and monkeypatching this.

In CmdStanPy we use os.path.expanduser which uses a combination of things instead of %HOME% on windows:

On Windows, USERPROFILE will be used if set, otherwise a combination of HOMEPATH and HOMEDRIVE will be used. An initial ~user is handled by checking that the last directory component of the current user’s home directory matches USERNAME, and replacing it if so. I haven’t seen issues with cmdstanpy and OneDrive yet, so I strongly suspect this difference is the reason

What do you guys think?

(Also see discussion on slack with helpful comments from @WardBrian and @ahartikainen)

jgabry avatar Aug 18 '23 15:08 jgabry

There is an issue here for people who use OneDrive to backup their Documents...

When cmdstan_model() is executed they get this error:

Compiling Stan program... Error in (function (command = NULL, args = character(), error_on_status = TRUE, …: ! System command 'make' failed

Exit status: 2 Stderr: make: *** /c/Users//OneDrive: Is a directory. Stop.

This is true even if cmdstanr is not installed in their Documents folder and set_cmdstan_path() is used to set the proper folder location. I believe this is true because cmdstanr always checks the HOME directory first and OneDrive changes the path of the Documents folder for people who back it up to OneDrive (OneDrive moves Documents to a subfolder of OneDrive).

We had two students in our Bayesian class face this issue and the solution was to either:

  1. Stop backing up Documents to OneDrive
  2. Change the HOME environment variable using Sys.setenv(HOME = "C:/Any/Path/Not/In/OneDrive")

belinskyc avatar Sep 08 '23 16:09 belinskyc

@belinskyc thanks for the report.

@rok-cesnovar do you have a preference for how we should handle this on windows going forward?

jgabry avatar Sep 08 '23 16:09 jgabry

I think we should try and replicate what cmdstanpy does. I can prioritize and work on this over the weekend. We just need to be backwards compatible to not force a reinstall for users where HOME works fine.

rok-cesnovar avatar Sep 08 '23 16:09 rok-cesnovar

Thanks @rok-cesnovar!

jgabry avatar Sep 08 '23 18:09 jgabry

There is utils::shortPathName

https://stat.ethz.ch/R-manual/R-devel/library/utils/html/shortPathName.html

ahartikainen avatar Sep 08 '23 19:09 ahartikainen

We’re also seeing other windows install issues that don’t seem related to OneDrive but that maybe would also be resolved by doing what CmdStanPy does?

For example, https://github.com/stan-dev/cmdstanr/issues/810 and https://discourse.mc-stan.org/t/cmdstanr-installation-error/32702. There are other similar ones too.

Those don’t mention OneDrive but seem related to path issues.

jgabry avatar Sep 10 '23 16:09 jgabry

Bumping this conversation for 2024, is there an update? I've seen some suggestions that users should delete their OneDrive folder, but this is a non-starter in the government and corporate space.

I'm happy to help with a patch but I can't find where %HOME% is getting grabbed before compilation on a quick search.

beansrowning avatar Feb 02 '24 21:02 beansrowning

Bumping this a bit to signal that even in professional spaces where you can delete the empty "OneDrive" folder left after IT sets the "OneDrive - Organisation" folder (as suggested in https://discourse.mc-stan.org/t/system-command-make-failed-models-wont-compile/30528), it's a temporary fix since mandatory software updates may just restore that folder and the issue with it (happened to me last week) (it can be deleted again, of course, but still)

mdahirel avatar Mar 30 '24 20:03 mdahirel

Bumping this a bit to signal that even in professional spaces where you can delete the empty "OneDrive" folder left after IT sets the "OneDrive - Organisation" folder (as suggested in https://discourse.mc-stan.org/t/system-command-make-failed-models-wont-compile/30528), it's a temporary fix since mandatory software updates may just restore that folder and the issue with it (happened to me last week) (it can be deleted again, of course, but still)

FWIW I've "fixed" this on my side by modifying %HOME% at the top of my script to %USERPROFILE% which should be the directory one down from the OneDrive folder (ex. C:/users/username/). Not the best solution, but the only one that worked for me.

Sys.setenv("HOME" = Sys.getenv("USERPROFILE"))

beansrowning avatar Apr 01 '24 14:04 beansrowning