tbm / test

0 stars 0 forks source link

Figure out Windows installation sans Cygwin #59

Closed tbm closed 8 years ago

tbm commented 9 years ago

Original report by Martin Blais (Bitbucket: blais, GitHub: blais).


Try installing this with MingW32 instead of Cygwin. It's a bit crazy, but some people want to run it that way.

tbm commented 9 years ago

Original comment by Matthias Kauer (Bitbucket: matthias_kauer).


Hey, I'm the one who brought this up on the mailing list. Give me a few days before I give up on figuring it out. How about that?

tbm commented 9 years ago

Original comment by Matthias Kauer (Bitbucket: matthias_kauer).


Ok, I made some attempts and (of course) it's still somewhat more difficult than I had hoped. With VS Express 2012 I ran into problems with unistd.h in the parser/lexer.c files so I supplied the macro that switches them off there. It also appears that there are issues with the hashsrc that you supply in setup.py. Maybe the integer range it supplies is too large for Windows? I ran into this with seeding random numbers before, but it's just a guess. I commented this out and supplied a low integer instead. This got everything compiled, but leaves me with a linker error now:

C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\BIN\link.exe /DLL /nologo /INCREMENTAL:NO /LIBPATH:C:\Anaconda\envs\bc3\libs /LIBPATH:C:\Anaconda\envs\bc3\PCbuild /EXPORT:PyInit_beancount/parser/_parser build\temp.win32-3.4\Release\src/python/beancount/parser/lexer.obj build\temp.win32-3.4\Release\src/python/beancount/parser/grammar.obj build\temp.win32-3.4\Release\src/python/beancount/parser/parser.obj /OUT:build\lib.win32-3.4\beancount/parser/_parser.pyd /IMPLIB:build\temp.win32-3.4\Release\src/python/beancount/parser\_parser.lib /MANIFESTFILE:build\temp.win32-3.4\Release\src/python/beancount/parser\_parser.pyd.manifest
LINK : error LNK2001: unresolved external symbol PyInit_beancount/parser/_parser
build\temp.win32-3.4\Release\src/python/beancount/parser\_parser.lib : fatal error LNK1120: 1 unresolved externals
error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 11.0\\VC\\BIN\\link.exe' failed with exit status 1120

I also tried it with mingw64 as supplied by Mr Lavavej. Here unistd.h appeared to be no problem. However, we may have to build Python3.4 with MingW somehow to make this work. This could also be a 32bit (my Python) vs 64bit (the compiler) issue. I'm not sure.

c:/opt/mingw_nuwen/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/../../../../x86_64-w6
4-mingw32/bin/ld.exe: cannot find -lpython34
collect2.exe: error: ld returned 1 exit status
error: command 'C:\\opt\\mingw_nuwen\\bin\\gcc.exe' failed with exit status 1

I hope this helps somewhat. Maybe my desire for having a re-distributable binary is as crazy as you put it and we should let this rest a bit. Hmm.

tbm commented 9 years ago

Original comment by Matthias Kauer (Bitbucket: matthias_kauer).


I also had to move a variable declaration in parser.c before any code was used. Not sure why, but that's what a quick search for error C2275: 'PyObject' : illegal use of this type as an expression suggested.

Win flex-bison might be another option. Are you optimistic about exploring that?

tbm commented 9 years ago

Original comment by Matthias Kauer (Bitbucket: matthias_kauer).


Update: installing libpython and mingw through anaconda and then calling setup.py again now yields me the same linker error as with Visual studio.

C:\Anaconda\envs\bc3\Scripts\gcc.bat -shared -s build\temp.win32-3.4\Release\src\python\beancount\parser\lexer.o build\temp.win32-3.4\Release\src\python\beancount\parser\grammar.o build\temp.win32-3.4\Release\src\python\beancount\parser\parser.o build\temp.win32-3.4\Release\src\python\beancount\parser\_parser.def -LC:\Anaconda\envs\bc3\libs -LC:\Anaconda\envs\bc3\PCbuild -lpython34 -lmsvcr100 -o build\lib.win32-3.4\beancount/parser/_parser.pyd
Cannot export PyInit_beancount/parser/_parser: symbol not defined
collect2.exe: error: ld returned 1 exit status
error: command 'C:\\Anaconda\\envs\\bc3\\Scripts\\gcc.bat' failed with exit status 1
tbm commented 9 years ago

Original comment by Martin Blais (Bitbucket: blais, GitHub: blais).


Hi Mathias, I tried it too, I got this far:

At this point it fails to compile because the preprocessor behaves differently than on Linux (the checksum I compute to warn against bad version compiled vs. source code fails to compile).

I stopped there, had other things to do. This code could be commented out. Sounds to be like you're encountering the next problem beyond that one.

Just curious... why not just install Cygwin and be done with it? Even if we get this to work, you won't have great command-line tools... I think you would still want Cygwin. A lot of the tools assume command-line options (except maybe bean-web).

tbm commented 9 years ago

Original comment by Matthias Kauer (Bitbucket: matthias_kauer).


I temporarily solved that checksum issue by disabling it, yes.

But overall, you're right. Let's let this settle for a bit before we make an additional effort.

I had done this kind of compilations in the past and I hoped that I could be helpful. Unix is integrated more deeply here than in the projects that I'm familiar with which makes it much harder.

tbm commented 8 years ago

Original comment by Gambhiro Bhikkhu (Bitbucket: gambhiro, GitHub: gambhiro).


I would like to suggest resurrecting this thread.

I'm trying to compile fava into a single Windows binary .exe with PyInstaller, and on Windows it currently errors out when trying to compile beancount into a wheel file.

Fava is a real wow for browsing accounting data from beancount files. The goal is to be able to let other people in the office use fava, if one can give them an icon to click on, Windows users start to get onboard.

yegle helped to make fava compatible with PyInstaller, and now it compiles into a single binary on Linux.

I tried to compile on Windows:

Then:

$ cd fava
$ python -m virtualenv -p python.exe venv
$ venv\Scripts\activate
$ python -m pip install -e .

Here it was missing unistd.h and then getopt.h. So I created them in one of the include locations: C:\Users\USERNAME\AppData\Local\Programs\Python\Python35\include

unistd.h from here, getopt.c and getopt.h from here.

Try again:

$ python -m pip install -e .

And now it errors out with sth else:

 parser.c
    src/python/beancount/parser/parser.c(135): warning C4090: 'function': different 'const' qualifiers
    src/python/beancount/parser/parser.c(273): error C2065: 'None': undeclared identifier
    src/python/beancount/parser/parser.c(273): warning C4047: 'function': 'const char *' differs in levels of indirection from 'int'
    src/python/beancount/parser/parser.c(273): warning C4024: 'PyUnicode_FromString': different types for formal and actual parameter 1
    error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\BIN\\amd64\\cl.exe' failed with exit status 2

Is this possible to make Windows compatible?

tbm commented 8 years ago

Original comment by willwray (Bitbucket: willwray, GitHub: willwray).


The newly released Windows 10 Anniversary Update brings WSL 'Windows Subsystem for Linux' with bash on Ubuntu on Windows

Installation instructions and more here: https://msdn.microsoft.com/commandline/wsl/about

This makes beancount installation easy, from bash:

#!bash
sudo apt-get install python3-pip
sudo apt-get install python3-lxml
sudo pip3 install beancount

This is not totally 'Windows compatible', as it is running in a 'Pico' process, but gives a convenient way to get the Linux command-line experience on Windows.

tbm commented 8 years ago

Original comment by Martin Blais (Bitbucket: blais, GitHub: blais).


Thanks willwray; I added these instructions to the document. I suppose this fulfills the ticket.

tbm commented 8 years ago

Original comment by Martin Blais (Bitbucket: blais, GitHub: blais).


A solution that works without Cygwin has been proposed by willwray.

tbm commented 8 years ago

Original comment by Steve Stefanovich (Bitbucket: sstef, GitHub: sstef).


Just additional instruction: add --pre to the last command, otherwise install won't be successful (ignores pre-releases by default, and BC versions are all pre-releases).