V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
wyc9296
V2EX  ›  Python

sublimeText3 的 REPL 怎么在虚拟环境下 run current file? - Python

  •  1
     
  •   wyc9296 · 2019-07-10 11:26:51 +08:00 · 1791 次点击
    这是一个创建于 1746 天前的主题,其中的信息可能已经有所发展或是发生改变。

    看中了 REPL 可以分屏,可以有交互界面、dos 界面、还可以直接 run 脚本。直接 run 时,对于一些一直运行的脚本,如 flask,可以右键 kill 掉,这点比 build system 有优势多了。

    但是,ctrl shift+P 打开 command_palette 后,输入SublimeREPL: Python-virtualenv,选择某个虚拟环境后,就直接转到 python 交互界面了:

    Python 3.5.4 (v3.5.4, Aug  8 2017, 02:17:05) [MSC v.1900 64 bit (AMD64)] on win32
    Type "help", "copyright", "credits" or "license" for more information.
    (InteractiveConsole)
    >>> 
    

    直接运行这个 file 的话(tool->sublimeREPL->python->python - run current file),只能在 global 的 python 环境下运行。

    1 条回复    2019-07-10 15:12:32 +08:00
    wyc9296
        1
    wyc9296  
    OP
       2019-07-10 15:12:32 +08:00
    研究了半天,我自己暂时的解决办法:
    (##how to run current file in sublimeREPL with python virtualenv )
    1. 记得修改一下 python_virtualenv_paths,把它设置成"~\\Envs"
    2. 在 packages\sublimeREPL 中找到 lang_integration.py,把 PythonVirtualenvRepl 这个 class 中的
    ```
    "cmd": [python_executable, "-u", "${packages}/SublimeREPL/config/Python/ipy_repl.py"],改
    ```
    改为
    ```
    "cmd": [python_executable, "-u", "$file_basename"],
    ```
    3. 快捷键设置:
    ```
    {
    "keys":["f5"],
    "caption": "SublimeREPL: Python - RUN current file",
    "command": "run_existing_window_command",
    "args": {
    "id": "python_virtualenv_repl",
    "file": "config/Python/Main.sublime-menu"
    }
    },
    ```
    打算从现在开始起不用 pycharm 了,速度太慢了。运行 flask app 时如果想停止,直接右键 kill 即可。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2955 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 03:34 · PVG 11:34 · LAX 20:34 · JFK 23:34
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.