Running task 1 of 1: python .copier/update_dotenv.py /bin/sh: 1: python: not found
semiprogarlic opened this issue ยท 11 comments
I have python3 installed and have configured an alias python="python3"
in my .bash_aliases
file, so both python
and python3
cmdlets are available.
DESKTOP-0U5S399:~$ python --version
Python 3.8.10
DESKTOP-0U5S399:~$ python3 --version
Python 3.8.10
However, copier is unable to find the python module in /bin/sh. Can we update the copier.yml file to use python3 .copier/update_dotenv.py
instead of python .copier/update_dotenv.py
?
> Running task 1 of 1: python .copier/update_dotenv.py /bin/sh: 1: python: not found Traceback (most recent call last): File "/home/dathuku/.local/bin/copier", line 8, in <module> sys.exit(copier_app_run()) File "/home/dathuku/.local/lib/python3.8/site-packages/plumbum/cli/application.py", line 638, in run inst, retcode = subapp.run(argv, exit=False) File "/home/dathuku/.local/lib/python3.8/site-packages/plumbum/cli/application.py", line 633, in run retcode = inst.main(*tailargs) File "/home/dathuku/.local/lib/python3.8/site-packages/decorator.py", line 232, in fun return caller(func, *(extras + args), **kw) File "/home/dathuku/.local/lib/python3.8/site-packages/copier/cli.py", line 71, in handle_exceptions return method(*args, **kwargs) File "/home/dathuku/.local/lib/python3.8/site-packages/copier/cli.py", line 270, in main worker.run_copy() File "/home/dathuku/.local/lib/python3.8/site-packages/copier/main.py", line 205, in __exit__ raise value File "/home/dathuku/.local/lib/python3.8/site-packages/copier/cli.py", line 270, in main worker.run_copy() File "/home/dathuku/.local/lib/python3.8/site-packages/copier/main.py", line 759, in run_copy self._execute_tasks(self.template.tasks) File "/home/dathuku/.local/lib/python3.8/site-packages/copier/main.py", line 284, in _execute_tasks subprocess.run(task_cmd, shell=use_shell, check=True, env=local.env) File "/usr/lib/python3.8/subprocess.py", line 516, in run raise CalledProcessError(retcode, process.args, subprocess.CalledProcessError: Command 'python .copier/update_dotenv.py' returned non-zero exit status 127
Same Issue with My Window WSL
> Running task 1 of 1: python .copier/update_dotenv.py
/bin/sh: 1: python: not found
Traceback (most recent call last):
File "/home/username/.local/bin/copier", line 8, in <module>
sys.exit(copier_app_run())
File "/home/username/.local/lib/python3.10/site-packages/plumbum/cli/application.py", line 638, in run
inst, retcode = subapp.run(argv, exit=False)
File "/home/username/.local/lib/python3.10/site-packages/plumbum/cli/application.py", line 633, in run
retcode = inst.main(*tailargs)
File "/home/username/.local/lib/python3.10/site-packages/decorator.py", line 232, in fun
return caller(func, *(extras + args), **kw)
File "/home/username/.local/lib/python3.10/site-packages/copier/cli.py", line 71, in handle_exceptions
return method(*args, **kwargs)
File "/home/username/.local/lib/python3.10/site-packages/copier/cli.py", line 263, in main
with self._worker(
File "/home/username/.local/lib/python3.10/site-packages/copier/main.py", line 205, in __exit__
raise value
File "/home/username/.local/lib/python3.10/site-packages/copier/cli.py", line 270, in main
worker.run_copy()
File "/home/username/.local/lib/python3.10/site-packages/copier/main.py", line 759, in run_copy
self._execute_tasks(self.template.tasks)
File "/home/username/.local/lib/python3.10/site-packages/copier/main.py", line 284, in _execute_tasks
subprocess.run(task_cmd, shell=use_shell, check=True, env=local.env)
File "/usr/lib/python3.10/subprocess.py", line 526, in run
raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command 'python .copier/update_dotenv.py' returned non-zero exit status 127.
I got the same Issue with both my armbian and debian12.
I have set alias python="python3"
in ~/.bashrc
file, but it didn't work.
Maybe it's not a project issue, but a Python issue.
Finally, I tried apt install python-is-python3
, and then it worked
Thanks @frank2016ma that actually solves the issue
It's highly advisable you use virtual environments. It'll not only solve said problem, but it'll also save you the headaches that will arise from dependency management, such as conflicting global package installations.
This issue can now be closed in my opinion.
i got the same issue on MacOS, i configured alias python="python3"
in my .zshrc
, but it just don't work
@cblberlin Figuring out whether the Python command will be available under python
or python3
, or if it is available at all especially after a fresh installation of Python, is something extremely inconsistent for a variety of reasons, ranging from what shell you're using (BASH, ZSH, etc.) to how the terminal session is being created (VSCode GUI microsoft/vscode-remote-release#83, System Launcher, etc.) to the command interpreter you're using (BASH, ZSH, etc.).
Hence, trying to come up with a one-size-fits-all solution is just not feasible.
If I were you I'd save myself the headache and rollback the modifications you made to ~/.zshrc
to try to fix it, then figure out under which command Python 3 is available by runing python -V
andpython3 -V
(recreate the terminal session by closing it and opening it again in case neither work after having just installed Python 3), so you can use the correct command to create and activate the virtual environment, as pointed out in my previous answer, and call it a day.
In the file copier.yml search for "_tasks:"
then change the line python .copier/update_dotenv.py
to python3 .copier/update_dotenv.py
And if you are wondering why it is still not working then it is because you are using copier with the remote repo, and not your local.
Just fork the repo, change the line, and then use copier like this ->
copier copy path_to_your_fork project-name --trust
thx man, i will try it
How about adding a Makefile to help create a virtual environment before executing it?
If you're on debian, install python-is-python3
Problem: sudo -E doesn't keep aliases only $PATH and other environmental variables.
- If you're on MacOS and have Python installed by homebrew you can solve this issue by using
sudo visudo
and adding:
Defaults env_keep += "PATH"
If sudo python
now works, you're good otherwise:
- Add
/opt/homebrew/opt/python3/libexec/bin
or similar to your$PATH
in~/.zshrc
:
export PATH=/opt/homebrew/opt/python3/libexec/bin:$PATH
Good to go. Now sudo python
works as expected as does copier.
MORE DETAIL:
/opt/homebrew/opt/python3
is actually symlinked to the latest python3 version so to make it more durable we use the path /opt/homebrew/opt/python3/libexec/bin