pit007

pit007

I’m trying to develop a project using Livebook.
So I wrote and tested the code for the first module.
I don’t want to publicize the code to Hex yet, because it’s way too early for this.
I created a new project using mix.
Now I would like to use the code of my first module in Livebook for further development.
When specifying the module name in Livebook’s Mix.install section I get the error message “No package with name…”. I kind of expected this. But then how can I “import” the module for use inLivebook?

Showing Posts 1 to 10

outlog

outlog

you can use the path option

Mix.install([
  {:mylib,  path: "/Users/myuser/somefolder/mylib"}
])
w0rd-driven

w0rd-driven

You may prefer relative paths using __DIR__. That would resolve to the directory your notebook is in.

For this type of work I usually create a directory, run git init, save my notebook here, commit, then run mix new <library_name> so everything is co-located.

An alternative would be to mix new, initialize git, and commit (I always commit immediately after the generator runs before I make any customizations), then save a notebook under the notebooks directory. Then you could do something like __DIR__/../ to go up to the parent directory and load the library that way. This approach is probably better if you’re wanting to include a notebook with your library.

The first approach makes sense if your primary focus is the notebook itself with tiny libraries to support it. You never need to publish to hex in either scenario if you don’t want to. If you package the whole thing in a git repository, other users can replicate your work whereas a standalone notebook wouldn’t work without all your dependencies.

You likely do not want to use absolute paths because my /Users/jeremy/ directory is not the same as your /Users/pit007 would be for an example. If you’re the only one using the notebook, portability doesn’t matter but I create very few notebooks for just myself.

adkron

adkron

I like to run an elixir application and then connect to that application instead of directly trying to pull in libraries.

Run your project with something like iex --sname test --cookie mycookie -S mix, which will start an iex console with your library loaded. Note the sname and cookie you use to create the session.

Then inside the livebook, find
Screen Shot 2022-11-18 at 3.29.41 PM
and click it. A menu will appear, and click the Configure button. Once the popup appears, click Attached node. You can then fill in your cookie and name and click connect. Now your livebook will have access to the same session at your iex console.

When you recompile code in iex, the livebook will have all the updated code available.

@w0rd-driven’s solution works. Connecting to a running node is my preferred method.

bmitc

bmitc

I’m noticing that after recompiling inside IEx, I still have to click the “Reconnect and setup” cell at the top to get the updates, even though there’s nothing in that cell. The Livebook doesn’t automatically update. Is this your experience?

Livebook also doesn’t seem to take into account the .iex.exs file where I have pre-entered aliases that I want to use in an IEx session or Livebook notebook. I still have to re-alias things inside the notebook.

pit007

pit007 OP

No, I just didn’t know I had to recompile.
After all Phoenix notices changes automatically via inotify and recompiles.

Thanks for your comment.

adkron

adkron

When starting Phoenix with iex -S, it no longer seems to pick up the signal to recompile. If you hop into the console and type recompile it will work. I haven’t tried to see if there is a way to fix this. Using the recompile command, you will not have to restart and reset the connection.

pit007

pit007 OP

Wonderful

Thank you very much for your help.
Cheers
Peter

adkron

adkron

Okay, I did some playing around, and this appears inaccurate. I just tried again and added a function to the LiveView. That seemed not to require a call to recompile. I’m going to experiment a little and see what I find. I’ll check back in if I figure anything out.

linusdm

linusdm

I had a similar question about recompilation a few months back. José and Jonatan were kind enough to answer my question in the github discussions here: How to recompile installed mix dependency (with `:path` option) without reconnecting runtime? · livebook-dev/livebook · Discussion #1625 · GitHub

Tl;dr: recompilation is not (yet) supported by Mix.install/2, so reconnecting is the only option, for path-dependencies.

bmitc

bmitc

Interestingly enough, I am now just doing recompile inside the session started by iex --sname <name> --cookie <cookie> -S mix, and it is working. This exact thing wasn’t working earlier when I posted my previous reply, for whatever reason, but now, I can just do recompile and then re-evaluate individual cells as expected. I’m not for sure what changed or if Livebook just got into some weird state.

I haven’t rechecked the .iex.exs file not being read.

— All posts loaded —

Where Next? Top

Trending in Questions Top

stjefim
Hello! Suppose you are building workflow (order / task / payment) processing system with the following requirements: Each workflow con...
New
jonnycharles
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
spammy
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
dli
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app? Looking for hints regarding: Addi...
New
roeland
Kia ora, We have been using elixir-google-api to connect to Google Drive. However, with the updates to Tesla due to CVEs this is now bro...
New
bottlenecked
Hi all, I wanted to ask how the community is dealing with post-release steps. Today we have Ecto migrations, which make sure that the db...
New
rahultumpala
Hello, I have an Elixir backend that implements a custom protocol over TCP. I want to load test the backend and assess the performance o...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge &amp; Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews