Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Possible Duplicate:
Automatically load packages at startup

I have made two packages "Package1" and "Package2". Package2 calls Package1. it works fine.But everytime I am reopening Mathematica,I have to run both packages and then load them by Needs. I dont want to load packages again and again.

share|improve this question

marked as duplicate by Szabolcs, Yves Klett, Mr.Wizard Jul 24 '12 at 9:53

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
If Package2 relies on Package1, I'd suggest loading it using the second argument of BeginPackage in Package2. This ensures that you only need to load Package2 manually before using it (and not Package1 as well). –  Szabolcs Jul 24 '12 at 9:52
    
@Szabolcs What you described is a public import which is only recommended in cases when the functionality of the second package (Package1) needs to be available for the users of Package2. In all other cases, a private import through calling Needs["Package1`"] in the Private` section of Package2 is the better method, for the sake of encapsulation and information hiding. –  Leonid Shifrin Jul 24 '12 at 11:42
    
@LeonidShifrin It does not in fact need to be in the Private` section for the import to be private, as it is the EndPackage of Package2 that removed the Package1 context from the context path. –  Szabolcs Jul 24 '12 at 11:53
    
@Szabolcs What I described is a standard practice (see R.Maeder's PIM for example). Your suggestion will work technically, but is a rather non-standard way of importing. If the package Package1 you are importing does not have BeginPackage-EndPackage and Begin-End itself (which is a case sometimes), then you will create all its symbols in the public part of Package2 with such an import, and therefore, leak its details to the user. It is not a frequent case, but from the "black box" point of view importing into a Private` subsection adds extra protection. –  Leonid Shifrin Jul 24 '12 at 12:11
    
It was not a suggestion, of course, just a clarification. It's easy to misunderstand your comment and assume that it's the Begin["`Private`"] that makes the imported package private. –  Szabolcs Jul 24 '12 at 17:37

1 Answer 1

You can add the Needs lines to your kernel init.m file.

I would suggest changing the init.m file found in $UserBaseDirectory/Kernel.

share|improve this answer
    
I have seen this <mathematica.stackexchange.com/questions/8221/…; but unable to get how it can be useful. I am able to get that .bak file in Mathematica kernel folder. –  Jennifer Jul 24 '12 at 12:02

Not the answer you're looking for? Browse other questions tagged or ask your own question.