python - pyinstaller导入错误: No module name '_socket'

标签 python sockets pyinstaller

我正在使用:

  • pyinstaller 3.2(我也试试开发版)
  • window 10
  • python 3.5.2

代码是:

import socket

print("test")
so = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
so.setblocking(True)  
print(so)

我这样启动pyinstaller

pyinstaller --noupx -D --log-level DEBUG test.py

当我启动可执行文件时,我得到以下信息:

Traceback (most recent call last):
  File "test.py", line 1, in <module>
  File "c:\python35-32\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 389, in load_module
    exec(bytecode, module.__dict__)
  File "socket.py", line 49, in <module>
ImportError: No module named '_socket'
Failed to execute script test

警告文件 warntest.txt 看起来像这样(我把它缩短了)

[...]
missing module named math.cos - imported by math, random, D:\Projet\eq_sim\test.py
missing module named socket.SOCK_STREAM - imported by socket, ssl, D:\Projet\eq_sim\test.py
missing module named socket.AF_INET - imported by socket, ssl, D:\Projet\eq_sim\test.py
missing module named socket.SO_TYPE - imported by socket, ssl, D:\Projet\eq_sim\test.py
missing module named socket.SOL_SOCKET - imported by socket, ssl, D:\Projet\eq_sim\test.py
missing module named copy.deepcopy - imported by copy, weakref, email.generator, D:\Projet\eq_sim\test.py
[...]

我查看了页面 https://github.com/pyinstaller/pyinstaller/wiki/If-Things-Go-Wrong找出我的问题但没有成功。

我已经检查存档文件 out00-PYZ.pyz,好像还可以

在目录 [...]bincache00_py35_32bit/中,文件 _socket.pyd 存在,所以它似乎找到了它。

我试过添加路径(-p)和其他东西,结果总是一样

这是一个非常简单的案例,所以我想我在这里遗漏了一些东西

最佳答案

好吧,伙计们……我很惭愧……我没有运行好的可执行文件。

我正在运行 build/ 目录中的 exe 文件,我必须运行 dist/ 目录中的那个。

关于python - pyinstaller导入错误: No module name '_socket' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38354982/

相关文章:

python - 从现有的日期列创建新列 "Week"

C语言,获取HTML源码

python - 在 PyInstaller 的 SPEC 文件中使用变量

JAVA同步块(synchronized block)在多线程环境中不起作用

python - 当我使用 pyinstaller3 打包 Python 脚本时,McAfee 总是发现病毒

python - Dask + pyinstaller 失败

python - 将 flask 脚本与模板过滤器一起使用

python - PyFMI FMU 模块方法 get_variable_unit() 常量

python - 如何从 pandas 读取日期时间

Java、端口、套接字、通过程序管道连接