Brian

Brian

What is the proper way to load a module from a file in to IEX?

In the python world, doing something like this pretty standard:

from . import xyz
xyz.do_something()

I did a bit of google and this is what I found
$ iex

Code.load_file(“some_file.exs”)
moduleFromSomeFile.doSomething(1)

I was wondering if this is the “right” way to import a module in to iex and just inspecting/playing around with functions.

Thank you

Showing Posts 1 to 10

OvermindDL1

OvermindDL1

If the compiled module is on the binary path for the BEAM then you can just do import Xyx to import everything from it. Or call it straight with Xyz.blah(42). mix sets up all those paths for you automatically if it is part of a project so with a mix project you can just do iex -S mix to get everything linked properly.

elderbas

elderbas

If I’m just dinkin around in a directory, outside of a mix project, and I have a module named “SomeModule.exs” in the working directory and I’m in iex, I do
c "SomeModule.exs", and I’ll have the module available to play with.

12
Post #2
bgargi

bgargi

Hey there!
You could simply use- “import abc” (Given that you are in the directory where the module is defined)
and then happily use the functions defined in abc ,and hence without having to do abc.fun1() simply do fun1().

m31271n

m31271n

  • import_file/1
  • c/1 / c/2 / r/1

Above are what you need. Enjoy!

robchristian

robchristian

Wow, not a single one of of these worked for me. Many show the module compile, but then the functions I expect are undefined. Could somebody show me a complete example, of how to run Jason.encode!(%{ "a" => 1 }), in the Elixir REPL, from inside a mix project?

hauleth

hauleth

$ iex -S mix
iex> Jason.encode!(%{"a" => 1})
"{\"a\":1}"
axelson

axelson

Scenic Core Team

Generally in Elixir you will not be importing modules from outside your project, so you will not need the techniques listed in this post. Instead you will generally declare dependencies (by adding to the list of deps in your mix.exs file). Then (as @hauleth showed) you can run iex -S mix to start an iex session inside the project, which will have all the modules from all your dependencies loaded (also if you’re using phoenix you may be interested in running iex -S mix phx.start to have an iex shell in the same beam instance as your phoenix application).

Here’s a page from the official tutorial with some more info: https://elixir-lang.org/getting-started/mix-otp/introduction-to-mix.html

fargozhu

fargozhu

what if you need to debug in a docker prod container where you don’t have the mix* files and you need to load HTTPoison to understand a catchy issue that doesn’t happen in your test env?

axelson

axelson

Scenic Core Team

Yeah, that doesn’t sound like a general case :+1:

mrjbj

mrjbj

I have a fixture under test/support/fixtures that isn’t working. I was hoping to load that module into iex and debug it interactively but i get “module not loaded and could not be found”. Is there a way to config for this scenario? Thanks.

Where Next? Top

Trending in Questions Top

katta
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
achenet
Hello, I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind. However, when I launch mix phx.server, I get an error...
New
Cxx-mlr
I’m working on a small exercise involving update_in/3, and I came up with this solution: data = %{ name: "Periodic Table", category:...
New
ChrisAmelia
I’ve got trouble wrapping my head around the order in which functions are called in this snippet (from Phoenix’s authentication): toke...
New
unaware8150
Hello folks! So at work, we are seeing some situations where we have to define some “fixed” strings that are used across the codebase in...
New
dillonoconnor
Is there any way to avoid the Hologram compiler running when using iex? It seems like the front-end code could potentially be disregarded...
New
thiagogsr
** (ArgumentError) expected :max_attempts to be a positive integer, got: {:@, [line: 10, column: 19], [{:max_attempts, [line: 10, column:...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New
KristerV
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
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

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews