# Using MATLAB Package with R2022b and R2021b downloaded

**URL:** <https://discourse.julialang.org/t/using-matlab-package-with-r2022b-and-r2021b-downloaded/90785>\
**Category:** New to Julia\
**Tags:** package\
**Created:** [November 24, 2022, 11:44pm UTC](https://discourse.julialang.org/t/using-matlab-package-with-r2022b-and-r2021b-downloaded/90785 "2022-11-24T23:44:08Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![dfb1002](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dfb1002/32/43827_2.png) [@dfb1002](https://discourse.julialang.org/u/dfb1002)\
**Post date:** [November 24, 2022, 11:44pm UTC](https://discourse.julialang.org/t/using-matlab-package-with-r2022b-and-r2021b-downloaded/90785/1 "2022-11-24T23:44:09Z")

</div>

Hello,

I am trying to use the MATLAB package, which I have read has a bug with both the R2022a and R2022b Matlab versions. I have R2021b installed, but when I attempt to build the package, it returns an error because it recognizes the copy of R2022b. On my other device, where I only have R2021b installed, it works fine. I still use Matlab for other purposes, so I need to keep a copy of the most recent version for that. Is there a way I can tell Julia to “look past” the R2022b copy of Matlab and find the R2021b copy? Or must I uninstall R2022b to make this work?

Thanks!

---

<div class="post-metadata">

**Author:** ![joa-quim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joa-quim/32/227_2.png) [@joa-quim](https://discourse.julialang.org/u/joa-quim)\
**Post date:** [November 25, 2022, 12:12am UTC](https://discourse.julialang.org/t/using-matlab-package-with-r2022b-and-r2021b-downloaded/90785/2 "2022-11-25T00:12:51Z")

</div>

Probably you must change the search order in your path such that R2021b is found first.

---

<div class="post-metadata">

**Author:** ![dfb1002](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dfb1002/32/43827_2.png) [@dfb1002](https://discourse.julialang.org/u/dfb1002)\
**Post date:** [November 25, 2022, 12:15am UTC](https://discourse.julialang.org/t/using-matlab-package-with-r2022b-and-r2021b-downloaded/90785/3 "2022-11-25T00:15:26Z")

</div>

How would I do that? Sorry, I am quite new to this language

---

<div class="post-metadata">

**Author:** ![joa-quim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joa-quim/32/227_2.png) [@joa-quim](https://discourse.julialang.org/u/joa-quim)\
**Post date:** [November 25, 2022, 12:19am UTC](https://discourse.julialang.org/t/using-matlab-package-with-r2022b-and-r2021b-downloaded/90785/4 "2022-11-25T00:19:35Z")

</div>

That’s not a Julia operation. You’d do that on OS side (Windows? Search the web on how to change the path)

---

<div class="post-metadata">

**Author:** ![dfb1002](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dfb1002/32/43827_2.png) [@dfb1002](https://discourse.julialang.org/u/dfb1002)\
**Post date:** [November 25, 2022, 12:44am UTC](https://discourse.julialang.org/t/using-matlab-package-with-r2022b-and-r2021b-downloaded/90785/5 "2022-11-25T00:44:19Z")

</div>

It’s not Windows, I have a Mac.

---

<div class="post-metadata">

**Author:** ![joa-quim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joa-quim/32/227_2.png) [@joa-quim](https://discourse.julialang.org/u/joa-quim)\
**Post date:** [November 25, 2022, 12:49am UTC](https://discourse.julialang.org/t/using-matlab-package-with-r2022b-and-r2021b-downloaded/90785/6 "2022-11-25T00:49:10Z")

</div>

Don’t remember how Matlab installs on Mac and how it gets found. Maybe it’s in your `.profile` or `.bashrc`. Where paths are declared. Sorry, you’ll to find that out (or some Macker helps you).

---

<div class="post-metadata">

**Author:** ![jd-foster](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jd-foster/32/35824_2.png) [@jd-foster](https://discourse.julialang.org/u/jd-foster)\
**Post date:** [November 25, 2022, 1:41am UTC](https://discourse.julialang.org/t/using-matlab-package-with-r2022b-and-r2021b-downloaded/90785/7 "2022-11-25T01:41:39Z")

</div>

Going off [the MATLAB.jl readme](https://github.com/JuliaInterop/MATLAB.jl#mac-os-x), you could try

```julia
pkg> rm MATLAB
julia> ENV["MATLAB_ROOT"] = "/Applications/MATLAB_R2012b.app"
pkg> add MATLAB

```

Replace the right-hand side with the path to your MATLAB app path if it’s different (you can click on the app and do Option-Command-C to copy the path to clipboard).

---

<div class="post-metadata">

**Author:** ![dfb1002](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dfb1002/32/43827_2.png) [@dfb1002](https://discourse.julialang.org/u/dfb1002)\
**Post date:** [November 30, 2022, 1:21am UTC](https://discourse.julialang.org/t/using-matlab-package-with-r2022b-and-r2021b-downloaded/90785/8 "2022-11-30T01:21:53Z")

</div>

Thank you! This worked in the sense that it now recognized R2021b, but I am now getting another error. It says LoadError: could not load library “/Applications/MATLAB\_R2021b.app/bin/maci64/libmx”  
dlopen(/Applications/MATLAB\_R2021b.app/bin/maci64/lixmx.dylib, 1): no suitable image found.

Do you know what that means?

---

<div class="post-metadata">

**Author:** ![jd-foster](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jd-foster/32/35824_2.png) [@jd-foster](https://discourse.julialang.org/u/jd-foster)\
**Post date:** [November 30, 2022, 3:40am UTC](https://discourse.julialang.org/t/using-matlab-package-with-r2022b-and-r2021b-downloaded/90785/9 "2022-11-30T03:40:37Z")

</div>

It means that the path to the library file that it thinks should be there  
`/Applications/MATLAB_R2021b.app/bin/maci64/lixmx.dylib`  
is not actually there. It don’t have MATLAB installed, so not sure why this is the case, but you can check whether you can follow the path in the Finder or Terminal to find out where it’s different.

---

<div class="post-metadata">

**Author:** ![dfb1002](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dfb1002/32/43827_2.png) [@dfb1002](https://discourse.julialang.org/u/dfb1002)\
**Post date:** [November 30, 2022, 12:15pm UTC](https://discourse.julialang.org/t/using-matlab-package-with-r2022b-and-r2021b-downloaded/90785/10 "2022-11-30T12:15:05Z")

</div>

I apologize, please bare with me. I am not very good with computer-related stuff. The idea of “path” is new to me from installing Julia. It took me forever to simply add Julia to the executable path because I don’t know anything about it.

How would I “follow the path” to see what is in Finder or Terminal? Also, what should I expect to add in order to make it work? Would I already have the needed file installed? I should mention that Matlab is working fine on my computer.

---

<div class="post-metadata">

**Author:** ![jd-foster](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jd-foster/32/35824_2.png) [@jd-foster](https://discourse.julialang.org/u/jd-foster)\
**Post date:** [December 1, 2022, 12:21am UTC](https://discourse.julialang.org/t/using-matlab-package-with-r2022b-and-r2021b-downloaded/90785/11 "2022-12-01T00:21:06Z")

</div>

Did you manage to do this?

> [@jd-foster](#):
>
> Replace the right-hand side with the path to your MATLAB app path if it’s different (you can click on the app and do Option-Command-C to copy the path to clipboard).

---

<div class="post-metadata">

**Author:** ![garrek](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/garrek/32/27937_2.png) [@garrek](https://discourse.julialang.org/u/garrek)\
**Post date:** [December 1, 2022, 4:30am UTC](https://discourse.julialang.org/t/using-matlab-package-with-r2022b-and-r2021b-downloaded/90785/12 "2022-12-01T04:30:54Z")

</div>

When you run a command from the terminal, the operating system doesn’t automatically know where the program is located in the file system. It has a list of directories where it can look. If it’s not in one of those, you get an error (`command not found` or something). So if you install a new program (like Julia or Python or something) you have to add it to this list of directories (or PATH) so that the OS can find it.

If you search for how to change your PATH on macOS, there are a quite a few articles. Here are a couple articles I found with more details:

> **[Add to PATH Mac: How to Set the PATH Variable in macOS](https://techpp.com/2021/09/08/set-path-variable-in-macos-guide/)**
>
> Learn how to set the PATH variable in macOS. The PATH variable is a file system environment variable that contains the location of commands and program files. In this article, you’ll learn how to set up your own PATH variable.

[https://beautifulracket.com/setting-the-mac-os-path.html](https://beautifulracket.com/setting-the-mac-os-path.html)

> **[How to get path of a file in Mac](https://setapp.com/how-to/how-to-find-the-path-of-a-file-in-mac)**
>
> Need to discover exactly where a file is located on your computer? Here’s how to get path of a file in Mac.

---

<div class="post-metadata">

**Author:** ![joa-quim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joa-quim/32/227_2.png) [@joa-quim](https://discourse.julialang.org/u/joa-quim)\
**Post date:** [December 1, 2022, 5:39pm UTC](https://discourse.julialang.org/t/using-matlab-package-with-r2022b-and-r2021b-downloaded/90785/13 "2022-12-01T17:39:49Z")

</div>

> [@dfb1002](#):
>
> could not load library “/Applications/MATLAB\_R2021b.app/bin/maci64/libmx”  
> dlopen(/Applications/MATLAB\_R2021b.app/bin/maci64/lixmx.dylib

I’m afraid the problem is way more complicated than a simple path adjustment. We had lots of problems like this with GMT MEX toolbox. The problem is that Mathworks shipped very old versions of some common used shared libs (netCXDF for example) and then they conflicted with those of the programs calling the Matlab libs. I’m not saying that’s what is happening here but hell smells a lot like it. The only way that I know of to track this is to use `otool -L` called on the program that has Matlab libs dependencies and see what comes out.

---

<div class="post-metadata">

**Author:** ![dfb1002](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dfb1002/32/43827_2.png) [@dfb1002](https://discourse.julialang.org/u/dfb1002)\
**Post date:** [December 1, 2022, 6:18pm UTC](https://discourse.julialang.org/t/using-matlab-package-with-r2022b-and-r2021b-downloaded/90785/15 "2022-12-01T18:18:40Z")

</div>

Yes, I was able to replace the path. It now finds R2021b. For what it’s worth, I have deleted R2022b entirely as I can run everything I need to at the moment on R2021b. The issue remains. I did this that way we don’t have to worry about the other version potentially causing any issue.

I mentioned in a reply to a different comment that I believe this is a Mac-only issue. On my Windows laptop with only R2021b installed, I had no issues using MATLAB.jl. Everything worked as intended with no need to change anything. I’m not sure if that helps, but it’s either an issue with the way OSX reads Matlab or an issue with the Mac version of MATLAB itself.

---

<div class="post-metadata">

**Author:** ![dfb1002](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dfb1002/32/43827_2.png) [@dfb1002](https://discourse.julialang.org/u/dfb1002)\
**Post date:** [December 1, 2022, 6:19pm UTC](https://discourse.julialang.org/t/using-matlab-package-with-r2022b-and-r2021b-downloaded/90785/16 "2022-12-01T18:19:12Z")

</div>

Perhaps this is the case, but I really don’t think it is. I had no issues using MATLAB.jl on my laptop, which only had R2021b installed. Now, out of curiosity, I have deleted R2022b from my current desktop that I hope to use, and the issue persisted. My laptop is Windows and my desktop is a Mac. If it was an issue of Matlab including old files, then the Windows version should have also had the same problem. Unless the Windows version of Matlab is more refined and doesn’t have the problem? I think this is somehow a Mac issue, but I’m so bad with computers in general that I can safely say I don’t have the capability to figure it out.

---

<div class="post-metadata">

**Author:** ![joa-quim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joa-quim/32/227_2.png) [@joa-quim](https://discourse.julialang.org/u/joa-quim)\
**Post date:** [December 1, 2022, 6:31pm UTC](https://discourse.julialang.org/t/using-matlab-package-with-r2022b-and-r2021b-downloaded/90785/17 "2022-12-01T18:31:28Z")

</div>

> [@dfb1002](#):
>
> then the Windows version should have also had the same problem.

Not necessarily. Unix is way more terrible with shared libs incompatibilities than Windows.

---

<div class="post-metadata">

**Author:** ![jd-foster](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jd-foster/32/35824_2.png) [@jd-foster](https://discourse.julialang.org/u/jd-foster)\
**Post date:** [December 2, 2022, 12:29am UTC](https://discourse.julialang.org/t/using-matlab-package-with-r2022b-and-r2021b-downloaded/90785/18 "2022-12-02T00:29:42Z")

</div>

I see now, the error said “no suitable image found.”

1. Can you post the full error message?
2. Can you say what macOS version you have?
3. Can you open Terminal, run this, and post the output?

```julia
dyld_info -platform /Applications/MATLAB_R2021b.app/bin/maci64/libmx.dylib

```

I’m wondering if there is an incompatibility here with your OS version.

---

<div class="post-metadata">

**Author:** ![jd-foster](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jd-foster/32/35824_2.png) [@jd-foster](https://discourse.julialang.org/u/jd-foster)\
**Post date:** [December 2, 2022, 12:35am UTC](https://discourse.julialang.org/t/using-matlab-package-with-r2022b-and-r2021b-downloaded/90785/19 "2022-12-02T00:35:15Z")

</div>

> [@dfb1002](#):
>
> I mentioned in a reply to a different comment that I believe this is a Mac-only issue.

Yes, that’s right. It’s to do with the way macOS is trying to work with the MATLAB code.

---

<div class="post-metadata">

**Author:** ![dfb1002](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dfb1002/32/43827_2.png) [@dfb1002](https://discourse.julialang.org/u/dfb1002)\
**Post date:** [December 5, 2022, 1:04pm UTC](https://discourse.julialang.org/t/using-matlab-package-with-r2022b-and-r2021b-downloaded/90785/20 "2022-12-05T13:04:42Z")

</div>

ERROR: Error building `MATLAB`:  
[ Info: Detected MATLAB root folder at “/Applications/MATLAB\_R2021b.app”  
[ Info: Detected MATLAB library path at “/Applications/MATLAB\_R2021b.app/bin/maci64”  
[ Info: Detected MATLAB executable at “/Applications/MATLAB\_R2021b.app/bin/matlab”  
ERROR: LoadError: could not load library “/Applications/MATLAB\_R2021b.app/bin/maci64/libmx”  
dlopen(/Applications/MATLAB\_R2021b.app/bin/maci64/libmx.dylib, 1): no suitable image found. Did find:  
/Applications/MATLAB\_R2021b.app/bin/maci64/libmx.dylib: mach-o, but wrong architecture  
/Applications/MATLAB\_R2021b.app/bin/maci64/libmx.dylib: mach-o, but wrong architecture  
Stacktrace:  
[1] dlopen(s::String, flags::UInt32; throw\_error::Bool)  
@ Base.Libc.Libdl ./libdl.jl:117  
[2] dlopen (repeats 2 times)  
@ ./libdl.jl:116 [inlined]  
[3] dlpath(libname::String)  
@ Base.Libc.Libdl ./libdl.jl:240  
[4] top-level scope  
@ ~/.julia/packages/MATLAB/SVjnA/deps/build.jl:79  
[5] include(fname::String)  
@ Base.MainInclude ./client.jl:476  
[6] top-level scope  
@ none:5

This is the error message.

I have Mac OS Big Sur.

I posted that message in the terminal, and it said zsh: command not found: dyld\_info

---

<div class="post-metadata">

**Author:** ![dfb1002](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dfb1002/32/43827_2.png) [@dfb1002](https://discourse.julialang.org/u/dfb1002)\
**Post date:** [December 5, 2022, 1:05pm UTC](https://discourse.julialang.org/t/using-matlab-package-with-r2022b-and-r2021b-downloaded/90785/21 "2022-12-05T13:05:47Z")

</div>

It feels strange that macOS is not properly working with the Matlab code when Matlab itself works. I guess I don’t see how that’s possible, but I suppose it is here.

[Next page](https://discourse.julialang.org/t/using-matlab-package-with-r2022b-and-r2021b-downloaded/90785.md?page=2)
