agriyakhetarpal / hugo-python-distributions

pip-installable binaries (wheels) for the extended version of the Hugo static site generator (note: unofficial, community-maintained)
https://pypi.org/project/hugo/
Apache License 2.0
13 stars 1 forks source link

Unable to create a new Hugo Project using Python #93

Closed MuhammadNYoussef closed 4 months ago

MuhammadNYoussef commented 4 months ago

I created a Python virtual environment and installed the hugo static site generator using pip install hugo. However, when I try to use the hugo command in the terminal, I encounter an error and am unable to proceed. This prevents me from creating a Hugo project using Python.

Steps to Reproduce:

  1. Create and activate a new Python virtual environment.
  2. Install hugo using pip install hugo.
  3. Run the command hugo version.

Error Message:

(.venv) PS P:\Project-Name> hugo version
Running Hugo 0.125.4 via hugo-python-distributions at P:\Project-Name\.venv\lib\site-packages\hugo\binaries\hugo-0.125.4-windows-amd64.exe
Traceback (most recent call last):
  File "D:\Python310\lib\runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "D:\Python310\lib\runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "P:\Project-Name\.venv\Scripts\hugo.exe\__main__.py", line 7, in <module>
  File "P:\Project-Name\.venv\lib\site-packages\hugo\cli.py", line 68, in __call
    check_call([hugo_executable(), *argv[1:]])
  File "D:\Python310\lib\subprocess.py", line 369, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['P:\\Project-Name\\.venv\\lib\\site-packages\\hugo\\binaries\\hugo-0.125.4-windows-amd64.exe', 'version']' returned non-zero exit status 3221225781.

What I want to do: Just create a static hugo project using Python.

agriyakhetarpal commented 4 months ago

Hi, @MuhammadNYoussef! Thanks for filing this bug report – first one by an external user. :)

I'm unsure why this happens, because I have been testing the wheels after I have built them since I started the project altogether.

Do the below links help?

https://stackoverflow.com/questions/49413443/trouble-debugging-error-with-exit-code-3221225781-missing-libraries-in-windows

https://stackoverflow.com/questions/60348640/docker-returning-exit-code-3221225781-installing-vc-redist-x64-exe

I think what is happening is that running the executable requires some version of the Windows UCRT and other dependencies, which is available on GitHub Actions runners, but probably not on regular Windows systems... I'll look for more reasons where this comes from, but it looks like there are some missing DLLs that the program is linked to but I haven't copied them into the wheel.

agriyakhetarpal commented 4 months ago

Strange – no dependencies seem to be required:

$ pipx run delvewheel repair hugo-0.125.4-py3-none-win_amd64.whl

repairing hugo-0.125.4-py3-none-win_amd64.whl
finding DLL dependencies
no external dependencies are needed
wheel copied to /Users/agriyakhetarpal/wheelhouse/hugo-0.125.4-py3-none-win_amd64.whl

and so says repairwheel:

$ pipx run repairwheel -o . hugo-0.125.4-py3-none-win_amd64.whl

repairing /Users/agriyakhetarpal/hugo-0.125.4-py3-none-win_amd64.whl
finding DLL dependencies
no external dependencies are needed
wheel copied to /var/folders/b3/2bq1m1_50bs4c7305j8vxcqr0000gn/T/repairwheel5gi0wkbv/hugo-0.125.4-py3-none-win_amd64.whl
Wrote /Users/agriyakhetarpal/hugo-0.125.4-py3-none-win_amd64.whl

I will test on a Windows system as well, just to confirm nothing is being missed.

agriyakhetarpal commented 4 months ago

Found the bug – I had to compile a static binary with MinGW, of course. No one has ever reported this, and it wasn't caught before in CI. I'll be happy to fix that in the next release, or would you want me to issue a patch release? I don't think I'll be able to backport this to the several past releases, and therefore would lean towards fixing it in the next one, so, as a temporary workaround, you can install MinGW using the Chocolatey package manager (choco install mingw) after installing Chocolatey, and everything will then work.

MuhammadNYoussef commented 4 months ago

Hey @agriyakhetarpal, Thanks a bunch for looking into my problem! The workaround you suggested is really helpful. I appreciate you taking the time to figure that out. Looking forward to a permanent fix, but in the meantime, this is a lifesaver!

agriyakhetarpal commented 4 months ago

@MuhammadNYoussef, would you be able to download and install wheels from https://github.com/agriyakhetarpal/hugo-python-distributions/actions/runs/8877331272/artifacts/1456296110 and confirm if they are working for you? You might need to uninstall MinGW that you installed to be able to test them properly. These builds are compiled as static binaries and therefore should resolve the issue – but since you opened the bug report, I think it's best to ask you too :) if they do, I'll mark #94 as closing the issue, which should go into the next release (hopefully soon). Again, many thanks for filing the bug report, truly a sign that things here need fixing, haha!

MuhammadNYoussef commented 4 months ago

@agriyakhetarpal, I used the wheels you provided and the issue is resolved now. Thanks a bunch!

agriyakhetarpal commented 4 months ago

I just pushed v0.125.5 (release) which includes the fix, should be available on PyPI in an hour or so. Thanks again for reporting it, and please don't hesitate to let me know if anything is still broken.