0
$\begingroup$

This question already has an answer here:

I have two packages that I would like to append to $Path. I have looked at this link for help but after I quit Mathematica, I have to repeat the process again.

Where can I permanently modify $Path?

Is there a way to permanently modify $Path so that I can always access my extra packages?

EDIT: Please this is not a duplicate question or I won't be asking. I tried all the suggestions in that link but they didn't provide a permanent solution. I can't load my packages after I quit Mathematica. I have to go through the whole process again whenever I restart Mathematica.

My init.m file looks like this:

SetOptions[$FrontEnd, 
NotebookBrowseDirectory->"/Users/name/Library/Mathematica/mypackages/poma-2.0",
AutoOpenPalettes->{},
Default2DTool->"Select",
Default3DTool->"RotateView",
PrivateFrontEndOptions->{"LicensesAgreed"->{"11.1"}},
VersionsLaunched->{"11.1.1", "11.2.0"},
NotebooksMenu->{"2017_ML" -> {
    FrontEnd`FileName[{$RootDirectory, "Users", "name", "Desktop", 
      "2017", "NMR_Workshop_2017"}, "2017_ML.nb",
     CharacterEncoding -> "UTF-8"], True, False, True}, "2017_ML" -> {
    FrontEnd`FileName[{$RootDirectory, "Users", "name", "Desktop",
      "2017", "NMR_Workshop_2017", "Malcom_Levitt",
      "SpinDynamica_Exercises"}, "2017_ML.nb", CharacterEncoding ->
     "UTF-8"], True, False, True}, "A_Problem set I" -> {
    FrontEnd`FileName[{$RootDirectory, "Users", "name", "Desktop", 
      "2017", "NMR_Workshop_2017"},
     "A_Problem set I.nb", CharacterEncoding -> "UTF-8"], True,
    False, True}, "MHL-exercises.nb" -> {
    FrontEnd`FileName[{$RootDirectory, "Users", "name", "Desktop", 
      "2017", "NMR_Workshop_2017", "Malcom_Levitt",
      "Exercises_ML_2017"}, "MHL-exercises.nb", CharacterEncoding ->
     "UTF-8"], True, False, True}, "Levitt_2017" -> {
    FrontEnd`FileName[{$RootDirectory, "Users", "name", "Desktop", 
      "2017", "NMR_Workshop_2017"}, "Levitt_2017.nb",
     CharacterEncoding -> "UTF-8"], True, False, True}, "Poma2.m" -> {
    FrontEnd`FileName[{$RootDirectory, "Users", "name", "Library", 
      "Mathematica", "programs", "poma-2.0"}, "Poma2.m", CharacterEncoding -> 
     "UTF-8"], True, False, True}, "Poma2.wl" -> {
    FrontEnd`FileName[{$RootDirectory, "Users", "name", "Library", 
      "Mathematica", "Applications"}, "Poma2.wl", CharacterEncoding -> 
     "UTF-8"], True, False, True}, "ini.nb" -> {
    FrontEnd`FileName[{$RootDirectory, "Users", "name", "Library", 
      "Mathematica", "mypackages", "SDv3.0.2.2", "SpinDynamica"}, "ini.nb", 
     CharacterEncoding -> "UTF-8"], True, False, True}, 
  "Untitled-5" -> {"", True, False, True}, "init" -> {
    FrontEnd`FileName[{$RootDirectory, "Users", "name", "Library", 
      "Mathematica", "mypackages", "SDv3.0.2.2", "SpinDynamica"}, "init.nb", 
     CharacterEncoding -> "UTF-8"], True, False, True}, "init" -> {
    FrontEnd`FileName[{$RootDirectory, "Users", "name", "Library", 
      "Mathematica", "mypackages", "poma-2.0"}, "init.nb",
     CharacterEncoding -> "UTF-8"], True, False, True}, "init" -> {
    FrontEnd`FileName[{$RootDirectory, "Users", "name", "Library", 
      "Mathematica", "mypackages", "poma-2.0"}, "init.nb", CharacterEncoding -> 
     "UTF-8"], True, False, True}, "HMQC.nb" -> {
    FrontEnd`FileName[{$RootDirectory, "Users", "name", "Downloads"}, 
     "HMQC.nb", CharacterEncoding -> "UTF-8"], True, False, True}, 
  "HMQC" -> {
    FrontEnd`FileName[{$RootDirectory, "Users", "name", "Library", 
      "Mathematica", "mypackages", "poma-2.0"}, "HMQC.nb", CharacterEncoding -> 
     "UTF-8"], True, False, True}, "hcaco_3d" -> {
    FrontEnd`FileName[{$RootDirectory, "Users", "name", "Library", 
      "Mathematica", "mypackages", "poma-2.0"}, "hcaco_3d.nb", 
     CharacterEncoding -> "UTF-8"], True, False, True}},
PalettesMenuSettings->{
 "BasicMathAssistant.nb" -> {
   TaggingRules -> {
     "ShowCalculator" -> True, "ShowBasicCommands" -> True, 
      "ShowBasicTypesetting" -> False, "ShowHelpLinks" -> False, 
      "PaletteMode" -> 1, "OptionsInsertionMode" -> 1}}},
FindSettings->{"FindBoxes":>"aroma",
"FindString"->"aroma",
"SearchType"->LiteralSearch},
StyleNameDialogSettings->{"Style"->"Title"},
HelpViewerSettings->{"WindowMargins"->{{290, Automatic}, {Automatic, 0}},
"WindowSize"->{860, 796}},
PrivateFrontEndOptions->{"DialogSettings"->{
 "Login" -> {"RememberMe" -> True}, 
  "WelcomeScreen" -> {"ShowRecentFilesContextMenu" -> False}, 
  "CustomStyles" -> {WindowMargins -> Automatic}, 
  "Install" -> {"Type" -> "Package"}},
"InterfaceSettings"->{
 "PredictiveInterface" -> {"ShowMinimized" -> False, "FirstUse" -> False}},
"WolframAlphaSettings"->{
 "Autoload" -> True, "BaseURL" -> "Automatic", "AppID" -> Automatic, 
  "SendMathematicaSessionInfo" -> Automatic, "Reinterpret" -> True, 
  "Interactive" -> True, "Language" -> Automatic, "Recalculate" -> True, 
  "MathematicaFormsFormatType" -> "MostlyInputForm", "Asynchronous" -> True}}
]

The init.nb file which is saved in the sane folder as the package looks like this:

 $Path = Append[$Path, 
  "/Users/name/Library/Mathematica/mypackages/poma-2.0"]

{"/Users/name/Library/Mathematica/DocumentationIndices", \
"/Applications/Mathematica v \
11.2.0.0.app/Contents/SystemFiles/Links", \
"/Users/name/Library/Mathematica/Kernel", \
"/Users/name/Library/Mathematica/Autoload", \
"/Users/name/Library/Mathematica/Applications", \
"/Library/Mathematica/Kernel", "/Library/Mathematica/Autoload", \
"/Library/Mathematica/Applications", ".", "/Users/name", \
"/Applications/Mathematica v 11.2.0.0.app/Contents/AddOns/Packages", \
"/Applications/Mathematica v \
11.2.0.0.app/Contents/SystemFiles/Autoload", \
"/Applications/Mathematica v 11.2.0.0.app/Contents/AddOns/Autoload", \
"/Applications/Mathematica v \
11.2.0.0.app/Contents/AddOns/Applications", \
"/Applications/Mathematica v \
11.2.0.0.app/Contents/AddOns/ExtraPackages", \
"/Applications/Mathematica v \
11.2.0.0.app/Contents/SystemFiles/Kernel/Packages", \
"/Applications/Mathematica v \
11.2.0.0.app/Contents/Documentation/English/System", \
"/Applications/Mathematica v \
11.2.0.0.app/Contents/SystemFiles/Data/ICC", \
"/Users/name/Library/Mathematica/mypackages/poma-2.0", \
"/Users/name/Library/Mathematica/mypackages/poma-2.0"}

If I quit Mathematica and re-open a notebook, path looks like this:

$Path

{"/Users/name/Library/Mathematica/DocumentationIndices", \
"/Applications/Mathematica v \
11.2.0.0.app/Contents/SystemFiles/Links", \
"/Users/name/Library/Mathematica/Kernel", \
"/Users/name/Library/Mathematica/Autoload", \
"/Users/name/Library/Mathematica/Applications", \
"/Library/Mathematica/Kernel", "/Library/Mathematica/Autoload", \
"/Library/Mathematica/Applications", ".", "/Users/name", \
"/Applications/Mathematica v 11.2.0.0.app/Contents/AddOns/Packages", \
"/Applications/Mathematica v \
11.2.0.0.app/Contents/SystemFiles/Autoload", \
"/Applications/Mathematica v 11.2.0.0.app/Contents/AddOns/Autoload", \
"/Applications/Mathematica v \
11.2.0.0.app/Contents/AddOns/Applications", \
"/Applications/Mathematica v \
11.2.0.0.app/Contents/AddOns/ExtraPackages", \
"/Applications/Mathematica v \
11.2.0.0.app/Contents/SystemFiles/Kernel/Packages", \
"/Applications/Mathematica v \
11.2.0.0.app/Contents/Documentation/English/System", \
"/Applications/Mathematica v \
11.2.0.0.app/Contents/SystemFiles/Data/ICC"}

And I can't load the package anymore

<<Poma2.m
Get::noopen: Cannot open Poma2.m.
$Failed
$\endgroup$

marked as duplicate by Henrik Schumacher, Szabolcs, LCarvalho, m_goldberg, Kuba Feb 9 '18 at 9:29

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.

  • 1
    $\begingroup$ Try to edit FileNameJoin[{$UserBaseDirectory, "Kernel", "init.m"}] as Szabolcs proposed. This should take effect after the next kernel restart. Why doesn't it work for you? $\endgroup$ – Henrik Schumacher Feb 8 '18 at 11:24
  • $\begingroup$ Thanks for your comment! I did that already. I tried all the suggestions on that page but it didn't permanently change the $Path. $\endgroup$ – cave Feb 8 '18 at 11:31
  • 1
    $\begingroup$ What does the init.m file contain? $\endgroup$ – Kuba Feb 8 '18 at 11:34
  • 3
    $\begingroup$ This is the front end init.m, is it not? Kernel's should be almost empty. $\endgroup$ – Kuba Feb 8 '18 at 11:57
  • 1
    $\begingroup$ @cave there is some kind of misunderstading. I don't understand what init.nb is for. And for me a file behind FileNameJoin[{$UserBaseDirectory, "FrontEnd", "init.m"}] returns what you claim is in FileNameJoin[{$UserBaseDirectory, "Kernel", "init.m"}]. But again, try PutAppend[ Unevaluated@ AppendTo[$Path, "/Users/name/Library/Mathematica/mypackages/poma-2.0"], FileNameJoin[{$UserBaseDirectory, "Kernel", "init.m"}] ], quit the kernel and let me know if it works. $\endgroup$ – Kuba Feb 8 '18 at 17:37