【发布时间】:2014-01-19 18:17:12
【问题描述】:
我正在尝试使用我编写的名为compileToPyd 的自定义模块将一些.py 文件编译成.pyd(它只处理与编译相关的各种命令)。
我在尝试编译一个简单文件时遇到很多错误:
path\lib>C:\Python27\python.exe "main_setup.py" build
running build
running build_ext
cythoning main.pyx to main.c
Error compiling Cython file:
------------------------------------------------------------
...
?# main.pyd
^
------------------------------------------------------------
main.pyx:1:0: Unrecognized character
building 'main' extension
c:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\BIN\cl.exe /c /nologo /Ox
/MD /W3 /GS- /DNDEBUG -IC:\Python27\include -IC:\Python27\PC /Tcmain.c /Fobuild\
temp.win32-2.7\Release\main.obj
main.c
main.c(1) : fatal error C1189: #error : Do not use this file, it is the result
of a failed Cython compilation.
error: command '"c:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\BIN\cl.ex
e"' failed with exit status 2
python\lib>"gcc" "main.c" -o "main.pyd" -shared -I"C:\Python27\include" -L"C:\Python27\libs" -lpython
27
main.c:1:2: error: #error Do not use this file, it is the result of a failed Cyt
hon compilation.
#error Do not use this file, it is the result of a failed Cython compilation.
文件本身很简单:
# main.pyd
# author name
# January 2014
class AuthenticationError(Exception):
pass
def main():
'''Main process'''
import authenticate
if authenticate.authenticate():
import some_module
some_module.main()
else:
raise AuthenticationError("Not Authenticated")
它不是一个可执行文件,应该被导入。编译适用于其他文件,那么为什么不是这个呢?谢谢!
【问题讨论】:
-
我在这里猜测,但编译器在文件中第一个可见字符 before 之前抱怨一个字符的事实向我表明该文件已与包含字节顺序标记 (BOM) 的编码。你能验证那个文件的编码吗?由于您使用的是 Visual Studio,因此请使用文件菜单上的高级文件保存选项来检查文件看起来像它具有的编码。然后尝试选择不包含 BOM 的编码。
-
我已将 Notepad++ 设置为不使用 BOM ......但显然它还是这样做了。您应该将其发布为答案;它解决了我的问题:)。顺便谢谢!
-
好的,将其作为答案发布,并提供更多信息。