Message Boards Message Boards

User-written package not processed when Get or Needs requests access

I'm on a Mac. I've written a package named FRED

(BeginPackage["FRED`"]) 

in notebook named FederalReservePackage.nb. It is a significantly modified version of an older Mathematica demonstration project with same name. FRED accesses the Federal Reserve Economic Data at the St. Louis Federal Reserve website using their API.

It has been evaluated successfully, and tested, then Saved As a Wolfram Language file FederalReservePackage.wl. I then used the Install Pallette function to install item type Package, source FederalReservePackage.wl, install name FRED, install for this user only. The file system shows that FRED.wl was installed in directory ~/Library/Mathematica/Applications, as documented. This directory is listed in the $Path variable.

In another nb file, I use

<<Fred`, or Get["FRED`"] or Needs["FRED`"] 

to attempt to access the package, but the entry points are not defined. Output from Needs says

"Needs: Context FRED` was not created when Needs was evaluated."

What am I doing wrong?

PS: If FRED is evaluated in the same kernel as the nb file, the application works.

POSTED BY: Lawrence Winkler
5 Replies
Posted 5 years ago

If you have a notebook and want to convert it to a package:

1. Wrap the notebook code between BeginPackage["context`"] and EndPackage[]. Make all the input cells to be initialization cells.

enter image description here

2. Save the .nb file as a .wl file in a place where MMA will find it. Filename same as the context. PackageTest in this example.

3. It should now be possible to call and use the package

enter image description here

POSTED BY: Hans Milton

Welcome to Wolfram Community! Please make sure you know the rules: https://wolfr.am/READ-1ST

The rules explain how to format your code properly. If you do not format code, it may become corrupted and useless to other members. Please EDIT your post and make sure code blocks start on a new paragraph and look framed and colored like this.

int = Integrate[1/(x^3 - 1), x];
Map[Framed, int, Infinity]

enter image description here

POSTED BY: Moderation Team

The context mark is in my code and in the message. However, the post eliminated the hash marks in the second paragraph. Thanks for pointing that out. I'll try to fix the post.

POSTED BY: Lawrence Winkler
Posted 5 years ago

Try Needs["Fred`"]

Notice the context mark after Fred.

POSTED BY: David Keith

I describe how to do this, according to the way that WRI provides, in an essay at my web site. You need only the first part of the essay.

Essentially, create an application in your $UserBaseDirectory/Applications directory and put your package there. If you have any other resources such as a palette your can also place it in your application. You can place everything there and Mathematica will automatically know how to find it. You don't have to use any Mathematica Install Palette operations. You can also have more than one package file there if you wish. It's all very simple and standard and yet users seem to get drawn away from it for no good reason at all.

You can also easily send the entire application to any other Mathematica user and they can install it simply by unzipping into their Applications folder.

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