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

sys.argv is empty #31

Open
optozorax opened this issue May 21, 2020 · 4 comments
Open

sys.argv is empty #31

optozorax opened this issue May 21, 2020 · 4 comments

Comments

@optozorax
Copy link

optozorax commented May 21, 2020

I'm trying to run this code:

python! {
	import matplotlib.pyplot as plt

	x = [1, 2, 3]
	y = [2, 4, 1]

	plt.plot(x, y)

	plt.xlabel("x - axis")
	plt.ylabel("y - axis")

	plt.title("Line graph!")

	plt.savefig("foo.png")
}

But get only this error:

thread 'main' panicked at 'python!{...} failed to execute'

But this code works as single python file.

It will be fine to get errors from python interpreter why code is failed to execute.

Also, is import supported?

@optozorax
Copy link
Author

optozorax commented May 21, 2020

Hmmm, sorry for being husty. I'm discovered that simple print() inside inline python didn't show anything on my console.

I use Windows 10 + Git Bash.

On PowerShell python errors and print showed correctly.

Also, the original error is this:

baseName = os.path.basename(sys.argv[0])
IndexError: list index out of range

So, this hack works:

import sys
sys.argv = ["./myprog"]

Therefore Original issue expanded to two problems:

  1. Nothing shows on Windows 10 + Git Bash
  2. sys.argv is empty

I think by default sys.args[0] should contain program address.

@optozorax optozorax changed the title Show execute error messages sys.argv is empty May 21, 2020
@m-ou-se m-ou-se mentioned this issue May 23, 2020
@m-ou-se
Copy link
Owner

m-ou-se commented May 23, 2020

Interesting. Here on Linux, sys.argv is [''], not []. Your example runs fine here.

Apparently something about sys.argv is different on Windows.

@m-ou-se
Copy link
Owner

m-ou-se commented May 23, 2020

I don't have a Windows computer here to test, but looking at the CPython source code, it looks like it should be impossible for sys.argv to be empty:

    /* sys.argv must be non-empty: empty argv is replaced with [''] */
    assert(config->argv.length >= 1);

source

So not sure what's happening in your case.

@Milchdealer
Copy link

This is also the documented behaviour:

If no script name was passed to the Python interpreter, argv[0] is the empty string.

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

3 participants