1
$\begingroup$

There is great code by István Zachar , but I do not know how to use it. I have saved the code as a .m file and use file->install to install it. However, when I call the package the error message below occurred. May you so kind to give me some reference of how the package to be created and install from scratch. I really want to write some useful package by myself.

Needs["ExploreGraphics`"] 

Needs::nocont: Context ExploreGraphics` was not created when Needs was evaluated.
$\endgroup$
  • $\begingroup$ Check the variable $Path. Is the package file in one of the directories listed? $\endgroup$ – mikado Jun 4 '17 at 19:31
  • $\begingroup$ Yes, the package file is in the folder. $\endgroup$ – Rikeijin Jun 5 '17 at 11:29
  • $\begingroup$ Kuba♦ Thank you. I saved the code by István Zachar in a m.file with name ExploreGraphics.m and use ExploreGraphics as the name of package. I am not sure whether it is the right way to use the code. $\endgroup$ – Rikeijin Jun 5 '17 at 17:03
  • $\begingroup$ @Kuba Thans for reminding me the cross-post this in Wolfram community. I had write to the moderation team for apology and will make sure the infomration will always be added next time. $\endgroup$ – Rikeijin Jun 5 '17 at 19:25
2
$\begingroup$

Notice the content of the message is only about missing context, which is usually introduced by BeginPackage["ExploreGraphics`"]. Your functions should already be loaded.

If your package is on $Path, and it seems it is, otherwise you'd get additional Get::noopen: Cannot open ExploreGraphics`. message, you are almost there.

If you want it to work well with Needs you need to add mentioned BeginPackage and friends. See Creating Mathematica packages, shortly you should write something like:

BeginPackage["ExploreGraphics`"]

  GetPlotRange::usage = ...
  GraphicsButton::usage = ...
  ...

Begin["`Private`"]
   (*implementation*)
End[]
EndPackage[]

Further reading:

How to install packages?

$\endgroup$
  • $\begingroup$ Thank @Kuba♦ very much. I finally got why the funtion in the package are loaded. I use an .nb file to test the code and save it as .m file. Now I copy the code into a new .wl file ( created by file->new->package(.wl) ) and save it as .wl file. Then I install the .wl file the same way with file->install. Fortunately all function work well now. I am wondering whether there is a way to develop package diractly from .nb file. community.wolfram.com/groups/-/m/t/297046 give a hint that one can set AutoGeneratedPackage ->Automatic to achive it, but I had hard time to find the option. $\endgroup$ – Rikeijin Jun 5 '17 at 19:07

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.