Open ibeex opened 5 years ago
hi @ibeex
Unfortunately this is not enough information to troubleshoot, what are the permissions on that file? also, can you share the version of shiv you are using and show me head -n1 my_command.pyz
?
thanks
here it is
[I] ➜ ll my_command.pyz
-rwxr-xr-x 1 myuser users 642K Nov 10 16:21 my_command.pyz
[I] ➜ head -n1 my_command.pyz
#!/usr/share/bash-completion/completions/python3
[I] ➜ type python
python is /home/myuser/.pyenv/shims/python
[I] ➜ type shiv
shiv is /home/myuser/.local/bin/shiv
shiv is installed with pipsi, I user pyenv to manage python versions, and virtualenvs
Edit:
it works using -p
shiv -e cpe_middleware.cpe_middleware:cli -p '/usr/bin/env python3' -o my_command.pyz .
is it bug or intended behaviour?
if I had to venture a guess I'd say the issue is the shebang there - is that a valid interpreter? does the pyz execute if you invoke it with your pyenv interpreter path? e.g.
/home/myuser/.pyenv/shims/python ./my_command.pyz
I'm not super familiar with pipsi, but nothing jumps out at me as incompatible with how shiv works.
/home/myuser/.pyenv/shims/python ./my_command.pyz
works, why is default python detected #!/usr/share/bash-completion/completions/python3
?
That is an excellent question - I have no idea why that would be the case.
If, when building a pyz
with shiv, you do not specify an interpreter or shebang (using the -p
option), then shiv defaults to sys.executable
but attempts first to suss out whether it's being invoked from a virtualenv or not, and if so, what is the actual location of that interpreter (rather than the interpreter that's been copied into the virtualenv).
This is done via the _interpreter_path
function (found here)
How did you make your pyz
? Were you in an activated virtualenv? Did you specify a shebang using -p
? In order to help I need to know more about your environment, and if possible, steps to be able to reproduce. Thanks :)
Hi @lorencarvalho my python setup involves pyenv pyenv manages python versions and virtualenviroments. My local pyton tools like black and shiv are installed in separate virtualenviroments with pipsi this configuration ensure that nothing is installed to system python and every project can haw separate python version and virtualenv.
So shiv is in separate virtualenv and it was invoked in virtualenviroment for my project
shiv -e cpe_m.cpe_mi:cli -o my_command.pyz .
.
One more thing as I understand shiv should make pyz
on your local machine and simplify deployment on remote machine. So isn't better that default shebang should be /usr/bin/env python3
or /usr/bin/env python2
depending on python version. And _interpreter_path
can return one or another depending is it py2 or py3.
@ibeex shiv only supports Python 3 (specifically 3.6, as f-strings are used) currently. It is theoretically possible that we could build Python 2 zipapps, but given EOL for Py2 is inching closer and closer every day (2020!) we've opted not to.
I'm unfamiliar with the implementation of pipsi and pyenv, so I'm not in the best position to debug those issues, but yes, if you intend to ship your pyz to another machine, then passing --python "/usr/bin/env python3"
when creating your pyz is generally the best practice.
I am having a similar issue with incorrect shebang:
$ python3 -m this | grep guess
In the face of ambiguity, refuse the temptation to guess.
If you ask me, -p
should be a mandatory option. ;)
Possibly allowing things like {pymajor}
based on the running interpreter.
doing
shiv -e cpe_m.cpe_mi:cli -o my_command.pyz .
in setup.py dir and then try to run command I get this strange error msg?