I have to type in a terminal a user password. googling arround lead to getpass as the most recommended way to do it.
But, somehow- using this function did not hide the characters as expected.
First I thought it has somthing to do with the platform ( Pycharm ), but testing is on IDLE yield the same.
any ideas why ? (code below was on Mac using Python shell)
>> import getpass
>>> a=getpass.getpass(prompt='Password')
Warning: Password input may be echoed.
PasswordTHISISPASSWORD
if you will launch it from IDE it will cause echo will be seen. You can try it in command line terminal it works fine as can be seen in the attached screenshot.
hope this helps
I tried your code with a terminal and with PyCharm too, it works better in terminal but i found a checkbox in the run configurations of PyCharm that avoid the echoing of the password and set it correctly to the variable as you could see with the debugger, but i noticed that if you try to print the variable in some cases it prints something strange.
Click on Edit Configurations... on the left of the run button and check Emulate terminal in output console, it worked with the last version of PyCharm
EDIT: I read just now that you are using a Mac, I tried this with linux, so I'm not sure it will work on mac
In the latest version of Pycharm, all you have to do is update your run configurations.
Run> Edit Configurations> Enable "Emulate terminal in output console"
This enables your Pycharm output console to behave as the terminal. Then, the getpass() function works well without echoing your password.
Related
I am using PyCharm 2021.2.4 on macOS Big Sur 11.6 with my interpreter running Python 3.9
My PyCharm debugger console displays as read only without the command prompt. I need the prompt so I can set the proper variables when I launch the script.
Here's what my debugger console looks like:
Here's the prompt I'm expecting as per the Jet Brains documentation: https://www.jetbrains.com/help/pycharm/using-debug-console.html#open
So far, I have tried:
Verifying that "Emulate terminal in console output" is deactivated as per: https://intellij-support.jetbrains.com/hc/en-us/community/posts/115000244824-Console-toolbar-is-gone?page=1#community_comment_115000347810
Installing PyCharm 2020.3 to check whether an earlier version exhibits the same behavior (it does).
Creating a conda environment using Python 2.7 as the interpreter.
Resetting the IDE to its default settings.
And in case it's relevant, I'm trying to run construal_level_task.py which is the file in this repo https://github.com/UOSAN/high_level_construal
At the command line, the file is launched with this command: python3 construal_level_task.py --id ASH999 --run 1 --session 1 and those inputs (id, run, session) are the ones I'm trying to enter in the debugger console to run the script in debug mode.
The python program exited, so you cannot interact with the console any more. You need to set a break point in your code. Then the debug console will become interactive.
those inputs (id, run, session) are the ones I'm trying to enter in the debugger console
Using the debug console is not the right way to enter inputs from command line arguments. Instead, you should edit the run configuration and add them there. See Pycharm and sys.argv arguments for an explanation of how to do this.
I think the problem is that you use conda interpreter. Is there a need for this? You can try using pure interpretator.
EDIT: Try to use virtual using normal interpreter (not conda). Your mistake is conflicting copies of conda envs.
I need to clear the terminal in Pycharm without clicking the trashbin myself. I've tried using the whole os and csl thing but it only makes some weird arrow in the terminal.
The os.system command cannot work because it only executes commands in the Console. It won't work in many other places including IDLE's Python Shell, PyCharm, etc.
It should work in your Terminal. You can write your code in PyCharm and execute it in a terminal.
You can also use multiple \n, but it is not really what you want.
Another idea would be to add a keyboard shortcut.
You need to open Preferences, look for "clear all" and assign a Keyboard Shotcut, for example I put Ctrl+Alt+5 :
Keyboard Shotcut, Ctrl+Alt+5
Then you need to use it when you are inside the console,
I hope it helps,
Kind Regards,
Manuel.
I'm kind of new to software development. Outside of VSCode, I can open up a terminal (let's say PowerShell), run python in it, type in a command (like 2+2), be able to click the up arrow key to find my previous command so that I can run it again.
If I run PowerShell in VSCode and do the same thing, nothing happens when I click the up arrow where I would expect my previous command to be cycled.
Is this a problem with my Python or VSCode? I've been looking for a solution for this but haven't found many useful topics on this.
This was going to just be a comment but its too long. Sorry it isn't more informative than it is. This is kind of an odd problem because VSCode isn't a true IDE. It doesn't have its own shell and just hijacks your powershell or bash terminal, depending on which OS you are using. You should be able to use your up and down arrows just like you can in powershell. I have tested it on my own VSCode installation and it works fine for me. If it's a problem, it's not with python, since VSCode will interact with the terminal the same way no matter which language you are using it for, so its probably with VSCode or your terminal. I have heard of others having issues with up arrow autocomplete in bash, so if you are connecting to a bash terminal that could be it, but I've never heard of it glitching in powershell. I'd say check which terminal you are using, see if the problem persists when you change terminals, and try reinstalling VSCode if it does. Past that, I don't know what to tell you.
I found a work-around. For me, neither git bash, nor PowerShell allowed up/down arrows for history switching within a python shell. So here it goes.
Ctr-Shift-P opens VSCode commands
Python: Create Terminal does not actuallt start python, but it does launch powershell in a mode that will enable us to succeed
py starts python shell with working up/down arrows!
It seems that the spyder has removed python console, but I got a program can only be run by python console, what can I do? or is there any thing I am wrong?
I got some codes from github, and it needs ADB driver for Android, after I installed ADB, I can run the program in cmd using python wechat_jump_auto.py, but cannot run in spyder with ipython.
In Spyder3 installed in Windows OS, we can add the path to adb using Tools --> Current user environment variables....
Here, we can add the path to adb.exe file by appending it to the path variable. Then, we need to restart Spyder3. Then you will be able to directly run your script with access to adb.exe from Spyder3 IPython console or simply by clicking Run button.
Just came across the same problem as you recently.
In fact, it seems that program using ADB tools just cannot run in Spyder even by python console (my Spyder IDE is equipped with both Ipython console and Python console).
One practical way to solve this problem is to run your code in cmd.
Open your cmd window and do something like this:
python "xxx(path)\xxxx.py(file name)"
In my case, it looks like this:
example image
Hit Enter, and hopefully your code will run successfully.
If it still cannot run, maybe you haven't set your environment variables correctly.
Hope this can solve your problem. Good luck :)
Has anyone else ever had this error in PuTTy?
For example, pressing the Up Key now produces:
>>> ^[[A
Google doesn't let you search for special characters so I'm stumped at finding existing version of this problem.
EDIT:
So this happened after I pasted in some unicode (when, I think, the translation was already set to utf-8).
I've checked the Change Settings dialog box for different settings than my other open PuTTy windows, but the settings appear to be identical.
EDIT2:
This is fixed by restarting PuTTy, but still a nuisance.
EDIT3:
How to replicate the exact same bug:
Open a putty terminal to a linux PC (I'm using RedHat)
Open Python 2.7.* - using the command python2.7 (note: error does not appear in 2.6)
import codecs
Now use the arrow keys, and these bizarre characters appear.
In my experience that's because "bash" is not running. Simply run "/bin/bash" to enjoy colors, history and more.
I've found that specifying "The Function Keys and Keypad" option to match your operating system resolves many issues.
[Putty]
Terminal -> Keyboard --> RadioButton "Linux"
(if you're using Linux) and then you can start your session
You could try changing the 'Application Cursor Keys' mode. It's in the Terminal->Keyboard subsection of the initial configuration window (these settings may potenitally be overridden by your server).
http://the.earth.li/~sgtatham/putty/0.55/htmldoc/Chapter4.html#S4.4.4
Just run the simple bash command or sudo bash in ssh. It usually works.
For those interested in the issue, had same simptoms in a virtualenvironment, resolved the issue with
pip install readlines
See following answer for details.
Terminal >>> Local line editing >>> Force off
See also