Is it possible to load packages (.m) directly from the network (http, https) without installing it locally?

  • $\begingroup$ Do you mean load from the world wide web via ftp ? Or did you mean how to store a package in an html page and load it via the hypertext transport protocol ( http) ? $\endgroup$ Oct 29 '12 at 11:05
  • $\begingroup$ Could also be ftp. I would however prefer http to transfer .m file as it is and be loaded as a package. The goal is to have a package used by several users during a development when the package changes very frequently without using synchronization tools like Dropbox, wget or Mathematica URL tools. $\endgroup$
    – Boocko
    Oct 29 '12 at 11:16
  • $\begingroup$ Would your best approach be to store this in a git or mercurial repository and some sort of change tracking as is the normal practise for multi-person development projects? You could then have a few Mathematica functions to pull/push the package to your local repository. $\endgroup$ Oct 29 '12 at 11:25
  • $\begingroup$ Thank you for the comment. Yes I would like the users to pull the file from the depository but for some reasons I should not install additional tools to their system. So, only plain Mathematica functions. After being unlucky with Needs[], it now looks that simple Import["https://.../package.m"] loads the file and namespace just OK. Can anyone explain me the difference between the Needs[] and Import[] of .m files? $\endgroup$
    – Boocko
    Oct 29 '12 at 11:35
  • $\begingroup$ Glad you found a solution to your problem. Needs checks to see if the context you are requesting is already in $Packages and calls Get, i.e. has already been loaded. Import reads all types of files into Mathematica but will not perform the checks that Needs does in the case of package files. $\endgroup$ Oct 29 '12 at 11:47

When loading packages remotely in Mathematica (extension .m) one can use the Import function, which behaves just as Get. However, one must the manually check the need for loading packages (something that is usually dome with Needs).

It is possible to use Import also within the imported package.

In the examples below one loads package Test using Import["https://.../Test1.m"], which automatically loads Test2.m and imports both Test' and Test'Deeptest' namespaces and both funcions firstF and secondF.

File Test1.m, placed somewhere on the WWW server.

      firstF::usage = "firstF[] calls secondF[] and prepends word first"
      firstF[] := "first, " <> Test`DeepTest`secondF[]
    End[ ]
    EndPackage[ ]

File Test2.m, placed somewhere on the WWW server.

     secondF::usage = "secondF[] returns string second"
     secondF[] := "second"
    End[ ]
    EndPackage[ ]

Thanks to the image_doctor for providing the initial help.


For an enterprise deployment of a package we store our packages on a network file server and then add the following to the user's init.m file:


You can then use Needs and package documentation shows up in the help browser.

For development we have found it to be much easier to use Wolfram Workbench (we use the Eclipse plugin) to synchronize with a Git archive (over http or other protocols) and load the package into Mathematica. It has a big advantage of automatically clearing and reloading the package after you make changes.


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.