Wolfram: Load a Package or File

By Xah Lee. Date: . Last updated: .

Get (Load a File of Wolfram Code)

Get[filename]

🔸 SHORT SYNTAX: <<filename

  • Load a file of Wolfram language code, by file name.
  • filename can also be file fullpath.
  • If filename is not fullpath, search the file in $Path. 〔see Wolfram: Search Paths $Path
Get[ "PlaneCurvePlot.wl" ]
Get[ "c:/Users/xah/git/PlaneCurvePlot/PlaneCurvePlot.wl" ]

Example. Load File in Current Notebook Dir

(* load a file that is in the current notebook dir *)

Get[FileNameJoin[ {NotebookDirectory[], "myfile.wl"}] ]

Example. Load File in Current Script Dir

(* load a file that is in the same dir as the running script *)
Get[FileNameJoin[ {DirectoryName[ $InputFileName ] , "myfile.wl"]}]

Load a Package by Context Name

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.

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.

Needs[ "PlaneCurvePlot`" ]

Wolfram. Package, Load File

Wolfram. Shell Scripting Tasks