Skip to main content
 首页 » 编程设计

python之尝试安装 python asyncio 时失败

2024年10月01日7sky-heaven

我尝试为 python 安装 asyncio 但失败了 我不知道失败是否是“overlapped.c:68: error: 'PyExc_ConnectionRefusedError' undeclared” 或“错误:命令‘c:\mingw\bin\gcc.exe’失败,退出状态为 1” 以及解决方案...

命令:

C:\Users\AA>pip 安装异步

输出:

Collecting asyncio 
  Using cached asyncio-3.4.3.tar.gz 
Installing collected packages: asyncio 
  Running setup.py install for asyncio ... error 
    Complete output from command C:\Python27\python.exe -u -c "import setuptools 
, tokenize;__file__='c:\\users\\ait\\appdata\\local\\temp\\pip-build-eucukh\\asy 
ncio\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replac 
e('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --recor 
d c:\users\ait\appdata\local\temp\pip-4yjfsw-record\install-record.txt --single- 
version-externally-managed --compile: 
    running install 
    running build 
    running build_py 
    creating build 
    creating build\lib.win32-2.7 
    creating build\lib.win32-2.7\asyncio 
    copying asyncio\base_events.py -> build\lib.win32-2.7\asyncio 
    copying asyncio\base_subprocess.py -> build\lib.win32-2.7\asyncio 
    copying asyncio\constants.py -> build\lib.win32-2.7\asyncio 
    copying asyncio\coroutines.py -> build\lib.win32-2.7\asyncio 
    copying asyncio\events.py -> build\lib.win32-2.7\asyncio 
    copying asyncio\futures.py -> build\lib.win32-2.7\asyncio 
    copying asyncio\locks.py -> build\lib.win32-2.7\asyncio 
    copying asyncio\log.py -> build\lib.win32-2.7\asyncio 
    copying asyncio\proactor_events.py -> build\lib.win32-2.7\asyncio 
    copying asyncio\protocols.py -> build\lib.win32-2.7\asyncio 
    copying asyncio\queues.py -> build\lib.win32-2.7\asyncio 
    copying asyncio\selectors.py -> build\lib.win32-2.7\asyncio 
    copying asyncio\selector_events.py -> build\lib.win32-2.7\asyncio 
    copying asyncio\sslproto.py -> build\lib.win32-2.7\asyncio 
    copying asyncio\streams.py -> build\lib.win32-2.7\asyncio 
    copying asyncio\subprocess.py -> build\lib.win32-2.7\asyncio 
    copying asyncio\tasks.py -> build\lib.win32-2.7\asyncio 
    copying asyncio\test_support.py -> build\lib.win32-2.7\asyncio 
    copying asyncio\test_utils.py -> build\lib.win32-2.7\asyncio 
    copying asyncio\transports.py -> build\lib.win32-2.7\asyncio 
    copying asyncio\unix_events.py -> build\lib.win32-2.7\asyncio 
    copying asyncio\windows_events.py -> build\lib.win32-2.7\asyncio 
    copying asyncio\windows_utils.py -> build\lib.win32-2.7\asyncio 
    copying asyncio\__init__.py -> build\lib.win32-2.7\asyncio 
    running build_ext 
    building 'asyncio._overlapped' extension 
    creating build\temp.win32-2.7 
    creating build\temp.win32-2.7\Release 
    c:\mingw\bin\gcc.exe -mdll -O -Wall -IC:\Python27\include -IC:\Python27\PC - 
c overlapped.c -o build\temp.win32-2.7\Release\overlapped.o 
    overlapped.c: In function 'SetFromWindowsErr': 
    overlapped.c:68: error: 'PyExc_ConnectionRefusedError' undeclared (first use 
 in this function) 
    overlapped.c:68: error: (Each undeclared identifier is reported only once 
    overlapped.c:68: error: for each function it appears in.) 
    overlapped.c:71: error: 'PyExc_ConnectionAbortedError' undeclared (first use 
 in this function) 
    overlapped.c: At top level: 
    overlapped.c:83: error: expected '=', ',', ';', 'asm' or '__attribute__' bef 
ore 'Py_AcceptEx' 
    overlapped.c:84: error: expected '=', ',', ';', 'asm' or '__attribute__' bef 
ore 'Py_ConnectEx' 
    overlapped.c:85: error: expected '=', ',', ';', 'asm' or '__attribute__' bef 
ore 'Py_DisconnectEx' 
    overlapped.c: In function 'initialize_function_pointers': 
    overlapped.c:96: error: 'WSAID_ACCEPTEX' undeclared (first use in this funct 
ion) 
    overlapped.c:97: error: 'WSAID_CONNECTEX' undeclared (first use in this func 
tion) 
    overlapped.c:98: error: 'WSAID_DISCONNECTEX' undeclared (first use in this f 
unction) 
    overlapped.c:109: error: 'Py_AcceptEx' undeclared (first use in this functio 
n) 
    overlapped.c:110: error: 'Py_ConnectEx' undeclared (first use in this functi 
on) 
    overlapped.c:111: error: 'Py_DisconnectEx' undeclared (first use in this fun 
ction) 
    overlapped.c: In function 'overlapped_RegisterWaitWithQueue': 
    overlapped.c:271: warning: implicit declaration of function 'RegisterWaitFor 
SingleObject' 
    overlapped.c:272: error: 'WAITORTIMERCALLBACK' undeclared (first use in this 
 function) 
    overlapped.c:272: error: expected ')' before 'PostToQueueCallback' 
    overlapped.c: In function 'overlapped_UnregisterWait': 
    overlapped.c:298: warning: implicit declaration of function 'UnregisterWait' 
 
    overlapped.c: In function 'overlapped_UnregisterWaitEx': 
    overlapped.c:321: warning: implicit declaration of function 'UnregisterWaitE 
x' 
    overlapped.c: In function 'Overlapped_dealloc': 
    overlapped.c:580: warning: unknown conversion type character 'R' in format 
    overlapped.c:580: warning: too many arguments for format 
    overlapped.c: In function 'Overlapped_ReadFile': 
    overlapped.c:714: warning: implicit declaration of function 'Py_MIN' 
    overlapped.c:716: warning: implicit declaration of function 'Py_MAX' 
    overlapped.c: In function 'Overlapped_AcceptEx': 
    overlapped.c:948: warning: implicit declaration of function 'Py_AcceptEx' 
    overlapped.c: In function 'Overlapped_ConnectEx': 
    overlapped.c:1035: warning: implicit declaration of function 'Py_ConnectEx' 
    overlapped.c: In function 'Overlapped_DisconnectEx': 
    overlapped.c:1075: warning: implicit declaration of function 'Py_DisconnectE 
x' 
    overlapped.c: In function 'ConnectPipe': 
    overlapped.c:1145: warning: implicit declaration of function 'PyUnicode_AsWi 
deCharString' 
    overlapped.c:1145: warning: assignment makes pointer from integer without a 
cast 
    overlapped.c: At top level: 
    overlapped.c:1287: error: variable 'overlapped_module' has initializer but i 
ncomplete type 
    overlapped.c:1288: error: 'PyModuleDef_HEAD_INIT' undeclared here (not in a 
function) 
    overlapped.c:1288: warning: excess elements in struct initializer 
    overlapped.c:1288: warning: (near initialization for 'overlapped_module') 
    overlapped.c:1289: warning: excess elements in struct initializer 
    overlapped.c:1289: warning: (near initialization for 'overlapped_module') 
    overlapped.c:1290: warning: excess elements in struct initializer 
    overlapped.c:1290: warning: (near initialization for 'overlapped_module') 
    overlapped.c:1291: warning: excess elements in struct initializer 
    overlapped.c:1291: warning: (near initialization for 'overlapped_module') 
    overlapped.c:1292: warning: excess elements in struct initializer 
    overlapped.c:1292: warning: (near initialization for 'overlapped_module') 
    overlapped.c:1293: warning: excess elements in struct initializer 
    overlapped.c:1293: warning: (near initialization for 'overlapped_module') 
    overlapped.c:1294: warning: excess elements in struct initializer 
    overlapped.c:1294: warning: (near initialization for 'overlapped_module') 
    overlapped.c:1295: warning: excess elements in struct initializer 
    overlapped.c:1295: warning: (near initialization for 'overlapped_module') 
    overlapped.c:1297: warning: excess elements in struct initializer 
    overlapped.c:1297: warning: (near initialization for 'overlapped_module') 
    overlapped.c: In function 'PyInit__overlapped': 
    overlapped.c:1310: warning: 'return' with a value, in function returning voi 
d 
    overlapped.c:1314: warning: 'return' with a value, in function returning voi 
d 
    overlapped.c:1317: warning: 'return' with a value, in function returning voi 
d 
    overlapped.c:1319: warning: implicit declaration of function 'PyModule_Creat 
e' 
    overlapped.c:1319: warning: assignment makes pointer from integer without a 
cast 
    overlapped.c:1321: warning: 'return' with a value, in function returning voi 
d 
    overlapped.c:1333: error: 'SO_UPDATE_CONNECT_CONTEXT' undeclared (first use 
in this function) 
    overlapped.c:1336: warning: 'return' with a value, in function returning voi 
d 
    error: command 'c:\\mingw\\bin\\gcc.exe' failed with exit status 1 
 
    ---------------------------------------- 
Command "C:\Python27\python.exe -u -c "import setuptools, tokenize;__file__='c:\ 
\users\\ait\\appdata\\local\\temp\\pip-build-eucukh\\asyncio\\setup.py';f=getatt 
r(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close( 
);exec(compile(code, __file__, 'exec'))" install --record c:\users\ait\appdata\l 
ocal\temp\pip-4yjfsw-record\install-record.txt --single-version-externally-manag 
ed --compile" failed with error code 1 in c:\users\ait\appdata\local\temp\pip-bu 
ild-eucukh\asyncio\ 

当我尝试安装 trollius 时,出现此错误:

  C:\Users\Administrator\Downloads\trollius-2.1>c:\Python27\python.exe setup.py bdist_wheel upload 
!!! WARNING !!! The Trollius project is now deprecated! 
 
running bdist_wheel 
running build 
running build_py/ 
running build_ext 
building 'trollius._overlapped' extension 
c:\mingw\bin\gcc.exe -mdll -O -Wall -Ic:\Python27\include -Ic:\Python27\PC -c overlapped.c -o build\temp.win32-2.7\ 
Release\overlapped.o 
overlapped.c:99: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'Py_AcceptEx' 
overlapped.c:100: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'Py_ConnectEx' 
overlapped.c:101: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'Py_DisconnectEx' 
overlapped.c: In function 'initialize_function_pointers': 
overlapped.c:112: error: 'WSAID_ACCEPTEX' undeclared (first use in this function) 
overlapped.c:112: error: (Each undeclared identifier is reported only once 
overlapped.c:112: error: for each function it appears in.) 
overlapped.c:113: error: 'WSAID_CONNECTEX' undeclared (first use in this function) 
overlapped.c:114: error: 'WSAID_DISCONNECTEX' undeclared (first use in this function) 
overlapped.c:125: error: 'Py_AcceptEx' undeclared (first use in this function) 
overlapped.c:126: error: 'Py_ConnectEx' undeclared (first use in this function) 
overlapped.c:127: error: 'Py_DisconnectEx' undeclared (first use in this function) 
overlapped.c: In function 'overlapped_RegisterWaitWithQueue': 
overlapped.c:287: warning: implicit declaration of function 'RegisterWaitForSingleObject' 
overlapped.c:288: error: 'WAITORTIMERCALLBACK' undeclared (first use in this function) 
overlapped.c:288: error: expected ')' before 'PostToQueueCallback' 
overlapped.c: In function 'overlapped_UnregisterWait': 
overlapped.c:314: warning: implicit declaration of function 'UnregisterWait' 
overlapped.c: In function 'overlapped_UnregisterWaitEx': 
overlapped.c:337: warning: implicit declaration of function 'UnregisterWaitEx' 
overlapped.c: In function 'Overlapped_dealloc': 
overlapped.c:600: warning: unknown conversion type character 'R' in format 
overlapped.c:600: warning: too many arguments for format 
overlapped.c: In function 'Overlapped_AcceptEx': 
overlapped.c:976: warning: implicit declaration of function 'Py_AcceptEx' 
overlapped.c: In function 'Overlapped_ConnectEx': 
overlapped.c:1062: warning: implicit declaration of function 'Py_ConnectEx' 
overlapped.c: In function 'Overlapped_DisconnectEx': 
overlapped.c:1102: warning: implicit declaration of function 'Py_DisconnectEx' 
overlapped.c: In function 'ConnectPipe': 
overlapped.c:1165: warning: unused variable 'AddressObj' 
overlapped.c: In function '_init_overlapped': 
overlapped.c:1379: error: 'SO_UPDATE_CONNECT_CONTEXT' undeclared (first use in this function) 
error: command 'c:\\mingw\\bin\\gcc.exe' failed with exit status 1 

请您参考如下方法:

是的,如果你想使用 asyncio 安装 python3。 通过以下命令安装 python3 并使 python 3 默认

别名 python=/usr/bin/python3 将此命令写入您的 ~/.bash_aliases 文件 sudo nano ~/.bash_aliases 当你打开你的终端时,这会自动将 python 路径设置为 python 3