full-stack-fastapi-template icon indicating copy to clipboard operation
full-stack-fastapi-template copied to clipboard

Running task 1 of 1: python .copier/update_dotenv.py /bin/sh: 1: python: not found

Open semiprogarlic opened this issue 11 months ago • 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

semiprogarlic avatar Mar 16 '24 18:03 semiprogarlic

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.

chapimenge3 avatar Mar 18 '24 05:03 chapimenge3

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

frank2016ma avatar Mar 19 '24 07:03 frank2016ma

Thanks @frank2016ma that actually solves the issue

chapimenge3 avatar Mar 19 '24 08:03 chapimenge3

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.

codespearhead avatar Mar 22 '24 16:03 codespearhead

i got the same issue on MacOS, i configured alias python="python3" in my .zshrc, but it just don't work

cblberlin avatar May 19 '24 09:05 cblberlin

@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 https://github.com/microsoft/vscode-remote-release/issues/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.

codespearhead avatar May 19 '24 14:05 codespearhead

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

DennisKretz avatar Jun 04 '24 15:06 DennisKretz

thx man, i will try it

cblberlin avatar Jun 04 '24 15:06 cblberlin

How about adding a Makefile to help create a virtual environment before executing it?

touero avatar Aug 22 '24 03:08 touero