Speed up Pytorch Debugging
Tick on the Settings -> Build, Extension,Depolyment -> Python Debugger -> Gevent compatible
to make debug on pytorch code (GPU) fast.
Speed up Visiting Externel Packages
Settings -> Python Interpreter -> Show All -> Show path for the selected interpreter -> Add (path to the package)
. Then this path will show in you project structure (in Externel Libararies
).
Useful short cuts
Help -> Keyboard shortcuts PDF
to get the shortcuts cheat sheet.
Ctrl + Shift + F
: Search in project.
Ctrl + P
: Show parameters hints. (cursor in function parentheses)
Ctrl + D
: Copy and paste a new line.
Ctrl + Alt + L
: Reformat code. Auto-fix space, indent, …
Ctrl + Alt + Shift + L
: Reformat code dialog. Reformatting with options, e.g., enable imports optimization.
Ctrl + Alt + O
: optimize imports
Ctrl + LeftClick
: Go to function file.
Shift + Enter
: Go to next line.
Resolve updating index forever
Commonly it’s because you put datasets under the content root of your project. Pycharm takes forever to index these millions of images… Right-clik the datasets folder and Mark Directory as Excluded
will help. If still not help, try adding the regex-file-name (e.g., *.jpg) or folder-name (e.g. data) into the Settings -- Editor -- File Types-- Ignored Files and Folders -- + -- <subdirectory/filetype-that-you-want-to-ignore>
Remote development
The older solutions:
- File synchronization: Useful when you are in favor of
- Editing codes in PyCharm.
- Manualy/automatically synchronize the changes to the remote project directory.
- Running the codes in a remote terminal (SSH connection).
- Remote interpreter: Useful when you are in favor of
- Editing codes in PyCharm.
- Automatically upload the local project directory to the server at customized-location/tmp (Unseen).
- Running the codes in PyCharm with remote backend.
The two solutions are quite similar. I prefer the first one because it’s more safe and the codes on the server are better organized.
File synchronization
Create a development
configuration (Tools --> Development --> Configuration
).
You may need set a new SSH
configuration:
Configure Mapping
to map the project path:
Configure Excluded Path
to specify paths on client/server that will NOT be synchronized, e.g., directories of datasets and saved results on the server.
After the configuration, you can now synchronize the codes by uploading/downloading files between the client and the server. (You may configure an auto-sync as needed).
Remote interpreter:
- You may use the command
which python
(afterconda activate target-env
) to get the python interpreter path of an exsitingconda
environment. - You may custom the
sync folder
of client and server. For example, by default, PyCharm will upload all files in current project on client to the server with path/tmp/pycharm_project_xxx
.
A new solution (Remote development)
The major advantage of it is that there is no files hosted in local machine and meanwhile you can edit and run Python in a PyCharm windows with remote backend. However, it’s currently (2023-03) a beta function and may suffer from the network latency.
This solution is close to the TeamViewer, but it does NOT transfer Graphic Information between the client and the server. Instead, it transfers the operations of PyCharm. Therefore, it will download an extra Pycharm software in local machine (unseen) that has the same version with the server. For more details please refer to the doc
You may need set a new SSH
configuration:
Do not click any bottom multiple times but instead click once and wait …
Finally, you can edit and run codes in the pop-up PyCharm window, which can be regarded as the Pycharm opened on the server.