Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wolframscript: command not found #3

Closed
LEMettler opened this issue Mar 17, 2024 · 9 comments
Closed

wolframscript: command not found #3

LEMettler opened this issue Mar 17, 2024 · 9 comments

Comments

@LEMettler
Copy link

My local wolframscript is not found, however works in the terminal.

The installation went without a problem, but plots produce this type of error:

Error: Command failed: wolframscript --code "ExportString[Rasterize[Show[Plot[x,{x,0,10}],Axes->True,AxesLabel->{x,y},Frame->False,Boxed->True],ImageSize->{250,Automatic},Background->None,AspectRatio->Automatic], {\"Base64\", \"PNG\"}]" /bin/sh: line 1: wolframscript: command not found

which wolframscript returns /usr/bin/wolframscript. However, entering this path in the settings also does not work:

Error: Command failed: "/usr/bin/wolframscript" --code "ExportString[Rasterize[Show[Plot[x,{x,0,10}],Axes->True,AxesLabel->{x,y},Frame->False,Boxed->True],ImageSize->{250,Automatic},Background->None,AspectRatio->Automatic], {\"Base64\", \"PNG\"}]" /bin/sh: line 1: /usr/bin/wolframscript: No such file or directory

OS: Linux Mint 21.2
Obsidian: v1.5.8

Other things i tested:

  • executing the command in terminal -> runs without issue
  • tested installation via community plugin browser and via clone from git

I tried to have a look at it myself but i have no experience with javascript and did not get very far :)

@MarcosNicolau
Copy link
Owner

Hi @LEMettler,

I think I know what is going wrong. When setting a custom path, the quotes are being added to the path. when they should not. Instead of being /usr/bin/wolframscript is doing "/usr/bin/wolframscript".

Since this should be an easy fix I'll push the changes asap and I'll let you know!

For the time being, I guess you could just copy the generated code and run it yourself.

@MarcosNicolau
Copy link
Owner

MarcosNicolau commented Mar 18, 2024

Ok, I've just tested and it is clearly not that, could you try to run this command /bin/sh -c 'wolframscript' on your terminal. Also, maybe you could try with /bin/wolframscript and see if that works.

@LEMettler
Copy link
Author

Hi @MarcosNicolau,

thank you for your quick reply.
Both /bin/sh -c 'wolframscript' and /bin/wolframscript both launch wolframscript in terminal. But both produce the same type of error with the plugin.

@MarcosNicolau
Copy link
Owner

It probably has to do with the PATH env var not being loaded. Since you told you were able to use the plugin via git clone, would you mind replacing the getBase64Plot function located in this file in your machine for:

export const getBase64Plot = async (
	plot: string,
	{ useCloud, wolframScriptPath }: GetBase64PlotSettings
): Promise<{ error: string; base64: string }> => {
	try {
		const { stdout, stderr } = await promisify(exec)(
			`${
				wolframScriptPath
					? '"' + wolframScriptPath + '"'
					: "wolframscript"
			} ${
				useCloud ? "--cloud" : ""
			}  --code "ExportString[${plot}, {\\"Base64\\", \\"PNG\\"}]"`,
			{
				// Here we make sure that the path gets loaded
				env: { PATH: process.env.PATH },
			}
		);
		if (stderr) return { error: stderr, base64: "" };
		// If it is not a valid image, it means there was a mistake in the wolfram syntax
		// So we return the base64 to debug the err, since it tells you whats wrong.
		if (!isValidBase64(stdout)) return { error: stdout, base64: "" };
		return { error: "", base64: stdout };
	} catch (err) {
		return { error: err, base64: "" };
	}
};

After that, you'd have to run npm run build and before that npm install. If that works for you, I'll push these changes asap.

Sorry that I am making you do this, but I have no way to test it on my end since it works on my machine 😁.

@LEMettler
Copy link
Author

No worries. I appreciate your help :)

I did as you instructed. Same error.
npm run build returned

> obsidian-sample-plugin@1.0.0 build
> tsc -noEmit -skipLibCheck && node esbuild.config.mjs production

I never worked with js/ts. Is the second line is the expected output?

@MarcosNicolau
Copy link
Owner

Yes, the output is ok. If it's still not working, it is because exec creates a new process and a new shell, but for some reason, it is not creating the PATH env you have on your config files. It probably has to do with electron doing weird stuff or your Obsidian installation (did you install it via flatpak? If so it won't invoke your app PATH for security reasons I believe).

Could you try this version please:

export const getBase64Plot = async (
	plot: string,
	{ useCloud, wolframScriptPath }: GetBase64PlotSettings
): Promise<{ error: string; base64: string }> => {
	try {
		console.log(process.env.PATH);
		const { stdout, stderr } = await promisify(exec)(
			`"wolframscript" ${
				useCloud ? "--cloud" : ""
			}  --code "ExportString[${plot}, {\\"Base64\\", \\"PNG\\"}]"`,
			{ env: { PATH: "/usr/bin/" } }
		);
		if (stderr) return { error: stderr, base64: "" };
		// If it is not a valid image, it means there was a mistake in the wolfram syntax
		// So we return the base64 to debug the err, since it tells you whats wrong.
		if (!isValidBase64(stdout)) return { error: stdout, base64: "" };
		return { error: "", base64: stdout };
	} catch (err) {
		return { error: err, base64: "" };
	}
};

As you probably noticed, there is a console log that prints the PATH env, could you tell me the output, please? If it is empty, that is why the exec does not have the PATH defined, coz it inherits the current process env variables.

PD: sorry for the delayed response! 😁

@LEMettler
Copy link
Author

I got it to work!

Solution: switching from flatpak to a .deb obsidian installation.

Before, I tested the console output of the PATH env. It was not empty, but i can confirm that it did not match my defined $PATH. Only think is that I forgot to copy it before deleting obsidian. 😆

Anyway, thank you very much for your help. Have a great day!

@MarcosNicolau
Copy link
Owner

Excellent!!! Glad you could solve the issue! I'll make sure to make it work on flatpak for the next release!! Thank you for opening the issue and helping with the bugs!! 😃

@MarcosNicolau
Copy link
Owner

#4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants