Hello Dear Community:
I want to ask something about a problem with Mathematica 9. My Wolfram Mathematica 9, can not read some package, like name_package.m. I'm working inside where I can find name_package.m . Now, some one can tell me what is the problem about this.
Really, I changed again the Mathematica version, and I can not solve this problem. In another PC and laptop I run this package very well. But, I can not find the answer for my problem in my laptop (a Ultrabook ASUS) I appreciate your time and any comment.
Let me outline a procedure, which I think would save a lot of people a lot of trouble.
First, instead of using the term "package" let's use the term "application". A package may always be considered to be part of an application but an application does not necessarily have to include a package. An application might be any group of folders and files associated with some subject that you want to keep together.
WRI has provided a standard place to put applications and that is in the $UserBaseDirectory/Applications folder. You can find the UserBaseDirectory by evaluating in a notebook:
(My experience is that many people I communicate with will put their packages anywhere but there. They always have some reason but THAT IS THE BEST PLACE TO PUT A PACKAGE.) The reason that this is the best place is that Mathematica automatically looks there for not only packages but also palettes and style sheets, which will automatically appear in your menus. It will also look there for an init.m file that you might want to associate with that application. If you someday add documentation Mathematica will also find it. Secondly, it is part of your own personal files and will persist independent of Mathematica updates. Another advantage is that the application packages can be loaded in a uniform manner from any notebook in any location. If you want to make links to other notebooks associated with the application you know exactly where to look for them. You never have to get involved in setting directories. If you want to send the entire application to someone else you can just zip it up, send it to her and she only has to unzip it into her $UserBaseDirectory/Application folder. Those are all significant advantages. Even if you are starting out with a modest application, say with just a package, that is still the best place because you can easily expand it later into a more elaborate application.
So your file structure might look something like the following (where I am showing how various optional elements might be included):
ProjectX/ (* top folder for the application *)
Documentation (* any documentation you might later add via Workbench *)
Palettes/ any palettes
StyleSheets/ any style sheets
MyTutorials/ perfected notebooks associated with ProjectX
SallysNotebooks/ notebooks done by an associate.
But you might start out with just the top folder, the package and maybe a working folder for notebooks associated with the project.
The BeginPackage statements for your packages would look like:
Notice that the path from the Application folder is included in the package name here. ProjectX is part of the Context. Then a user could, from anywhere, load one of the packages with, say:
But a much better method is to write an init.m file that looks like this:
Then WRI has implemented a neat shortcut such that the entire application can be loaded with:
When Mathematica sees only a top level folder in the Get statement it automatically looks for the init.m file in the application and evaluates it.
So when you think package, think application instead and, if you get off on the right foot, things will go much smoother from that point on.
I wish that I could help more. I hope this gets resolved.
Thank you Mr. D. Reiss, You are very kindly for your time and atenttion! I will tray to contact directly then. Regards.
Unfortunately these are details that I do not have suggestions for. I would suggest that you contact Wolfram Customer Support (unless someone here has additional suggestions for help):
Thank you so much for your comment.
I wrote this contribute something interesting how my new line of command:
Now I'm running Mathematica 10.0.1 and using " Ubuntu 12.04.4 LTS " OS.
My problem persist. my NamePackage.m don't run. But, in other PC is running this package, using Mathematica 9 or 10.
Really I don't know what it is the origin of the problem.
I was thinking about the installation of Mathematica was wrong..may be (a bad instalation for example). Then, I take off the different archive from Mathematica: given by: /usr/local/Wolfram/Mathematica/ ; ~/.Mathematica/ ; /usr/share/Mathematica/ ; /usr/local/Wolfram/ (/usr/local/Wolfram/Mathematica/) ; and the archive that found in /usr/local/bin/ It's name are: math mathematica Mathematica MathematicaScript MathKernel mcc wolfram WolframKernel WolframScript .-
But, now I'm running "Mathematica" where I have my NamePackage.m and this package don't is up!, Mathematica don't show the letter that should be appear, If it's running ok.
I don't know what it is the problem in my machine(may be) or in some tool that Mathematica loss(why not?).
Other situation that I did, is, I open my package using Mathematica, but when put Run Package in ON, don't run again!
again, I select all and run(using Ctrl+A and then Shift+Enter) and the package is "running" with many errors that don't should show, because I run in OTHER PC that read very well which showed nathing error.
Now I feel uneasy for my problem..and I can not find the final and correct answer to my problem. Please I appreciate your time and atention, But what do you think about this??
Thanks Bruce! I forgot about that.
fyi, The Community editor interprets underscore characters and dollar sign characters as formatting commands if they are not escaped with a backslash (\) or in backquotes (``). I patched your posts; I hope they get across your meanings better now.
When Mathematica tries to load a package with either Get (which you are using with the shorthand <<) or Needs Mathematica first looks for the packages in the correent working directory (which in your first example you have set to the directory where your package is located) and if the package is not there then it looks in the directories that it knows about. These directories are the ones contained in the $Path parameter.
So if your package's directory is not contained amongst the directories in $Path then Mathematica will not find it. You can add that directory to the $Path parameter for the current Mathematica session using
where directory is the full path to the directory where your package is located.
Thank you for your comments Mr. D. Reiss.
The form that I'm reading the special package is using the next sentence:
My NamePackage.m is located in a folder, it's name is "The_Program".
If my Mathematica can not read NamePackage.m like I explained before, I change the "Directory" and I force that Wolfram is working in "The_Program" folder. Now, run the package again, but, I have a problem again, can not read the package correctly!.
I appreciate your time and attention.
A couple of quick comments or suggestions.
The first is, depending upon how you are trying to load your package, you should determine whether Mathematica knows where to look for your package. How are you trying to load it and where is that package located on your system?
Second suggestion is that you do not use _ characters in the name of your package. This potential he can cause problems in your code because the _ character has a meaning in Mathematica to indicate a pattern. Problems might not happen, but it is best to avoid their potentiality.