Pycharm not importing standard library [duplicate] - python

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.

Related

Pycharm "Unable to create process using" [duplicate]

This question already has answers here:
PyCharm always thows this error on creating new project and interpreter(virtual env) is missing for the project
(2 answers)
Closed last year.
Last week I tried to run my python file and it work fine but when I tried it today it gave this error:
Unable to create process using 'C:\Users\Programmer\AppData\Local\Microsoft\WindowsApps\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\python.exe C:/Users/Programmer/PycharmProjects/help/V1.1.py'
It also exited with code 101.
I tried updating pip but It didn't do anything.
You'd better check the interpreter version you're using. If you are using PyCharm, you can choose File -> Settings -> Project: prjectName -> Porject Interpreter. Finally, select the desired Python version number from the Porject Interpreter drop-down menu on the right side of the window.
I know is old, had the same problem, for me it work to run the Pycharm as Administrator.

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

Clearing the screen of IDLE interactive mode [duplicate]

This question already has answers here:
Any way to clear python's IDLE window?
(23 answers)
Closed 2 years ago.
Can I clear the screen of IDLE interactive mode in Windows? I tried with the following code which fails to work:
import os
os.system('cls')
The cls command works only in Windows terminal(command prompt) and it doesn't work in IDLE screen.
Is there any other way? Or first of all, is there any hope to clear that IDLE interactive mode???
cls and clear are commands which will clear a terminal (ie a DOS prompt, or terminal window). If you are using the shell within IDLE, which won't be affected by such things, a workaround might be to print a lot of empty lines with print("\n" * 100). See also this answer for more information.
No, it is not possible, neither in IDLE, nor in Python command prompt.
Use IPython instead with its “magic” command %cls (and many others), preferable as a part of some IDE which utilized it, for example Spyder, PyCharm or JupyterLab.
Anaconda contains both Spyder and JupyterLab and many Python packages, it's probably the best all-in-one solution.
You can from os import system and then system("cls")
this will just clear out the screen. have fun coding:).

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

Pycharm detection [duplicate]

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

Categories

Resources