2
$\begingroup$

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:

BeginPackage["EKSModel`EFields`"]

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

$\endgroup$
1
  • $\begingroup$ Is the directory on $Path? $\endgroup$
    – ilian
    Jun 3, 2015 at 16:53

1 Answer 1

2
$\begingroup$

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"}]]
$\endgroup$
1
  • $\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$ Jun 4, 2015 at 18:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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