require
require(module::Symbol)
This function is part of the implementation of using / import, if a module is not already defined in Main. It can also be called directly to force reloading a module, regardless of whether it has been loaded before (for example, when interactively developing libraries).
Loads a source files, in the context of the Main module, on every active node, searching standard locations for files. require is considered a top-level operation, so it sets the current include path but does not use it to search for files (see help for include). This function is typically used to load library code, and is implicitly called by using to load packages.
When searching for files, require first looks in the current working directory, then looks for package code under Pkg.dir(), then tries paths in the global array LOAD_PATH.
Examples
julia> require("MyModule")
MyModule
julia> require(:MyModule)
MyModule
The require function is used to load a module in Julia. The module can be specified either as a string or as a symbol.
Here are a few common examples of how to use the require function:
-
Load a module specified as a string:
julia> require("MyModule") MyModuleThis example loads the module named "MyModule" by providing its name as a string.
-
Load a module specified as a symbol:
julia> require(:MyModule) MyModuleThis example loads the module named "MyModule" by providing its name as a symbol.
-
Force reloading a module:
julia> require(:MyModule) MyModule # After making changes to the module julia> require(:MyModule) MyModuleIf a module has already been loaded, you can force a reload by calling
requireagain.
Note: The require function searches for files in the current working directory, under Pkg.dir(), and in the paths specified in the global LOAD_PATH array.
See Also
assert, backtrace, code_llvm, code_lowered, code_native, code_typed, code_warntype, :@which, compilecache, current_module, eval, finalize, finalizer, fullname, function_module, function_name, include_dependency, InterruptException, invoke, isconst, isdefined, isgeneric, methodswith, method_exists, module_name, module_parent, require, subtypes, unsafe_load, workspace, __precompile__,User Contributed Notes
Add a Note
The format of note supported is markdown, use triple backtick to start and end a code block.