zplab / zbar-py

Simple python 2 and 3 compatible interface to the zbar barcode-reading library
MIT License
82 stars 30 forks source link

Window build errors #8

Closed rounaksingh closed 5 years ago

rounaksingh commented 6 years ago

Hi, There have reports regarding building zbar-py on windows. So, I tried compiling/building the package myself using Python 3.5/win10/32bit. I found that there are few issues. Some are related to the unportable code. unistd.h and getopt is not available on windows VC/VC++ 14 build tools for python 3.

I am working to get portable versions of unistd.h and getopt. From https://stackoverflow.com/questions/341817/is-there-a-replacement-for-unistd-h-for-windows-visual-c https://gist.github.com/ashelly/7776712

Thanks

jackalhan commented 6 years ago

Thank you,

We tried the following with Zach, : Comment out line 75 of setup.py: ext_modules=[zbar], This will make the zbar C library not try to build. Then run the usual setup.py to install the package (take note of where it gets installed to). Next, download the pre-packaged zbar library and install the DLL. Find zbar.dll wherever it gets installed (or try to extract it from the installer), copy it to the same directory where zbar.py gets installed to, and rename it as _zbar.dll.

But according to my testing, I am still getting a runtime error in _zbar.c file while importing zbar.

rounaksingh commented 6 years ago

Hi, I build the code in windows10, Python 3.5 MSVC14. with work-arounds. New Code 1) unistd.h from https://stackoverflow.com/questions/341817/is-there-a-replacement-for-unistd-h-for-windows-visual-c 2) getopt.h https://gist.github.com/ashelly/7776712 3) for sys/time.h for gettimeoftheday(): I have a independent implementation. https://gist.github.com/ugovaretto/5875385 However, There is more win native way to work it is using GetLocalTime or GetSystemTime for windows https://stackoverflow.com/questions/10905892/equivalent-of-gettimeday-for-windows 4) error C2036: 'void *': unknown size in scanner.c https://stackoverflow.com/questions/37460579/error-c2036-void-unknown-size 5) There was some problem in _zbar.c (PyInitmodulename: I changed it to PyInitzbar) 6) I also found a iconv implementation for windows on github which I included as submodule. https://github.com/holy-shit/iconv-for-windows

After these, the setup.py was able to build the code. However, while importing it is still showing importError. There is problem while registering the API, it is showing AttributeError-- functions from c are not linking.

Somebody else should give it a try or use swig or Cython. Wraping becomes really easy using these modules.

Also, the licenses of the new code (most of it is LGPL) should be taken into consideration.

Thanks

jmdp1313 commented 6 years ago

Using windows 10 64-bit with Python 3.5

Source/zbar/qrcode/qrdectxt.c(9): fatal error C1083: Cannot open include file: 'iconv.h': No such file or directory error: command 'C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\cl.exe' failed with exit status 2

^ error arose when i tried py setup.py install from zbar-py-devel, any solutions to this? Thanks