I have a package and notebook in the same directory, but Needs is throwing an error

"Cannot open EField.m".

I have tried several variations of this. I am using the following command in my notebook. The notebook and EField.m are in the same directory.

Needs["EKSModel`EFields`", "EField.m"]

The package is declared as:


Do we need to register packages when they are in the same directory?

  • $\begingroup$ Is the directory on $Path? $\endgroup$ – ilian Jun 3 '15 at 16:53

The Notebook location is not automatically added to the package search path.

Try assembling the qualified file path with NotebookDirectory and FileNameJoin:

Needs["EKSModel`EFields`", FileNameJoin[{NotebookDirectory[], "EField.m"}]]
  • $\begingroup$ Thanks Mr. Wizard - I used strESegment = NotebookDirectory[] <> "ElectrodeSegment.m" strEFieldPath = NotebookDirectory[] <> "EField.m" Get[strESegment] Get[strEFieldPath] Would there be any way to wrap this in a Try ... Catch or equivalent error checking? $\endgroup$ – Doug Kimzey Jun 4 '15 at 18:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.