Error while knitting Rmarkdown with reticulate: OSError: libomp.dylib not found - r-markdown

I'm trying to knit an Rmarkdown with reticulate for a chunk of python code.
Knitting throws out an error saying libomp.dylib not found, but the code runs fine as a chunk (not knitted).
Machine: Macbook M1 Max
OS: Ventura 13.0.1
I used below packages for python with reticulate.
library(reticulate)
use_python("/Users/ramanujam/opt/anaconda3/bin/python")
from lazypredict.Supervised import LazyClassifier
from sklearn.model_selection import train_test_split
I'm Getting the error below.
However, code executes fine as a chunk.
Error in py_call_impl(callable, dots$args, dots$keywords) :
OSError: dlopen(/Users/xxx/opt/anaconda3/lib/python3.9/site-packages/lightgbm/lib_lightgbm.so, 0x0006): Library not loaded: /usr/local/opt/libomp/lib/libomp.dylib
Referenced from: <8DF2AF67-B85F-3F67-B687-E50A514307EC> /Users/xxx/opt/anaconda3/lib/python3.9/site-packages/lightgbm/lib_lightgbm.so
Reason: tried: '/usr/local/opt/libomp/lib/libomp.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/usr/local/opt/libomp/lib/libomp.dylib' (no such file), '/usr/local/opt/libomp/lib/libomp.dylib' (no such file), '/Library/Frameworks/R.framework/Resources/lib/libomp.dylib' (mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64')), '/Library/Java/JavaVirtualMachines/jdk1.8.0_241.jdk/Contents/Home/jre/lib/server/libomp.dylib' (no such file)
I underestand this is a dependency on libomp.
I already tried installing libomp with
brew install libomp
Tried creating a symlink to R.framework path from the brew install location but there is a conflict of architecture there.
Since the code executes in chunk but has trouble during knitting, I'm guessing the libomp source used is different there. But I'm not clear on how or why Rstudio would have a different source while running in chunks vs. knitting as I have specified the python path to be used.
Any help would be appreciated. Thanks in advance!

Related

No module named 'numpy.core._multiarray_umath'

I am trying to use matploitlib_cpp on Windows 11 with Numpy 1.24.2 and Python 3.11, but I keep running in to the following error.
Original error was: No module named 'numpy.core._multiarray_umath'
I know this has been posted at a million different places on the internet and I have tried following all the guides that says reinstalling numpy and whatever, it does not work for me. What I can see in my path ..\Python3.11\Lib\site-packages\numpy\core is that I have a file named _multiarray_umath.cp311-win_amd64.pyd but no file named _multiarray_umath. I also tried to use a virtual environement from Anaconda but I am not sure how to build matploitlib_cpp against such virtual enviornment.
I got it working by using the release binaries instead of debug binaries.

Caffe2 installed correct but can't load glog library

I pip installed caffe2 via a "Prebuilt Caffe2 Python Wheel" without an error. But running the first example I get the following error message which seems not be able to find/load "/usr/local/opt/glog/lib/libglog.0.dylib".
If I import caffe2.python it does not give me an error.
The glog is missing in usr/local/opt.
Is this a Mac GPU problem ? I know that CUDA is a problem/does not run on Mac or is there anything else I missed/I have to do. ?
Thanks for any help.
WARNING:root:This caffe2 python run does not have GPU support. Will run in CPU only mode.
WARNING:root:Debug message: No module named caffe2_pybind11_state_gpu
CRITICAL:root:Cannot load caffe2.python. Error: dlopen(/usr/local/lib/python2.7/site-packages/caffe2/python/caffe2_pybind11_state.so, 10): Library not loaded: /usr/local/opt/glog/lib/libglog.0.dylib
Referenced from: /usr/local/lib/python2.7/site-packages/caffe2/python/caffe2_pybind11_state.so
Reason: image not found

ImportError: libjpeg.so.9

I have installed opencv in ubuntu. Now, when I am importing cv2,
there is an error
'ImportError: libjpeg.so.9: cannot open shared object file: No such file or directory'
How to fix the error ?
I have already searched net and tried some but couldn't resolve the error.
I have also tried the following :
sudo apt-get install libjpeg9
The following is the output :
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package libjpeg9
Thanks..
For whatever reason your version of OpenCV has been oucompiled against http://ijg.org/files/jpegsrc.v9b.tar.gz ... Either you should also compile and instlal that or you can recompile opencv with libraries that are on your system.

Jpegs in Django-wiki

I'm trying to get django-wiki running.
It works well so far, except I can't display .jpeg images.
At first I had trouble when only importing jpeg files in the webapp.
I fixed this modifying setup.py of PIL's setup.py as follows:
JPEG_ROOT = libinclude("/usr/lib")
# Line 214
add_directory(library_dirs, "/usr/lib")
add_directory(library_dirs, "/usr/lib/x86_64-linux-gnu")
Jpeg libs I have currently installed:
libjpeg-progs
libjpeg62:amd64
libjpeg62-dev:amd64
libjpeg8:amd64
libopenjpeg2:amd64
After install PIL with pip install PIL, I get this output which doesn't look that bad, at least I thought so
*** TKINTER support not available
--- JPEG support available
--- ZLIB (PNG/ZIP) support available
*** FREETYPE2 support not available
*** LITTLECMS support not available
No error messages (and no "decoder ntót available") and I can view the images properly on my server, which means upload works great. But in the wiki only the file names are shown and when I click on them I get
"This image failed to load."
Could someone please help me? I can't find any error output (debug mode is activated).
Thanks in advance
You are compiling software! You need to install development libraries for these things to compile, e.g. apt-get install libjpeg-dev.
Also, install Pillow, it has less chances of failure to compile - pip install pillow.

Mac/Django error message: "/mercurial/osutil.so: no appropriate 64-bit architecture"

I'm new to Macs (and quite new to Django) and I'm setting up an existing Django/MySQL site that uses Mercurial as a site package, on a new Macbook Pro.
All was going well during installation - no error messages. I installed the default versions of most packages from macports.
However when I try runserver, localhost shows the following error message:
ImportError at /
.../lib/python2.6/site-packages/mercurial/osutil.so: no appropriate 64-bit architecture (see "man python" for running in 32-bit mode)
Please could anyone advise? I've tried typing the following at the terminal:
defaults write com.apple.versioner.python Prefer-32-Bit -bool yes
but it didn't help.
I've gotten a similar error and a combination of two things helped me install Mercurial for OS X Lion. I'm running OS X 10.7.3.
First, there is a bug on line 455 of the setup.py script (at least for Mercurial 2.2.1, the version I tried). The line
version = runcmd(['/usr/bin/xcodebuild', '-version'], {})[0].splitlines()
should be replaced with
version = runcmd(['/usr/bin/xcodebuild', '-version'], {})[0]
Second, after I installed Mercurial (either by easy_install, Mac OS X binary installer, and compilation), I kept getting the following error message:
ImportError: dlopen(/Library/Python/2.7/site-packages/mercurial/osutil.so, 2): no suitable image found. Did find: /Library/Python/2.7/site-packages/mercurial/osutil.so: mach-o, but wrong architecture
However, after seeing this post, I noticed that
defaults read com.apple.versioner.python Prefer-32-Bit
outputs 1 on my system. However, running this command
defaults write com.apple.versioner.python Prefer-32-Bit -bool no
and then recompiling / installing mercurial resulted in a working executable for me at the end.
If everything from my comment checks out, try setting that Prefer-32-bit in an user environment variable instead of at the command line.
Edit this file: ~/.MacOSX/environment.plist
See:
http://developer.apple.com/mac/library/documentation/MacOSX/Conceptual/BPRuntimeConfig/Articles/EnvironmentVars.html#//apple_ref/doc/uid/20002093-113982