Execute#
此文档重点介绍了如何在 PyCharm 中运行脚本.
Run Last Executed File:
Ctrl + R
(MacOS)Select a file to Run:
Ctrl + Alt + R
(MacOS)
Set your Python executable (Even for virtualenv)#
如何用快捷键来用指定的 Python 解释器运行脚本.
Preference
-> Project
-> Project Interpreter
, Set Python executable.
Windows:
C:\Python27\python.exe
MacOS:
If your python are installed from HomeBrew, it should be at:
/usr/local/Cellar/python2/2.7.13/Frameworks/Python.framework/Versions/2.7/bin/python2.7
Linux:
<path-to-your-virtualenv-folder>
Execute in Bash#
Note
Before 2020, we need a BashSupport plugin (No longer free). But after that, PyCharm support run bash script out-of-the-box.
Another way is to use External Tools
to configure it.
Set up external tools:
Preference
->Tools
->External Tools
->Add new one
click+
sign.Config executable:
Name
: name for this tool, I useRun with Bash
,Description
: any description text,Program
: The executable file (.exe for Windows, usually using git-bash.exe, /bin/bash for MacOS),Parameters
:$FileName$
(you can select from macro),Working Directory
:$FileDir$
, clickOK
.Assign a Keymap:
Preference
->Keymap
-> SearchRun with Bash
-> Add a keymap, I useShift + `
.Try it out: select a file in project view, press Ctrl + Shift +
`
.
Open File in Sublime Text#
Set up external tools:
Preference
->Tools
->External Tools
->Add new one
click+
sign.Config executable:
Name
: name for this tool, I useSublime Text
,Description
: any description text,Program
: The sublime text executable file (path\to\Sublime Text.exe
for Windows,/Applications/Sublime Text.app
for MacOS),Parameters
:$FileName$
(you can select from macro),Working Directory
:$FileDir$
, clickOK
.Assign a Keymap:
Preference
->Keymap
-> SearchSublime Text
-> Add a keymap, I useAlt + Cmd + S
.Try it out: select a file in project view, press
Alt + Cmd + S
.
Note
Configuration for VSCode is similar.
Reference:
PyCharm: Open the current file in Vim, Emacs or Sublime Text: https://andrewbrookins.com/python/open-the-current-file-in-vim-emacs-or-sublime-text-from-pycharm/