Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception: cannot load R library #120

Closed
plutoese opened this issue Oct 12, 2019 · 10 comments
Closed

Exception: cannot load R library #120

plutoese opened this issue Oct 12, 2019 · 10 comments

Comments

@plutoese
Copy link

While running radian, something goes wrong.
Traceback (most recent call last):
File "c:\python\lib\runpy.py", line 193, in run_module_as_main
"main", mod_spec)
File "c:\python\lib\runpy.py", line 85, in run_code
exec(code, run_globals)
File "C:\Python\Scripts\radian.exe_main
.py", line 9, in
File "c:\python\lib\site-packages\radian_init
.py", line 76, in main
RadianApplication(r_home, ver=version).run(options)
File "c:\python\lib\site-packages\radian\radianapp.py", line 83, in run
rchitect.init(args=args)
File "c:\python\lib\site-packages\rchitect\setup.py", line 27, in init
raise Exception("cannot load R library")
Exception: cannot load R library

@randy3k
Copy link
Owner

randy3k commented Oct 12, 2019

What version of R have you installed? Could you report the output of radian --version

@a-hurst
Copy link
Contributor

a-hurst commented Nov 30, 2019

Can confirm this is an issue with a fresh VM install of Windows 10, a fresh install of R 3.6.1, and Python 3.7.5 installed from the Microsoft Store:

C:\Users\austinhurst>python -m radian --version
radian version: 0.4.2
r executable: C:\Program Files\R\R-3.6.1\bin\R
r version: 3.6.1
python executable: C:\Users\austinhurst\AppData\Local\Microsoft\WindowsApps\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\python.exe
python version: 3.7.5

I get the same error as the user above:

C:\Users\austinhurst>python -m radian
Traceback (most recent call last):
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.7_3.7.1520.0_x64__qbz5n2kfra8p0\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.7_3.7.1520.0_x64__qbz5n2kfra8p0\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\austinhurst\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\radian\__main__.py", line 16, in <module>
    main()
  File "C:\Users\austinhurst\AppData\Local\Packages\PythonSoftwareFoundation.Python. 
  File "C:\Users\austinhurst\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\radian\radianapp.py", line 83, in run
    rchitect.init(args=args)
  File "C:\Users\austinhurst\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\rchitect\setup.py", line 27, in init
    raise Exception("cannot load R library")
Exception: cannot load R library

However, I decided to try uninstalling the Microsoft Store python and re-installing from Python.org, and sure enough radian works perfectly fine. Maybe the way the MS store version is compiled has some weird problems with cffi behaviour? Anyway, for now the solution is apparently just to use the Python.org version of Python. @plutoese, how did you install Python on your system?

@randy3k
Copy link
Owner

randy3k commented Nov 30, 2019

I’ll take a look when I have a chance.

@randy3k
Copy link
Owner

randy3k commented Nov 30, 2019

I could reproduce the same error with Microsoft store python 3.7. (And I even couldn't pip install radian with Microsoft store python 3.8). I didn't dig too much for the exact reason why it failed, I am guessing that it is lacking some dynamic libraries which cffi requires.

Traceback (most recent call last):
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.7_3.7.1520.0_x64__qbz5n2kfra8p0\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.7_3.7.1520.0_x64__qbz5n2kfra8p0\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\vagrant\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\Scripts\radian.exe\__main__.py", line 9, in <module>
  File "C:\Users\vagrant\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\radian\__init__.py", line 88, in main
    RadianApplication(r_home, ver=__version__).run(options)
  File "C:\Users\vagrant\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\radian\radianapp.py", line 83, in run
    rchitect.init(args=args)
  File "C:\Users\vagrant\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\rchitect\setup.py", line 29, in init
    system2utf8(ffi.string(lib._libR_dl_error_message()))))
Exception: Cannot load R shared library. The specified module could not be found.

@randy3k
Copy link
Owner

randy3k commented Dec 14, 2019

I finally figured out the reason why radian doesn't work with Microsoft Store python. It is because Microsoft Store apps are very conservative about DLLs searching path, i.e., it doesn't allow an app to search for DLLs outside of the system paths: https://docs.microsoft.com/en-us/windows/win32/dlls/dynamic-link-library-search-order#standard-search-order-for-windows-store-apps
Thus radian is not able to locate the Rblas.dll which is needed for opening R.dll.

The bad news is, however, that there is virtually no fix because R relies on dynamic imports.

@diandian11
Copy link

I also has the same errror
image
image

@randy3k
Copy link
Owner

randy3k commented Dec 29, 2019

Actually, it’s not the same error. In your case, radian even cannot locate the R shared library. I see that it is a 32bit python, do you also install a 32bit R?

@randy3k
Copy link
Owner

randy3k commented May 2, 2020

I came up with a workaround to support microsoft store python
randy3k/rchitect@9dba230

@randy3k randy3k closed this as completed May 2, 2020
@renkun-ken
Copy link
Contributor

@randy3k Nice work. Will remove the Microsoft Store Python issue from https://github.com/Ikuyadeu/vscode-R/wiki/Installation:-Windows when it is released.

@randy3k
Copy link
Owner

randy3k commented May 2, 2020

v0.5.4 is out :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants