美文网首页程序员
mac os上安装python3

mac os上安装python3

作者: 语文报 | 来源:发表于2017-08-13 15:28 被阅读0次

    在mac os上安装python3遇到了一些问题,现在记录如下:
    环境:macOs Sierra
    已经存在python2.7

    1. 首先选择brew安装python3.6, 出现ssl模块未安装的问题。 搜寻解决方案之后,都说如果出现这种情况 使用

    brew install openssl
    brew unlink openssl
    brew link openssl --force

    然后重新安装python3.6 ,使用

    brew install python3 --with-brewed-openssl

    结果 brew 提示 Warning: Refusing to link: openssl 由于对brew本身不是很熟悉,很多选项并不了解 故考虑从源码安装python3

    1. 选择从源码安装python3.6, 全部采用默认选项

    ./configure
    make
    make test
    sudo make install

    结果依然无法安装ssl模块,故查找具体原因,大致上理解是macos的openssl版本比较旧 而brew install ssl本身并没有取代系统ssl模块的位置,而是安装在了别的位置,所以python3安装会跳过ssl模块
    最后综合了几个帖子,屡次实验得到如下的解决方案
    >export LDFLAGS="-L\$(brew --prefix  openssl)/lib"  
    

    export CFLAGS="-I$(brew --prefix openssl)/include"
    ./configure --prefix=${你自己的家目录}/python3.6 --enable-optimizations
    make
    make altinstall

    测试:

    $ python3
    import ssl

    成功

    相关文章

      网友评论

        本文标题:mac os上安装python3

        本文链接:https://www.haomeiwen.com/subject/mfkerxtx.html