WolframLang: Load a Package or File

By Xah Lee. Date: . Last updated: .

Load Any File of WolframLang Code

Load a file. It search file in dirs in $Path.

Get[ "c:/Users/xah/Desktop/Xah_WolframLang_packages/PlaneCurvePlot/PlaneCurvePlot.wl" ]

Load File in Current Dir

(* load a file, where the file is in the same dir as the current notebook *)

Get[StringJoin[NotebookDirectory[], "myfile.wl"]]
(* load a file, where the file is in the same dir as the running script *)

Get[StringJoin[ DirectoryName[ $InputFileName ] , "myfile.wl"]]

〔see WolframLang: Get Script Path, Notebook Dir

Load a Package by Context Name

Another way to load a package, is to call Needs. This is a slightly higher level, based on Context Name , not a hard file path. It'll only load the file if the context is not already loaded.

Needs[ ContextName ]

Load a file if ContextName is not already in $Packages

The file name to load is based on ContextName to filename convention. You can give a second argument for a specific file name.

〔see WolframLang: Context (Namespace)

Once it figured out a file name, it calls Get to load the file.

in general, for Needs to work, you should put packages in the Wolfram Library Dir, in the Applications or Autoload subdirectory. 〔see WolframLang: Init Dir, Library Dir

Needs

Needs[ "PlaneCurvePlot`" ]

WolframLang, Package, Load File

WolframLang, Shell Tasks