Search code examples
csvdependenciesjulia

Can't run Julia script using environment libraries


Heyo.

I've been struggling running packages and might need some help. Here's what I've done so far:

  1. Used Pkg to generate a project called Void

  2. Added CSV and DataFrames as dependencies (which got listed in the TOML)

  3. Saw the project status (which included both libraries)

  4. Instantiated

But still, my project won't run anything that contains the libraries. Here's my code:

# src/Void.jl
using CSV, DataFrames

module Void
    function testing()
        frame = CSV.read("sheet.csv", DataFrame)
        print(frame)
    end
end

Void.testing()

export Void

I tried julia --project=. src/Void.jl to run this script, but it gave me UndefVarError: `CSV` not defined.

Trying julia --project=. and using Void in this order threw me an error saying CSV ain't a dependency too.

ERROR: LoadError: ArgumentError: Package Base does not have CSV in its dependencies:
- You may have a partially installed environment. Try `Pkg.instantiate()`
  to ensure all packages in the environment are installed.
- Or, if you have Base checked out for development and have
  added CSV as a dependency but haven't updated your primary
  environment's manifest file, try `Pkg.resolve()`.
- Otherwise you may need to report an issue with Base
Stacktrace:
 [1] macro expansion
   @ .\loading.jl:1634 [inlined]
 [2] macro expansion
   @ .\lock.jl:267 [inlined]
 [3] require(into::Module, mod::Symbol)
   @ Base .\loading.jl:1611
 [4] include
   @ .\Base.jl:457 [inlined]
 [5] include_package_for_output(pkg::Base.PkgId, input::String, depot_path::Vector{String}, dl_load_path::Vector{String}, load_path::Vector{String}, concrete_deps::Vector{Pair{Base.PkgId, UInt128}}, source::Nothing)
   @ Base .\loading.jl:2049
 [6] top-level scope
   @ stdin:3
in expression starting at C:\Users\alunotemp\Área de Trabalho\Codes\Void\src\Void.jl:1
in expression starting at stdin:3

I also tried doing what the error sugested, but none worked. What am I doing wrong?


Solution

  • You need to do using CSV, DataFrames inside the module like this:

    module Void
        using CSV, DataFrames
        function testing()
            frame = CSV.read("sheet.csv", DataFrame)
            print(frame)
        end
    end
    

    Note though that creating modules is not very simple as there are several concepts you need to learn. I recommend you read in detail https://docs.julialang.org/en/v1/manual/modules/ before doing this.

    Most Julia users never need to create their own modules.