Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot install on windows #7

Closed
pashagolub opened this issue Apr 16, 2018 · 16 comments
Closed

Cannot install on windows #7

pashagolub opened this issue Apr 16, 2018 · 16 comments

Comments

@pashagolub
Copy link

Windows 10, Python 3.6.

Full output is:

C:\Python36-32\Scripts>python -m pip install pg_query
Collecting pg_query
  Using cached pg_query-0.27.tar.gz
  Ignoring aenum: markers 'python_version < "3.6"' don't match your environment
Requirement already satisfied: setuptools in c:\python36-32\lib\site-packages (from pg_query)
Installing collected packages: pg-query
  Running setup.py install for pg-query ... error
    Complete output from command C:\Python36-32\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\PAVLO~1.GOL\\AppData\\Local\\Temp\\pip-build-8ph4yow2\\pg-query\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record C:\Users\PAVLO~1.GOL\AppData\Local\Temp\pip-m36oza86-record\install-record.txt --single-version-externally-managed --compile:
    running install
    running build
    running build_py
    creating build
    creating build\lib.win32-3.6
    creating build\lib.win32-3.6\pg_query
    copying pg_query\error.py -> build\lib.win32-3.6\pg_query
    copying pg_query\keywords.py -> build\lib.win32-3.6\pg_query
    copying pg_query\node.py -> build\lib.win32-3.6\pg_query
    copying pg_query\printer.py -> build\lib.win32-3.6\pg_query
    copying pg_query\__init__.py -> build\lib.win32-3.6\pg_query
    copying pg_query\__main__.py -> build\lib.win32-3.6\pg_query
    creating build\lib.win32-3.6\pg_query\enums
    copying pg_query\enums\lockoptions.py -> build\lib.win32-3.6\pg_query\enums
    copying pg_query\enums\nodes.py -> build\lib.win32-3.6\pg_query\enums
    copying pg_query\enums\parsenodes.py -> build\lib.win32-3.6\pg_query\enums
    copying pg_query\enums\pg_class.py -> build\lib.win32-3.6\pg_query\enums
    copying pg_query\enums\primnodes.py -> build\lib.win32-3.6\pg_query\enums
    copying pg_query\enums\__init__.py -> build\lib.win32-3.6\pg_query\enums
    creating build\lib.win32-3.6\pg_query\printers
    copying pg_query\printers\ddl.py -> build\lib.win32-3.6\pg_query\printers
    copying pg_query\printers\dml.py -> build\lib.win32-3.6\pg_query\printers
    copying pg_query\printers\sfuncs.py -> build\lib.win32-3.6\pg_query\printers
    copying pg_query\printers\__init__.py -> build\lib.win32-3.6\pg_query\printers
    running build_ext
    error: [WinError 2] The system cannot find the file specified

    ----------------------------------------
Command "C:\Python36-32\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\PAVLO~1.GOL\\AppData\\Local\\Temp\\pip-build-8ph4yow2\\pg-query\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record C:\Users\PAVLO~1.GOL\AppData\Local\Temp\pip-m36oza86-record\install-record.txt --single-version-externally-managed --compile" failed with error code 1 in C:\Users\PAVLO~1.GOL\AppData\Local\Temp\pip-build-8ph4yow2\pg-query\
@lelit
Copy link
Owner

lelit commented Apr 16, 2018

I never tried to build it on Windows machines, and the error is quite obscure, so it's not easy for me to help here. Does the compiler toolchain come with make?

I will try to install it on a VM with Win8 (if it still boot...), and report back.

@lelit
Copy link
Owner

lelit commented Apr 16, 2018

A very quick inspection suggests that even the underlying libpg_query library isn't easily compilable on Windows: its Makefile relies on GNU make facilities...

@pashagolub
Copy link
Author

Oh, I see now. I'll try to build it using MinGW and will let you know

@pashagolub
Copy link
Author

Nope, the same error. make present though

@lfittl
Copy link

lfittl commented Apr 16, 2018

Yes, at this point Windows is unfortunately not supported for libpg_query - the error above probably is caused by a compilation error in the C library code itself.

@lelit
Copy link
Owner

lelit commented Apr 16, 2018

Thank you Lukas! I spent a little on this, but the nmake that comes with Visual Studio misses lots of GNU make extensions...
I don't know if that will require a complete rewrite; also my Makefile uses some gmake features.

@lfittl
Copy link

lfittl commented Apr 16, 2018

Apart from the makefiles the other issue is that the extracted code from Postgres is currently not supporting Windows.

I've created pganalyze/libpg_query#44 to track this on the libpg_query repo itself.

@pashagolub
Copy link
Author

Closing this issue as outdated

@pashagolub pashagolub closed this as not planned Won't fix, can't repro, duplicate, stale Jul 6, 2023
@lelit
Copy link
Owner

lelit commented Jan 2, 2024

New year brought new hope on the subject, sooner or later someone could try it out.

@lelit
Copy link
Owner

lelit commented Jan 15, 2024

I did some experiments, but I ran out of spare time and ideas trying to solve redefinition errors between PG's win32_port.h and MSVC 2022 headers 😭

@lelit
Copy link
Owner

lelit commented Jan 15, 2024

@lfittl, any idea on what may trigger those hard errors?
Maybe I am including something extra, or in the wrong order?

@lfittl
Copy link

lfittl commented Jan 15, 2024

@lfittl, any idea on what may trigger those hard errors? Maybe I am including something extra, or in the wrong order?

I think that can happen when the windows system headers get loaded before pg_query gets loaded and is able to set some defines. Specifically, I think the Windows definition of S_IFLNK might get pulled in because WIN32_LEAN_AND_MEAN isn't set the first time windows.h gets loaded (see https://github.com/pganalyze/libpg_query/blob/16-latest/src/postgres/include/port/win32_port.h#L47).

It appears that S_IFLNK is the only hard error in that build, it might be worth to change the relevant code to instead look like this:

#ifndef S_IFLNK
#define S_IFLNK S_IFCHR
#endif

@lelit
Copy link
Owner

lelit commented Jan 15, 2024

Thank you, I will try to reorder the headers inclusion and see what happens.

lelit added a commit that referenced this issue Jan 17, 2024
As suggested by Lukas in #7 (comment),
the PG headers must be included first under Windows, even before any
other system header.

This is still not enough though, and I'm still investigating how to
convince Cython to include Python.h after postgresql.h.
@lelit
Copy link
Owner

lelit commented Jan 19, 2024

The good news is that on my local development machine I finally got it working, and all tests are green.
OTOH, the CI is not happy, and it will take some time before I can spend more cycles on that fighting with Windows.

lelit added a commit that referenced this issue Jan 21, 2024
As suggested by Lukas in #7 (comment),
the PG headers must be included first under Windows, even before any
other system header.

This is still not enough though, and I'm still investigating how to
convince Cython to include Python.h after postgresql.h.
lelit added a commit that referenced this issue Jan 21, 2024
Compiling on Windows is always a pain (IMHO, of course :-), but with a
sufficient amount of patience I was eventually able to do it, first on
my local machine and then tweaking the CI configuration to build wheels
on GitHub.

Due to the way PG's headers has been extended to support Windows, its
main header (that is, postgres.h) must be included earlier than any
other system header, and that means before Python.h.

Since I could not find a way to convince Cython to generate a C source
that includes a particular header before anything else, I replaced the
`cythonize` approach with an explicit pre-generation of the C source
using the `cython` CLI tool and the hacking it with `ed` to move the
import of "postgres.h" near the beginning.

This fixes issue #7.
@lelit
Copy link
Owner

lelit commented Jan 21, 2024

I just released 6.0.dev2, and the CI should produce Windows wheels... 🥳

@lelit
Copy link
Owner

lelit commented Jan 23, 2024

v6 is out, carrying Windows binary wheels!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants