I'm trying to use the Hex packaged CSV.
I'm added the dependency to mix.exs like so:
def application do
[applications: [:logger, :csv]]
end
defp deps do
[
{:csv, "~> 1.4.2"}
]
Then, I run mix deps.get
& mix deps.compile
in terminal.
The dependency folder shows up in deps folder.
Everything seems to be okay until I try to use the dependency. I'm getting this error:
"module CSV is not loaded and could not be found"
I've tried a simply use without importing like so:
File.stream!("data.csv") |> CSV.decode
I've tried importing like so:
import(CSV)
File.stream!("data.csv") |> CSV.decode
I've tried prefixing the deps directory:
import(deps.CSV)
File.stream!("data.csv") |> CSV.decode
And the full path to the deps subdirectory:
import(deps.csv.lib.csv.CSV)
File.stream!("data.csv") |> CSV.decode
No matter what it doesn't seem to find the dependency module.
What am I missing?
I'm guessing that your IDE is misconfigured. Here is an command line example of how to get up and running.
mix new csv_tester
cd csv_tester
# edit mix.exs to add {:csv, "~> 1.4"} to your deps, like you have above
mix deps.get
iex -S mix
iex(1)> [["name", "age"], ["Bob Saget", 64]] |> CSV.encode() |> Enum.join("")
"name,age\r\nBob Saget,64\r\n"
Modules are globally accessible, so you do not need to use the import
statement unless you only want a specific function in a given module, or you do not want to have to fully qualify the function call with the Module name. See import docs.
Anything that you can execute in iex
you should be able to call from any other Module in your project
If you still need help debugging, you can run this in iex to list all modules that should be available at runtime and then filter for anything containing CSV in the module name:
iex(1)> :code.get_path() |>
Enum.map(&to_charlist/1) |>
Enum.map(&:erl_prim_loader.list_dir/1) |>
Enum.map(&elem(&1, 1)) |>
Enum.concat() |>
Enum.map(&to_string/1) |>
Enum.filter(fn module -> module =~ "CSV" end)
Which should output something like this
["Elixir.CSV.Encode.beam", "Elixir.CSV.Encoder.beam", "Elixir.CSV.beam",
"Elixir.CSV.Lexer.EncodingError.beam", "Elixir.CSV.LineAggregator.beam",
"Elixir.CSV.Parser.beam", "Elixir.CSV.Lexer.beam",
"Elixir.CSV.Encode.BitString.beam",
"Elixir.CSV.LineAggregator.CorruptStreamError.beam", "Elixir.CSV.Decoder.beam",
"Elixir.CSV.Decoder.RowLengthError.beam", "Elixir.CSV.Encode.beam",
"Elixir.CSV.Parser.SyntaxError.beam", "Elixir.CSV.Encode.Any.beam",
"Elixir.CSV.Defaults.beam"]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With