Twisted app在OS X上失败并显示错误"无法加载应用程序:没有名为OpenSSL.SSL的模块"

 yuanchengyc 发布于 2023-01-09 15:03

通过twistd -n -y chatserver.py它运行Twisted(OS X 10.9.3)文件失败时出错:

...line 40, in 
    from OpenSSL.SSL import Error, ZeroReturnError, WantReadError
exceptions.ImportError: No module named OpenSSL.SSL

Failed to load application: No module named OpenSSL.SSL

python shell中的Twisted和ssl导入很好:

python
Python 2.7.3 (default, Oct 26 2012, 16:12:44) 
[GCC 4.2.1 Compatible Apple Clang 4.0 ((tags/Apple/clang-421.0.60))] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import twisted
>>> import ssl
>>> exit()

任何正确方向的指针?

谢谢!

1 个回答
  • 根据提供的信息,我会假设你:

    没有加载pyOpenSSL(错误说它试图导入"OpenSSL.SSL",你试图导入"ssl",我不知道"ssl"是否映射到pyOpenSSL).请参阅twisted的TLS文档.

    要么

    你的twistd正在运行一个不同的python实例然后你在终端提示符下得到的

    更新:

    鉴于评论中的反馈,并遵循SO的信息:检索python模块路径和查找python解释器的完整路径

    尝试运行以下命令以查看当前的python路径:

    对于twistd,将以下内容放在一个文件中并以与当前运行的twistd相同的方式运行它:

    from twisted.application.service import Application
    from twisted.internet import reactor
    import sys
    
    def print_path():
        print "   ----    The path to the twistd python is: " + str(sys.executable) + "   ----"
        reactor.stop()
    
    application = Application("path_test")
    reactor.callWhenRunning(print_path)
    

    对于命令行python,只需在交互模式下运行以下命令:

    import sys
    print sys.executable
    

    在我的情况下(运行OS X 10.9.3,我得到一些有点自定义的python)

    twistd来:

    % twistd -n -y twisted-question-24191967.py
    2014-06-13 11:08:19-0400 [-] Log opened.
    2014-06-13 11:08:19-0400 [-] twistd 13.2.0 (/usr/bin/python 2.7.5) starting up.
    2014-06-13 11:08:19-0400 [-] reactor class: twisted.internet.selectreactor.SelectReactor.
    2014-06-13 11:08:19-0400 [-]    ----    The path to the twistd python is: /usr/bin/python   ----
    2014-06-13 11:08:19-0400 [-] Main loop terminated.
    2014-06-13 11:08:19-0400 [-] Server Shut Down.
    

    交互方式:

    >>> import OpenSSL.SSL
    >>> print OpenSSL.SSL.__file__
    /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/OpenSSL/SSL.so
    >>> import sys
    >>> print sys.executable
    /usr/bin/python
    

    2023-01-09 15:04 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有