Message Boards Message Boards

0
|
12128 Views
|
10 Replies
|
4 Total Likes
View groups...
Share
Share this post:

Can not read a package name_package.m in my laptop using Mathematica 9.

Posted 10 years ago

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.

Regards,

PA

POSTED BY: pedro allendes
10 Replies

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:

$UserBaseDirectory

(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):

$UserBaseDirectory/Applications/
     ProjectX/ (* top folder for the application *)
     Documentation (* any documentation you might later add via Workbench  *)
     FrontEnd/
           Palettes/ any palettes
           StyleSheets/ any style sheets
     Kernel/ init.m
     package1.m
     package2.m
     MyTutorials/ perfected notebooks associated with ProjectX 
     DevelopmentNotebooks/ ...
     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:

BeginPackage["ProjectX`package1`",{...}]

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:

<<ProjectX`package1`

But a much better method is to write an init.m file that looks like this:

<<ProjectX`package1`
<<ProjectX`package2`

Then WRI has implemented a neat shortcut such that the entire application can be loaded with:

<<ProjectX`

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.

POSTED BY: David Reiss
Posted 10 years ago

Thank you Mr. D. Reiss, You are very kindly for your time and atenttion! I will tray to contact directly then. Regards.

POSTED BY: pedro allendes

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):

http://www.wolfram.com/support/contact/

POSTED BY: David Reiss
Posted 10 years ago

Thank you so much for your comment. I wrote this contribute something interesting how my new line of command: AppendTo[$Path, "/home/.../The_Program"] 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?? Regards, PA

POSTED BY: pedro allendes

Thanks Bruce! I forgot about that.

POSTED BY: David Reiss

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.

POSTED BY: Bruce Miller

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

AppendTo[$Path, directory]

where directory is the full path to the directory where your package is located.

POSTED BY: David Reiss
Posted 10 years ago

Thank you for your comments Mr. D. Reiss. The form that I'm reading the special package is using the next sentence:

<<NamePackage.m 

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.

POSTED BY: pedro allendes

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.

POSTED BY: David Reiss
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