Wolfram: Load a Package or File

By Xah Lee. Date: . Last updated: .

Load Any File of WolframLang Code

Load a file by file name. It search file in dirs in $Path. 〔see Wolfram: Search Paths $Path for Loading File

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

Load File in Current Notebook Dir

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

Get[StringJoin[NotebookDirectory[], "myfile.wl"]]

Load File in Current Script Dir

(* load a file, where the file is in the same dir as the running script *)

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

〔see Wolfram: 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 Wolfram: 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 Wolfram: Init Dir, Library Dir

Needs

Needs[ "PlaneCurvePlot`" ]

WolframLang, Package, Load File

WolframLang, Shell Scripting Tasks