美文网首页关于tensorflow
2019-10-31 解决sublime安装sublimeREP

2019-10-31 解决sublime安装sublimeREP

作者: 4aGreed | 来源:发表于2019-10-31 00:28 被阅读0次

    问题出现的原因:
    你在cmd下可以import tensorflow
    sublime中新建编译系统之后设置好python也可以进行import,就是在安装了sublimeREPL之后出错

    我的解决办法
    默认的路径指向的是你环境变量中python路径,即你cmd下输入python的路径,现在要改变成为···\anaconda\envs\tensorflow中的python路径
    1、sublime中点击首选项,浏览插件目录,打开sublimeREPL->config->python->Main.sublime-menu(拖拽至sublime打开即可)
    2、找到如下部分的代码

                       {                   
                         "command": "repl_open",
                         "caption": "Python - RUN current file",
                         "id": "repl_python_run",
                         "mnemonic": "R",
                         "args": {
                            "type": "subprocess",
                            "encoding": "utf8",
                            "cmd": ["python", "-u", "$file_basename"],
                            "cwd": "$file_path",
                            "syntax": "Packages/Python/Python.tmLanguage",
                            "external_id": "python",
                            "extend_env": {"PYTHONIOENCODING": "utf-8"}
                            }
                        },
    修改为
    
                   {                   
                     "command": "repl_open",
                     "caption": "Python - RUN current file",
                     "id": "repl_python_run",
                     "mnemonic": "R",
                     "args": {
                        "type": "subprocess",
                        "encoding": "utf8",
                        "cmd": ["E:\\anaconda\\envs\\tensorflow\\python", "-u", "$file_basename"],
                        "cwd": "$file_path",
                        "syntax": "Packages/Python/Python.tmLanguage",
                        "external_id": "python",
                        "extend_env": {"PYTHONIOENCODING": "utf-8"}
                        }
                    },
    

    注意修改部分要根据你自己的虚拟环境下的路径进行填写
    3、ctrl+s之后重启sublime,然后运行如下代码块

    import tensorflow as tf
    import os
    os.environ["TF_CPP_MIN_LOG_LEVEL"] = "2"
    message = tf.constant("welcome")
    with tf.Session() as sess:
        print(sess.run(message).decode())
    

    是不是输出了你想要的结果?

    如果还有什么别的错误可以留言一起讨论讨论~

    相关文章

      网友评论

        本文标题:2019-10-31 解决sublime安装sublimeREP

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