Why I`m Getting Oserror: [errno 7] Argument List Too Long: B'/usr/local/bin/git'?
Solution 1:
"Argument list too long" is a Unix-style error that indicates that the arguments to the exec
-like function are, well, too long. (The b'/usr/local/bin/git'
part here is misleading: that's not the part that is too long.) The /Library/Frameworks/Python.framework/
prefix strongly suggests that you're on MacOS, which has a Mach-ish kernel that is Unix-based and has relatively small argument limits:
sh-3.2$ sysctl kern.argmax
kern.argmax: 262144
This means that there's a maximum of 256 kiB of argument characters, including the command itself and all the bytes of arguments, including the \0
byte that terminates each one. There's often a limit on the length of argv
itself as well. The details vary from one system to another. See also this question on the unix.stackexchange.com site, for instance.
It's not immediately clear to me what to do about this. Looking at the stack trace, we find this pair of lines (which I've split up further for posting purposes here):
File "/Library/Frameworks/Python.framework/Versions/3.8/
lib/python3.8/site-packages/lib50/_api.py", line 326, inprepare
_run(git(f"add -f {' '.join(shlex.quote(f) for f in included)}"))
which points to the main culprit: a function named prepare
in the lib50
library that is part of what your course provided. This is trying to run a Git command with many file names passed to its git add
command. Where did it get the included
list? That, we don't know. If this list were shorter, the problem would not occur, but if there is no way for you to shorten the list, knowing this won't help.
Raising kern.argmax
would help, but it is probably not something you can set.
Using a different OS, with a different (or raise-able) maximum, could help.
The "right answer", though, is probably to have the software itself be smarter. There's no need to invoke git add
this particular way, with every file listed as one big argv
vector. Indeed, instead of invoking git add
directly, a program should probably be invoking git update-index
instead. A Python program should probably be using update-index
with the --stdin
and -z
flags (and any other flags as appropriate for this particular function's intended usage).
Other systems now provide Unix-like error numbers as well, even if they're not based on Unix. This particular one is E2BIG
or error #7, on MacOS.
Post a Comment for "Why I`m Getting Oserror: [errno 7] Argument List Too Long: B'/usr/local/bin/git'?"