Skip to main content

cdf format - Problem with PlayerPro recognizing a proprietary package


This question follows on from my earlier question Can Wolfram's Player Pro Use Proprietary Packages.


That question appeared to have established that, yes, PlayerPro can use proprietary packages.


Hmmm....? I've got two problems (to start) one of which I'll describe here and the second in a separate question.


I purchased a PlayerPro license ($200 USD) for OS X to evaluate what it really can and does do. I installed it on a machine that had no other Mathematica installation. I tested its installation and functionality by running a couple of simple completely self-contained CDFs on it without any trouble.



I then transferred copies of three files to the PlayerPro equipped machine and located them in the following directories:



/Users/username/Library/MathematicaPlayerPro/Applications.myPackage.m /Users/username/Library/MathematicaPlayerPro/Applications.myNotebook.nb /Users/username/Library/MathematicaPlayerPro/Kernel.init.m



myPackage.m holds proprietary functions.


myNotebook.nb provides a Grid of InputFields and a Button to execute code contained in myPackage.m. All of its code resides in an initialization cell (but that starts to get into my next question).


init.m contains the following code:


(** User Mathematica initialization file **)
Get["myPackage`"]


The comparable deployment on my machine running Mathematica works perfectly.


On the PlayerPro machine, not so much.


I have shut down and restarted PlayerPro and the problem persists. I have rebooted the machine, launched PlayerPro and the problem persists.


Upon opening myNotebook.nb, I can see plainly that none of the function names from myPackage.m have run. They all remain blue. The package has not loaded automatically. As the notebook depends almost entirely on the code in the package nothing in it executes.


Neither does it appear that the initialization cell runs.


I then went into:


PlayerPro >>> Preferences >>> System >>> Edit Trusted Directories

and specifically added the:




.../MathematicaPlayerPro/Applications


.../MathematicaPlayerPro/Kernel



directories, restarted, rebooted, still nothing.


Does anyone have any ideas of how to get this working?


I've actually phoned Premier Support about this. The did not have a ready answer. If I hear anything useful from them I'll post it.


Update 1: I have used Encode to encode the package in question.


I have made the assumption that the init.m package would not require encoding. Perhaps that assumption needs reexamination.


Update 2: Encoding init.m has no affect.


Update 3: I created a notebook to test the following two lines of code for loading the package:



Get["myPackage`"]

$Failed

Get["Users/username/Library/MathematicaPlayerPro/Applications/myPackage`"]

Get::noopen : Cannot open Users/username/Library/MathematicaPlayerPro/Applications/myPackage`
$Failed

I have also tried:



Needs["myPackage`"]
Needs::nocont : Context myPackage` was not created when Needs was evaluated.

$Failed

Needs["myPackage,"Users/username/Library/MathematicaPlayerPro/Applications/myPackage`"]


Get::noopen : Cannot open Users/username/Library/MathematicaPlayerPro/Applications/myPackage`
Needs::nocont : Context myPackage` was not created when Needs was evaluated.
$Failed


Update 4: Premier Support suggested some of the same things that Albert does in his answer below (still working through all of Albert's suggestions). They did discover something peculiar with PlayerPro:



I know that the main difference between this procedure and what you may have been doing with your package is that you have your Needs/Get statement inside of the PlayerPro init.m file. I did try doing the same, and found that it did not load the package. I will check on this issue with our developers to get more information.



Update 5: Sorry for all these updates, but this now appears like a bug in (at least) PlayerPro 9.0.1.0. The init.m file whether encoded or not simply doesn't do its job, at least not in anyway similar to how it works in full blown Mathematica.


I have successfully found a workaround (but not a happy one), with the generous assistance of both answers made to this question. Still, having Wolfram provide either a fix or at least a readily available explanation of why it differs in PlayerPro from Mathematica would save a lot time and frustration.



Answer



The general requirements for a package file to be loaded in PlayerPro are listed in this answer which I think you already know about.


My suspection is that your problems are in some detail in your package that might or might not have to do with the fact you are running this in PlayerPro. As usual you should start with something very simple and then add things step by step until your real problem works or you can exactly tell which step led to a problem, otherwise there is just too many small details that can go wrong. I see some potential problems with your calls to Get and Needs, especially you can't mix full path names and context names as in


Get["Users/username/Library/MathematicaPlayerPro/Applications/myPackage`"]


But the return value of


Get["myPackage`"]

and the message of


Needs["myPackage`"]

indicate that you rather have a problem in the content of your package file, maybe some piece of code that doesn't work on PlayerPro as expected.


Here is my suggestion for finding out what actually goes wrong:




start with something very simple. Create a text file with this content:


BeginPackage["test`"]
testfun::usage="testfun does nothing";
EndPackage[];

naming it, e.g. "C:\\Users\\albert.retey\\Desktop\\test.txt" (of course adopt the path name to something valid on your computer). Then evaluate the following in Mathematica:


Encode[
"C:\\Users\\albert.retey\\Desktop\\test.txt",
"C:\\Users\\albert.retey\\Desktop\\test.m"]


This should create an encoded package, check that it exists and contains something like:


(*!1N!*)mcm
jX#r/N5>m^c0Q )K,<@X>.5bPbTY_m,n@1#W5cPbTYS)Q6i.XXJ.p1
2!rF:tH|qLWBuA`Ua'

Now create a new notebook with the following content:


Get["C:\\Users\\albert.retey\\Desktop\\test.m"]

?testfun


Evaluating this should show the usage message of testfun as defined in the package. Once that works in Mathematica, open the same notebook with PlayerPro and see whether that works there, too. If you are running PlayerPro on another machine than Mathematica, then don't forget to change the path to the correct value on the target machine before saving the the notebook.



For Needs to work, the package file must create the correct Context, that means the name of the package file and the context given in BeginPackage need to agree, otherwise you'll get the Needs::nocont message. Here is how you can test whether that works for your encoded package file: Create a notebook with this content and save it in the same directory as your encoded package file:


Quit[]
AppendTo[$Path, NotebookDirectory[]];
Needs["test`"]

Evaluating this should now work both in Mathematica and PlayerPro.



For the final deployment, you usually want to put the package file in one of those directories that Mathematica or PlayerPro search for packages instead of tweaking $Path. Basically you can copy your file to any directory listed in $Path, but by convention you should either use the Applications subdirectory of either $UserAddOnsDirectory (for installation for single user) or $AddOnsDirectory (for system wide installation).



To do so, copy the encoded package file into the "Applications" subdirectory of e.g.$UserAddOnsDirectory directory. Doing so, we can load it without giving the full path name of the package file and just use the context name of the package in either Get or Needs. Make sure you use the exact outcome of what $UserAddOnsDirectory gives you evaluated in PlayerPro on the target machine. For me $UserAddOnsDirectory is: "C:\\Users\\albert.retey\\AppData\\Roaming\\MathematicaPlayerPro" and the path to the package file then needs to be: "C:\\Users\\albert.retey\\AppData\\Roaming\\MathematicaPlayerPro\\Applications\\test.m". To test this, create another notebook with the following content:


Quit[];
Get["test`"]
?testfun

And evaluate it in PlayerPro. Again, you should now see the given usage message. If this doesn't work, make sure the file can be found, e.g. with:


FileNames["test.m", $Path]

Again, you need to create a notebook with this content in Mathematica, open that with PlayerPro and evaluate it in PlayerPro. This will also show whether there are more than the expected instances of the test.m file in your $Path, loading a different package than what you think is also a very common source of errors.




If you have the above running, start with a new file with the name of your own package. Start again with just the trivial content but the correct filename and context. Once that works, add the content. If the loading then doesn't work, restart with an empty package file and add the definitions for your function one by one and check whether each works. That way you should find the insulting code. If you don't see why that piece of code doesn't work in PlayerPro, come back and add that to your question or create a new one...


Final note: I tested this with PlayerPro 8.0.4, I can hardly imagine that these things have changed for version 9 of PlayerPro that came out a few days ago, but if the above doesn't work and you are actually using version 9 of PlayerPro, you might want to add that information.


Comments

Popular posts from this blog

plotting - Filling between two spheres in SphericalPlot3D

Manipulate[ SphericalPlot3D[{1, 2 - n}, {θ, 0, Pi}, {ϕ, 0, 1.5 Pi}, Mesh -> None, PlotPoints -> 15, PlotRange -> {-2.2, 2.2}], {n, 0, 1}] I cant' seem to be able to make a filling between two spheres. I've already tried the obvious Filling -> {1 -> {2}} but Mathematica doesn't seem to like that option. Is there any easy way around this or ... Answer There is no built-in filling in SphericalPlot3D . One option is to use ParametricPlot3D to draw the surfaces between the two shells: Manipulate[ Show[SphericalPlot3D[{1, 2 - n}, {θ, 0, Pi}, {ϕ, 0, 1.5 Pi}, PlotPoints -> 15, PlotRange -> {-2.2, 2.2}], ParametricPlot3D[{ r {Sin[t] Cos[1.5 Pi], Sin[t] Sin[1.5 Pi], Cos[t]}, r {Sin[t] Cos[0 Pi], Sin[t] Sin[0 Pi], Cos[t]}}, {r, 1, 2 - n}, {t, 0, Pi}, PlotStyle -> Yellow, Mesh -> {2, 15}]], {n, 0, 1}]

plotting - Plot 4D data with color as 4th dimension

I have a list of 4D data (x position, y position, amplitude, wavelength). I want to plot x, y, and amplitude on a 3D plot and have the color of the points correspond to the wavelength. I have seen many examples using functions to define color but my wavelength cannot be expressed by an analytic function. Is there a simple way to do this? Answer Here a another possible way to visualize 4D data: data = Flatten[Table[{x, y, x^2 + y^2, Sin[x - y]}, {x, -Pi, Pi,Pi/10}, {y,-Pi,Pi, Pi/10}], 1]; You can use the function Point along with VertexColors . Now the points are places using the first three elements and the color is determined by the fourth. In this case I used Hue, but you can use whatever you prefer. Graphics3D[ Point[data[[All, 1 ;; 3]], VertexColors -> Hue /@ data[[All, 4]]], Axes -> True, BoxRatios -> {1, 1, 1/GoldenRatio}]

plotting - Mathematica: 3D plot based on combined 2D graphs

I have several sigmoidal fits to 3 different datasets, with mean fit predictions plus the 95% confidence limits (not symmetrical around the mean) and the actual data. I would now like to show these different 2D plots projected in 3D as in but then using proper perspective. In the link here they give some solutions to combine the plots using isometric perspective, but I would like to use proper 3 point perspective. Any thoughts? Also any way to show the mean points per time point for each series plus or minus the standard error on the mean would be cool too, either using points+vertical bars, or using spheres plus tubes. Below are some test data and the fit function I am using. Note that I am working on a logit(proportion) scale and that the final vertical scale is Log10(percentage). (* some test data *) data = Table[Null, {i, 4}]; data[[1]] = {{1, -5.8}, {2, -5.4}, {3, -0.8}, {4, -0.2}, {5, 4.6}, {1, -6.4}, {2, -5.6}, {3, -0.7}, {4, 0.04}, {5, 1.0}, {1, -6.8}, {2, -4.7}, {3, -1.