在菜单栏选择"File | Settings", 在弹出的Settings窗口中选择"Editor | File and Code Templates | Python Script", 在右侧键入以下内容:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
@file : ${NAME}.py
@path_to_file:
@author : ${USER} hc-y
@date : ${YEAR}/${MONTH}/${DAY}
@contact : ***@gmail.com
@brief : 简介or简述创建该文件的目的
@intro :
@relatedfile: 有关联的文档
file_001.py
file_002.py
@annotation: hc-y_note:, hc-y_Q:, hc-y_highlight:, hc-y_add:, hc-y_modify:, hc-y_write:,
"""
"""
运行该脚本文件时的命令行打印输出
"""
-Pycharm创建文件模板_小郑要飞飞-CSDN博客_pycharm如何创建js文件 20160313
-pycharm File and Code Template设置_nathan8的博客-CSDN博客_pycharm file and code 20180505
"""
# hc-y_Q0817
# hc-y_modifybug
# hc-y_note_un:加了后缀_un表示"好像是,大概是,有待进一步核实"
# hc-y_note:完善注释/修改注释/新增注释;
@license : Licence
@site : ${SITE}
@software: ${PRODUCT_NAME}
@time : ${DATE} ${TIME}
@time : ${YEAR}/${MONTH}/${DAY}
"""
Code is copied from xxx/xxx/xxx.py def xxx().
Code is modified from xxx/xxx/xxx.py def xxx().
Code is created by hc-y_write1006.
hc-y_note0430:common op
'common op'表示常用操作, 供读写代码时参考;
hc-y_note0503:shape e.g,
'shape e.g,'表示在当前模型超参数设置下, Tensor的shape; 便于理解代码;
'# mark_record'位于adet/utils/comm.py脚本文件头部和尾部, 便于核查是否拷贝;
Ctrl+Alt+L
。Online Python Compiler - online editor
We can tell debugger when to pause a program by setting breakpoints.
To set a breakpoint, click on blank area seen on left side of line number in editor. When you click it, it should display red circle; which means breakpoint is set on that line number. Here is image of how it looks like.Once you set breakpoint, when you start program in debug mode, it will pause execution when program reaches the line where breakpoint is set.
Now we can use stepping commands to execute program line by line.
- continue – Resume program execution until next breakpoint is reached
- step into – Execute program line by line stepping into function
- step over – Execute program line by line but don’t go inside function call
- step out – Resume program execution until current function is finished
打开终端,键入命令ifconfig
,找到打印输出中的“inet addr: 211.67.33.208 Bcast: 211.67.34.255 Mask: 255.255.252.0”。
在菜单栏选择"Tools | Deployment | Configuration", 点击左上角的"+" Create new server, 输入你给即将要连接的服务器所起的别名; 然后,
操作参考:Project Interpreter | 略 | SSH Interpreter | 略 |
在菜单栏选择"Run | Edit Configurations…"打开"Run/Debug Configurations"窗口后, 可以指定不同的Python interpreter;
如果要运行GPU程序, 则有时可能需要将CUDA路径添加到环境变量(Enviroment variables)中;
在本地编辑好脚本文件后, 需要先将其upload to远程服务器, 再运行;
如果通过上面的配置进行远程调试的话,我认为大致流程应该是下面这样:
- 在RemoteHost面板中,选中想要修改的代码,然后右键点击Download from here将内容下载至本地(这个本地是你在配置Mappings时设置的本地文件夹);
- 在本地(这个本地是你在配置Mappings时设置的本地文件夹)修改你的代码,修改完成后在编辑区域或者文件名上右键,选择upload to…来提交到服务器;
- 在提交之后,你可以像普通调用本地解释器一样的直接运行本地的这个文件(但其实运行的是服务器的文件);
- 在这里,虽然RemoteHost里的文件可以直接编辑,但是并不建议这么做,因为这里编辑之后并不能直接运行;
问题描述与解决方案:
在本地修改了某个脚本文件, 并upload to远程服务器之后, 如果运行/调试时仍然follows the logic of the old code, 可以试试"File | Invalidate Caches / Restart …";
在菜单栏选择"Tools | Deployment | Browse Remote Host", 可以打开相应的Remote Host面板,这个面板显示的就是远程服务器上的文件,显示的范围是你在"Tools | Deployment | Configuration"选项卡下配置的Root path路径下的文件;
在菜单栏选择"Tools | Start SSH session… | Select host to connect",选择远程服务服务器,便可在PyCharm自带的Terminal中进行远程服务器的终端操作。
问题描述:
开始
原因分析:
开始
解决方案:
开始
问题描述and原因分析:
用PyCharm打开项目时,Indexing需要很长时间的原因之一是项目工程里包含了很多的程序文件以及数据文件;
解决方案:
解决方案是把某些程序文件和数据文件所在的文件夹设置为Excluded,也就是不把这些文件夹包含在项目工程内;操作方式一:在菜单栏"File | Settings… | Project: | Project Structure"中,点击右边的"+ Add Content Root“号,将不想索引的文件夹Mark as Excluded即可。操作方式二:直接用鼠标右击某个文件夹,选择"Mark Directory as | Excluded"。
打开PyCharm之后,下方一直在index,以及一直Updating中的问题_希望之下的博客-CSDN博客 20190425
20200906
问题描述:
如题,例如Debug时访问的却是C:/Users/usrname/.PyCharm2019.2/system/remote_sources/-1468910861/-416239508/mmcv/runner/epoch_based_runner.py这种远程端在本地的只读缓存代码。
原因分析:
system/remote_sources/路径下存储的是project解释器中安装的包的一个local副本, 即从远程解释器环境派生的只读缓存代码, 由于"mmcv library"是以Python site-packages的形式安装的, 所以对C:/Users/usrname/.PyCharm2019.2/system/remote_sources/-1468910861/-416239508/mmcv/runner/epoch_based_runner.py的内容修改并不能更新远程服务器/home/usrname/miniconda2/envs/cy_mmlab/lib/python3.8/site-packages/mmcv/runner/epoch_based_runner.py中的相应内容;
python - Pycharm debugger: breakpoint links to remote_source files - Stack Overflow 20191004
***20190513 Sergey Karpov: I couldn’t reproduce it. Did you install your modules as editable to your interpreter? remote_sources are the packages installed to your project interpreter and downloaded by PyCharm to have a local copy of them.
解决方案:
要修改远程端的代码时, 有三种方式:
cd /home/usrname/miniconda2/envs/cy_mmlab/lib/python3.8/site-packages/mmcv/runner
vim epoch_based_runner.py
在line29和line30之间插入以下代码: # c-y_add20200904: record data:
for img_id in range(data_loader.batch_size):
data_batch['img_metas']._data[0][img_id].update(dict(mode=self.mode, epoch=self._epoch, img_iter=self._inner_iter, total_iterations=len(data_loader)))
在line125和line126之间插入以下注释:
# how does the code jump to [self.val()] evaluate the model on the validation set per 2 epochs?
# evaluation = dict(interval=2, metric='mAP') c-y_Q20200908:每2个epoch后, 是如何跳转到self.val()执行val的?
在line50和line51之间插入以下代码: # c-y_add20200908: record data:
# assert self._epoch < 1, 'record data, have finished one epoch!'
***20190719 Alexleviyev: Having the same problem with WSL. I’m trying to modify a library that’s not meshing well with my code, but the debugger uses a cached version of my library after I edit it while using the debugger. No fix found yet?
***20190723 Alexleviyev:
@Andrey-Resler Yes, I did. Unfortunately that didn’t work either.
I found a hackey solution that might be useful for people. Basically, edit the temporary file. Then open the terminal and run the script I posted below. The idea is that you replace the actual library file in your filesystem with the temporary one you’re editing after you make your modifications. It solves the most annoying problems and makes the workflow as you’d expect it for the most part. This is WSL specific solution, but I’d expect if you’re working on a remote server the same idea would apply. Make a script that transfers the edited file to the remote before you launch your debugger every time and you should be golden.
The problem I’m running into now is that I can’t open projects that are located purely in WSL, and not on my /mnt/c/ directory. VSCODE seems to work, and I can call pycharm on anything in /mnt/c, but not in WSL. This makes it so that even though I can edit through some temporary files and continue with my debugger remotely, as soon as I try to get into a file that isn’t in my temporary directory the debugger stops . Any suggestions on how to handle that? If so, that would essentially provide a workaround for this bug in practice until a more concrete fix is presented
#!/bin/bash
# Used to push modified library files to remote_resources
# Will allow faster debugging of external libraries with pycharm
bilby='/home/alex/anaconda3/envs/myenv/lib/python3.6/site-packages/bilby/gw/'
pycharm='/mnt/c/Users/Alex/.PyCharm2019.1/system/remote_sources/1045508341/555082905/bilby/gw/'
# Files to forward
file1='utils.py'
# Copy over the files
cp $pycharm$file1 $bilby
问题描述:
Python Console中的python环境。
原因分析:
通过PyCharm自带的Terminal进入的python环境 和 Python Console中的python环境 是不同的,得看它们各自使用的是哪条路径下的python.exe解释器。
创建一个PyCharm项目时,可以根据需要自行选择确定“Project Interpreter”,以避免相关依赖包的版本冲突。
解决方案:
在PyCharm中安装依赖包时可以采用以下方式:a.进入"File | Settings | Project Interpreter"里面,点击右边“+”号,搜索“Available Packages”并安装;b.在PyCharm自带的Terminal中,使用命令安装;
问题描述:
PyCharm中,Debug模式下,Debugger | Variables无法显示"frame variables",Console | Show Python Prompt也无法打印输出"frame variables"的相关信息。
原因分析:
无
解决方案:
在PyCharm中打开File | Settings | Build, Execution, Deployment | Python Debugger, 勾选Gevent compatible;
debugging - Why does PyCharm say “Unable to display frame variables” in debug mode? - Stack Overflow 20161129
问题描述:
pydev debugger: warning: trying to add breakpoint to file that does not exist 20171129
数学公式粗体 \textbf{} 或者 m e m o r y {\bf memory} memory
数学公式粗斜体 \bm{}
摘录自“bookname_author”
此文系转载,原文链接:名称 20200505
高亮颜色说明:突出重点
个人觉得,:待核准个人观点是否有误
分割线
分割线
问题描述:
原因分析:
解决方案: