randy3k / radian

A 21 century R console
MIT License
2k stars 76 forks source link

Problem with Mac M1 #398

Open nicolopadovan opened 1 year ago

nicolopadovan commented 1 year ago

I have seen that others have been having the same problem, but none of the solutions provided seems to be helpful.

Here's the error when trying to use radian (both when trying to attach the VSCode R Session Watcher and when running r or radian in the terminal.

Traceback (most recent call last):
  File "/Users/nico/opt/anaconda3/bin/radian", line 10, in <module>
    sys.exit(main())
  File "/Users/nico/opt/anaconda3/lib/python3.9/site-packages/radian/app.py", line 108, in main
    RadianApplication(r_home, ver=__version__).run(options, cleanup=cleanup)
  File "/Users/nico/opt/anaconda3/lib/python3.9/site-packages/radian/app.py", line 205, in run
    rchitect.init(args=args, register_signal_handlers=True)
  File "/Users/nico/opt/anaconda3/lib/python3.9/site-packages/rchitect/setup.py", line 49, in init
    raise Exception(load_lib_error())
Exception: Cannot load shared library: dlopen(/Library/Frameworks/R.framework/Resources/lib/libR.dylib, 0x000A): tried: '/Library/Frameworks/R.framework/Resources/lib/libR.dylib' (mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64')), '/System/Volumes/Preboot/Cryptexes/OS/Library/Frameworks/R.framework/Resources/lib/libR.dylib' (no such file), '/Library/Frameworks/R.framework/Resources/lib/libR.dylib' (mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64')), '/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/lib/libR.dylib' (mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64')), '/System/Volumes/Preboot/Cryptexes/OS/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/lib/libR.dylib' (no such file), '/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/lib/libR.dylib' (mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64'))

When trying to attach, VSCode yields the following error: The terminal process "/Users/nico/opt/anaconda3/bin/radian '--no-save', '--no-restore'" terminated with exit code: 1.

I am guessing that maybe one between R, Python or Radian I have installed is not ARM, but the error doesn't seem to be proving this hypothesis right. I also see that some files are stated as MISSING - which is the reason why I tried uninstalling and reinstalling R, VSCode, Anaconda, Radian - same results.

For completeness: I did add these lines to the ~/.zshrc file: alias r="radian" export R_HOME=/Library/Frameworks/R.framework/Resources

psobolewskiPhD commented 1 year ago

Can you post the output of a few things:

  1. in the terminal type arch and post the output. E.g. for me this shows arm64
  2. In termnial, type R to launch the R console. What is the Platform? e.g. mine:
    R version 4.2.2 (2022-10-31) -- "Innocent and Trusting"
    Copyright (C) 2022 The R Foundation for Statistical Computing
    Platform: aarch64-apple-darwin20 (64-bit)
  3. you installed radian using conda, can you please type conda info into the terminal and post the output? Particularly important are the channel URLs and platform.
  4. type python -c "import platform; print(platform.machine())" into your Terminal and post the output

Basically the error suggests you have mostly arm64 stuff, but an x86 python environment or x86 radian. So most likely your conda setup got polluted. I use miniforge3 the conda-forge conda release on my M1 with no issues, so I suspect it's the anaconda settings.

nicolopadovan commented 1 year ago

Can you post the output of a few things:

  1. in the terminal type arch and post the output. E.g. for me this shows arm64
  2. In termnial, type R to launch the R console. What is the Platform? e.g. mine:
R version 4.2.2 (2022-10-31) -- "Innocent and Trusting"
Copyright (C) 2022 The R Foundation for Statistical Computing
Platform: aarch64-apple-darwin20 (64-bit)
  1. you installed radian using conda, can you please type conda info into the terminal and post the output? Particularly important are the channel URLs and platform.
  2. type python -c "import platform; print(platform.machine())" into your Terminal and post the output

Basically the error suggests you have mostly arm64 stuff, but an x86 python environment or x86 radian. So most likely your conda setup got polluted. I use miniforge3 the conda-forge conda release on my M1 with no issues, so I suspect it's the anaconda settings.

Thanks for your quick response and thanks in advance for your help

psobolewskiPhD commented 1 year ago

Ok your conda info shows: all osx-64 channels, aka x86, and same for platform. And your python is, as a result, x86 and not arm64. Compare with mine, showing osx-arm64:

conda info                                                      (nap-test) ─╯

     active environment : nap-test
    active env location : /Users/piotrsobolewski/Dev/miniforge3/envs/nap-test
            shell level : 2
       user config file : /Users/piotrsobolewski/.condarc
 populated config files : /Users/piotrsobolewski/Dev/miniforge3/.condarc
                          /Users/piotrsobolewski/.condarc
          conda version : 22.9.0
    conda-build version : not installed
         python version : 3.10.8.final.0
       virtual packages : __osx=13.1=0
                          __unix=0=0
                          __archspec=1=arm64
       base environment : /Users/piotrsobolewski/Dev/miniforge3  (writable)
      conda av data dir : /Users/piotrsobolewski/Dev/miniforge3/etc/conda
  conda av metadata url : None
           channel URLs : https://conda.anaconda.org/conda-forge/osx-arm64
                          https://conda.anaconda.org/conda-forge/noarch
          package cache : /Users/piotrsobolewski/Dev/miniforge3/pkgs
                          /Users/piotrsobolewski/.conda/pkgs
       envs directories : /Users/piotrsobolewski/Dev/miniforge3/envs
                          /Users/piotrsobolewski/.conda/envs
               platform : osx-arm64
             user-agent : conda/22.9.0 requests/2.27.1 CPython/3.10.8 Darwin/22.2.0 OSX/13.1
                UID:GID : 501:20
             netrc file : None
           offline mode : False

So if you want to use all native arm64 tooling, you will need a new conda install that's actually arm64 native. My suggestion would be miniforge3, the conda-forge project conda install: https://github.com/conda-forge/miniforge I personally use mamba, which is much faster than vanilla conda.

Note: this is a small install, just what you need to make envs and install stuff.. my understanding is that anaconda packs a ton of packages by default, so if you need that, then I'm not sure the best path.

nicolopadovan commented 1 year ago

Thank you again. Would I need to uninstall conda and re-install it using miniforge? Or do I just need to uninstall the packages and then use miniforge to install them?

psobolewskiPhD commented 1 year ago

I'm not sure, I've never had multiple conda, so I can't say. If you don't need the x86 conda for anything specific, then probably best to nuke it, otherwise you're apt to have situations where you can't be sure which conda is active.

nicolopadovan commented 1 year ago

I'm not sure, I've never had multiple conda, so I can't say. If you don't need the x86 conda for anything specific, then probably best to nuke it, otherwise you're apt to have situations where you can't be sure which conda is active.

I can delete the current conda no problem: my doubt is why it has installed x86-xx when I installed conda using the ARM installer :/

psobolewskiPhD commented 1 year ago

No idea—I've been using the conda-forge conda from the beginning because it had arm64 support while anaconda didn't.

If you only care about radian, you could probably use the macOS system python3...

nicolopadovan commented 1 year ago

No idea—I've been using the conda-forge conda from the beginning because it had arm64 support while anaconda didn't.

If you only care about radian, you could probably use the macOS system python3...

I will give it a try immediately and eventually close the issue if solved :)