Knowledge summary of programming tools

vscode

Add parameters (args) when vscode debugs python code

https://blog.csdn.net/zk0272/article/details/83105574
Add a lanch.json file under the .vscode folder, the content is as follows:
{ // Use IntelliSense to learn about possible attributes. // Hover to view descriptions of existing attributes. // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 “version”: “0.2.0”, “configurations”: [ { “name”: “Python: current file", "type": "python", "request": "launch", "program": "${file}", "console": "integratedTerminal", "args": [ "–train", " ./data/ResumeNER/train.char.bmes”, “–dev”, “./data/ResumeNER/dev.char.bmes”, ] } ] }

















The relative path of vscode

https://zhuanlan.zhihu.com/p/159435958
1. If you are using the F5 debugging that comes with vscode, you can modify the launch.json file in the .vscode directory and add "cwd": “${fileDirname }"
insert image description here

Vs code runs python to import the upper-level directory module import failure problem, prompting No module named 'xx'

pycharm

This problem is easy to solve for pycharm:
just set the path of workspace or src root in pycharm.
insert image description here
insert image description here

The solution in vscode

Subdirectory python/test_relative_path
root directory python

hello.py is under the subdirectory test_relative_path.
hello.py under the subdirectory directly imports testPP3 under the root directory, and an error will be reported as no module name testPP3

Print os.getcwd() to find that the current execution path is the root directory python

Printing sys.path shows that there is no root directory in the path, only subdirectories are saved

So you need to add the root directory to sys.path, and then the files in the subdirectory can import the modules defined in the root directory.

import os
print(os.getcwd())

import sys
print(sys.path)

sys.path.append(os.getcwd())

insert image description here

References


Vs code runs python to import the module of the upper directory

(46 messages) python import problem: absolute path, relative path, sys.path.append_weixin_44546620's blog-CSDN blog_sys.path.append relative path
https://blog.csdn.net/weixin_44546620/article/details/ 104755730

(46 messages) vscode imports its own py file, its own library/package_Wuli_jiejie's blog-CSDN blog
https://blog.csdn.net/Wuli_jiejie/article/details/118703169

VSCode - How to set debugging working directory - VoidCC
http://cn.voidcc.com/question/p-dbcjrrif-qp.html

Guess you like

Origin blog.csdn.net/xyl295528322/article/details/116206882