Skip to content

Failed to install this package from source code on Win10 #51

Description

@myd7349

Hey, guys!
I encountered several compilation errors while installing from source on my PC.

My environment:
OS: Win10 Simplified Chinese(So the default system encoding is GBK, not UTF-8)
Python version: Python 3.6
VS2015(vc14) is also installed on my PC.

The first error is about setup.py.

D:\GitHub\python-rapidjson>py -3 setup.py install
Traceback (most recent call last):
File "setup.py", line 27, in
long_description = f.read()
UnicodeDecodeError: 'gbk' codec can't decode byte 0xa6 in position 4092: illegal multibyte sequence

After I changed code below:

with open('README.rst') as f:
    long_description = f.read()

to

with open('README.rst', encoding='utf-8') as f:
    long_description = f.read()

This error disappeared.

The second error is about python-rapidjson/rapidjson.cpp:

...
running build_ext
building 'rapidjson' extension
D:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -I./rapidjson/include "-ID:\Program Files\Python36\include" "-ID:\Program Files\Python36\include" "-ID:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE" "-ID:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\ATLMFC\INCLUDE" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.1\include\um" "-IC:\Program Files (x86)\Windows Kits\8.1\include\shared" "-IC:\Program Files (x86)\Windows Kits\8.1\include\um" "-IC:\Program Files (x86)\Windows Kits\8.1\include\winrt" /EHsc /Tp./python-rapidjson/rapidjson.cpp /Fobuild\temp.win-amd64-3.6\Release./python-rapidjson/rapidjson.obj
rapidjson.cpp
./python-rapidjson/rapidjson.cpp(341): error C2131: expression did not evaluate to a constant
./python-rapidjson/rapidjson.cpp(341): note: failure was caused by non-constant arguments or reference to a non-constant symbol
./python-rapidjson/rapidjson.cpp(341): note: see usage of 'length'
./python-rapidjson/rapidjson.cpp(344): error C3863: array type 'char [length+]' is not assignable

So I had to change code:

            char zstr[length + 1];

            strncpy(zstr, str, length);
            zstr[length] = '\0';

            value = PyLong_FromString(zstr, NULL, 10);

to

            std::string zstr(str, length);

            value = PyLong_FromString(zstr.c_str(), NULL, 10);

The last error I encountered:

./python-rapidjson/rapidjson.cpp(1060): error C2556: 'char (*__timezone(void))[10]': overloaded function differs only by return type from 'long *__timezone(void)'
C:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt\time.h(73): note: see declaration of '__timezone'
./python-rapidjson/rapidjson.cpp(1060): error C2373: '__timezone': redefinition; different type modifiers
C:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt\time.h(73): note: see declaration of '__timezone'

It seems that timezone is defined as a macro. So, again MSVC failed to compile.
So, I renamed variable timezone to timeZone.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions