Message Boards Message Boards

0
|
171 Views
|
2 Replies
|
2 Total Likes
View groups...
Share
Share this post:

How do I make a package run automatically when there is a Needs[ ] function call in a notebook

Posted 2 days ago

Though I'm an experienced programmer, unfortunately I just dabble with Mathematica and am struggling with some stuff I would have expected (as a programmer) to be trivial

(NB I did Google searches and even a session with ChatGPT but could not get an answer that worked)

Basically, I wrote a small financial analysis package for myself and decided to put the common function in a separate package (for reuse). The package has a .m extension and of course is bracketed with BeginPackage/EndPackage and the path to that package is in the search path for Mathematica.

My problem is that package does not seem to run automatically when it is needed. Specifically, if I don't explicitly open that package and click the Run Package button, then my main notebook that uses that package doesn't work.

How do I make that package be automatically available and ready for use?

Thanks in advance

POSTED BY: David Jameson
2 Replies
Posted 2 days ago

Thank you --- now I understand and I have it working.

I was misled by the fact that explicitly running that package made it work and so I just assumed it had been found but (of course) running the package just pulled in those functions to the system.

I guess it would be nice if paths could be set from the Settings dialog.

POSTED BY: David Jameson

For Needs to work, first verify that FindFile can find the package And for that to work, verify that the package is in one of the directories listed in $Path or modify $Path to include the location where you have it. That is a dollar sign followed by Path. It is next to impossible to type it here for some reason.

POSTED BY: Gustavo Delfino
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract