Message Boards Message Boards

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

Installing and using a third-party package

Posted 3 years ago

Downloaded a package file from internet (fictitious name: packagename.m)

Installed the package and verified that a file with the same package name has been created under (Windows O.S.) directory "C:\ProgramData\Mathematica\Applications"

If I call Needs["packagename"] I get the message ....Needs::nocont: Context qulib was not created when Needs was evaluated.

If I call Needs["packagename.m"] I get the message ...Needs::cxt: Invalid context specified at position 1 in Needs[qulib.m]. A context must consist of valid symbol names separated by and ending with `.

An Internet search did not help with this apparently stupid problem...thank you very much.

POSTED BY: andrea andrea
2 Replies
Posted 3 years ago

Get does not reply with any message...apparently it work...many many thanks Joel for the explanations and for the super fast reply.

I will add beginPckage and EndPackage to the package file to have the package added as a context.

Thanks again.

POSTED BY: andrea andrea
Posted 3 years ago

Try using "Get" instead of "Needs". Also, add a backtick to the end of the filename, or use the .m extension explicitly.

As the messages suggests, Needs expects the package file to do a little more than just contain code. Needs expects the package file to contain a BeginPackage/EndPackage construct that adds a context like MyPackage` to the context path. Apparently the package file you downloaded doesn't do that.

Get will just expect to find syntactically-correct Wolfram Language code and evaluate it and return the last expression, nothing more.

The advantage of having a package add to the context path is that multiple calls to Needs will result in the file being loaded only once. It does that by checking whether the requested context has been added to the context path.

POSTED BY: Joel Klein
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