Closed DareDevilDenis closed 2 years ago
I'd be fine with special-casing this for macOS.
PRs are welcome, I have no mac to test this. The CI doesn't have this problem as it (properly, IMO) sets PATH
and DOTNET_ROOT
.
And by the way, the reason this is special-cased on Windows is that on this system one expects it to always install into Program Files
and to not update the global PATH
. On Unix systems, I expect things to be in PATH
after installation. The error here happens because the profile (i.e. set of environment variables) is not automagically updated, you'd need to add that to your installation routine.
Thanks @filmor
Based on your advice, we could add the following which would make it work on macOS:
def find_dotnet_root() -> str:
dotnet_root = os.environ.get("DOTNET_ROOT", None)
if dotnet_root is not None:
return dotnet_root
if sys.platform == "win32":
# On Windows, the host library is stored separately from dotnet.exe for x86
prog_files = os.environ.get("ProgramFiles")
dotnet_root = os.path.join(prog_files, "dotnet")
## if os.path.isdir(dotnet_root): MOVED BELOW
## return dotnet_root MOVED BELOW
### START NEW
if sys.platform == "darwin":
dotnet_root = r'/usr/local/share/dotnet'
if os.path.isdir(dotnet_root):
return dotnet_root
### END NEW
# Try to discover dotnet from PATH otherwise
dotnet_path = shutil.which("dotnet")
if not dotnet_path:
raise RuntimeError("Can not determine dotnet root")
I have a few questions:
Do you know if there is any way for the user to install .NET Core to a non-default location? This page: https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-environment-variables#:~:text=DOTNET_ROOT%20%2C%20DOTNET_ROOT(x86)&text=The%20default%20location%20on%20Linux,on%20a%2064%2Dbit%20OS. says:
However, for the Windows and macOS installers I couldn't see a way to change the install location.
On my macOS, .NET was installed to: /usr/local/share/dotnet
which agrees with https://stackoverflow.com/questions/38567353/how-to-determine-if-net-core-is-installed which says:
Strangely, the Microsoft link above says:
Why does it say that the default location on macOS is /usr/share/dotnet
when it's actually /usr/local/share/dotnet
?
On my Windows and macOS installations, there is no "DOTNET_ROOT" environment variable. How does this get set?
I'm not interested in Linux (I don't have a Linux machine), but I see that the following pages say that .NET is installed to /usr/share/dotnet/
(which agrees with the microsoft link)
https://stackoverflow.com/questions/45523961/where-is-the-dotnet-runtime-installed-to-on-ubuntu
https://stackoverflow.com/questions/38567353/how-to-determine-if-net-core-is-installed
Should we add the following clause?
if sys.platform == "linux":
dotnet_root = r'/usr/share/dotnet'
DOTNET_ROOT
is something that you can set yourself. That change seems fine to me, please create a PR. I don't want to set a default on Linux, on all reasonable Linux systems, you will have dotnet
on the PATH
. Your other questions should be directed at Microsoft :)
Thanks @filmor. I've created the PR: https://github.com/pythonnet/clr-loader/pull/25
Thank you :)
On macOS with pythonnet 3.0.0a2 installed (clr-loader 0.1.7) but without .NET core installed:
get_coreclr(C:\MyApp.runtimeconfig.json)
This results in the following exception:
If a NEW Terminal window is opened then this error does not occur. However we should not have to open a new Terminal window for it to find the dotnet executable. Performing the same steps on Windows works fine - we don't need to open a new command window.
My application has the prerequisites that pythonnet and .NET runtime are first installed. I am getting reports from people that they have installed the prerequisites but it is still failing. They don't realise that they need to open a new Terminal window to get it working.
The reason for the exception seems to be in clr-loader/util/find.py there is a difference how it finds the "dotnet" executable between Windows and macOS:
dotnet_path = shutil.which("dotnet")
doesn't find anything because dotnet is not in the path for this Terminal window.To fix this, could macOS just look in /usr/local/share/dotnet ? (I'm don't have Linux so I'm not sure where dotnet gets installed to on Linux)