Pycharm detection [duplicate] - python

This question already has an answer here:
How to check if python unit test started in PyCharm or not?
(1 answer)
Closed 6 years ago.
I want to know whether python script is started from PyCharm. Next string
in_pycharm = 'original_argv' in dir(sys) and 'pydevd' in sys.original_argv[0]
works ok for Debug and don't work for Run.
Can anyone recommend me better way?

Simplest solution is probably to have pycharm specify an environment variable, something like INPYCHARM=1, then check os.environ.get('INPYCHARM')==1. You can specify the environment variable in the Run/Debug configuration menu (from the Run drop-down menu).
Edit: Looks like PYCHARM_HOSTED is specified in os.environ by default, so the following should work (tested on pycharm 5.0.4).
in_pycharm = 'PYCHARM_HOSTED' in os.environ

Related

What does TERM environment variable not set mean? [duplicate]

This question already has answers here:
How to fix "TERM environment variable not set" when clearing console using Python code?
(2 answers)
Closed 12 months ago.
I am new to python, I was trying to clear the console and I got this message 'TERM environment variable not set'.
I found ways to fix the issue online but I couldn't find an explanation for what it actually means.
$TERM is an environment variable, meaning that it is maintained by the OS, and shared between programs, rather than just belonging to your own program.
In this case, $TERM represents the type of terminal your program is running in. For example, when I run echo $TERM in a terminal, I get xterm-256color as output. Presumably, the clear command you're using checks what terminal is being used in order to figure out how to clear the terminal (since different terminals might do so in different ways).

Adding a run configuration in PyCharm for a python project [duplicate]

This question already has answers here:
How to set default PyCharm interpreter?
(7 answers)
Closed 1 year ago.
I opened a series of files to edit them and my run button is greyed out. I can't figure out exactly why, but I think it has something to do with the "add configuration" prompt nest to the run button. I don't know how to add a configuration and don't want to mess up my editor. I have the newest version of the community version of PyCharm.
Add Configuration is greyed out because maybe you haven't added python path to the project try adding it and you should be clear before posting questions maybe some code and pictures will help. Try this and let me know if this have solved your problem.

Pycharm not importing standard library [duplicate]

This question already has answers here:
Difference Between Python's IDLE and its command line
(4 answers)
Closed 1 year ago.
But they work just fine in IDLE. For example,
import time
time.asctime()
works fine in IDLE, but is not working in Pycharm.
I have tried changing the interpreter but still doesn't work. Other packages that I installed myself from cmd like numpy are working fine.
Any help will be appreciated
EDIT : When I add the package time by pressing + in the interpreter settings, it says
ERROR: Could not find a version that satisfies the requirement time
If you get no error message, and you have shown us your whole program then your problem is that you are expecting time.asctime() on its own to produce output the way it does in IDLE.
But to get the same effect in a program that PyCharm runs, you need something like print(time.asctime()).
To get PyCharm to do what IDLE does in this case, you need to ask PyCharm to open a Python console.

can we access a python console in a terminal via an interruption within the python script for debugging [duplicate]

This question already has answers here:
How to step through Python code to help debug issues?
(15 answers)
Can I put a breakpoint in a running Python program that drops to the interactive terminal?
(6 answers)
Closed 2 years ago.
To clarify my question, for example in some IDEs such as PyCharm one can put a breakpoint in the code, run the python script and when the code reaches that breakpoint, the program stops while the user can investigate some of the variables until that breakpoint.
Is such functionality possible through a terminal, that is executing a python code but while having it stopped at a certain line, a python console would be available for debugging.
Yes, you can use builtin Python Debugger import pdb; pdb.set_trace() as a one-liner to get full access to the current scope you are in, ability to call any functions, step through code, display values etc.
There's also https://pypi.org/project/pdbpp/ which needs to be installed separately. It has all the features that pdb has and then some.
i think that is not possible if u are running it in just the terminal.
if u want to investigate variables and stuff at a certain point, maybe u can simply just code lens

VS Code - can you display a Python shell [duplicate]

This question already has answers here:
How to execute Python code from within Visual Studio Code
(34 answers)
Closed 4 years ago.
When using Python IDLE I find the Python shell, with the >>> prompt very useful for testing syntax. Is there a way of getting a Python shell integrated in VS Code?
Maybe the answer is just to open Python IDLE in another window.
Apparently this is a duplicate of another question, but I did several searches on the words Python shell and didn't find anything that seemed relevant. Sorry.
Many thanks to Jaxi for the answer that you need to type Python in the Terminal Window.
stated here you can use ctrl+backtick to open a terminal window, then from there just type python and it will give you the python shell:
https://code.visualstudio.com/docs/editor/integrated-terminal

Categories

Resources