How to connect Pycharm with microphone on macOS - python

I have a problem with my microphone connectivity using Pycharm.
I ran the below code on Spyder and terminal and they were fine.
However, on Pycharm, it seemed run without error but just without result as well.
I see that both my terminal and Spyder have access to microphone (system preferences -> security & privacy). If anyone knows how to trigger the system to allow microphone connectivity using Pycharm, any answers will be appreciated.
Thanks!
I also tried to record my voice using pyaudio and that worked fine with Spyder and terminal, but no audio was recorded if using Pycharm (though the file was created).
simple code:
import speech_recognition as sr
r = sr.Recognizer()
with sr.Microphone() as source:
print("Speak")
audio = r.listen(source)
print("Stop")
try:
print("You said " + r.recognize_google(audio))
except:
pass

Even though it is an older question, I stumbled upon the same problem under MacOS. So maybe someone can find this useful:
Problem is that every App running on recent MacOS versions needs permissions for security relevant services, e.g. recording from the microphone. Unfortunately PyCharm did not request the needed permission, and it is not possible to set the permissions by hand. Every app you build and debug with PyCharm does not have those permissions either.
Maybe Jetbrains did already fix this, so be sure to use the latest version. For me, a little workaround did the trick: Just start Pycharm from Terminal, as long as Terminal has the microphone permissions, everything works fine. I did it with a small script:
#!/bin/sh
cd /Applications/PyCharm\ CE.app/Contents/MacOS/
./pycharm

Make sure that PyCharm also has access to microphones in the settings, and also run PyCharm as administrator when launching it.

Related

Python 3.10 IDLE does not respond everytime I hit configure IDLE from options

I am a Windows 10 user, and had configured the Python 3.10 IDLE to dark mode and had added the Fira Code font to the IDLE a few days back (Through the Options menu). Then the Python IDLE was working fine; without issues.
However, each time after that when I try to go to 'Configure IDLE' from Options Menu, Python IDLE just freezes and then stops responding, until I manually close it. It then asks to run a Windows check and reports the error to Windows. I have tried uninstalling and reinstalling Python; however that did not work.
Image: Python has stopped responding (happens everytime I click on configure IDLE)
I am a Windows user and tried running python from cmd using the command: py -m idlelib to start IDLE from the command line to try and get an error report, however the same problem happens as mentioned above, and I do not get an error report when I close Python. I tried finding solutions in similar questions, however I did not understand what was going on. I also do not seem to figure out how 'running the Python IDLE' through the command line works, other than running it using the above command. Can someone please assist me on what to do next at this point, that would be of huge help :D
Try uninstalling the font. The Doesn't work part of the Editor compatibility list on https://github.com/tonsky/FiraCode includes IDLE. I suspect that the font is incompatible with tcl/tk. Your report is similar to
IDLE Settings window won't appear
See https://bugs.python.org/issue45103 for so far futile efforts to protect IDLE.
UPDATE: We were not able to reproduce the problem with FireCode. However, the BPO issue referenced above lead to a tcl/tk bug report that lead to a bugfix, at least for the Phaistos font, that is included in tcl/tk 8.6.12. This is included in the new Python 3.9.9 Windows installer and will be in the upcoming 3.10.1 installer. It might fix your issue with FiraCode.

Stop program from closing in python

So I made a program that uses the pyautogui module to type "Hello" over and over again in a while loop and press enter. It's not a console output. It works perfectly fine when I launch it from the pycharm editor but when I open it from the folder or convert to an exe it just closes instantly. Why does the program close when I try opening it from the file explorer or after converting it to an exe?
I'm new to python, thanks for any help!
import pyautogui
import time
message = "Hello"
time.sleep(5)
while True:
pyautogui.typewrite(message)
pyautogui.press("enter")
time.sleep(37)
After pressing Run I have 5 seconds to switch to a notepad and it will start typing "Hello" and enter every 37 seconds.
For anyone having the same problem on a Mac, you need to go to your security preferences.
Settings > Security & Privacy > Privacy > Accessibility
and allow that specific application to access your computer by pressing the + icon. However, in the question, you stated that you are using .exe files, so I will assume you are on Windows. I don't use Windows, but for people reading this question in the future on Mac, I hope this helps.
I have finally solved the problem!!
I ran my python script via the windows command prompt. The error it showed me was an error with a module named pyautogui. The problem was that my module was installed with the wrong version. Using "pip3" instead of "pip" install pyautogui fixed the problem for me and now I can open and use my script directly from the file explorer.

Python on Windows opens new window

Here's the problem, after installing Python (3.6, 3.7, 3.8) on Microsoft Windows when you invoke it, it opens in a new window.
This question has been raised before, and replies talk about modifying the code to pause the output or keep the program running so it doesn't close the window. I can not modify every python package ever made for windows compatability.
My problem is that this is not how Python works on *nix platforms. Surely there must be a way to get python to execute within a command prompt ?
My immediate issue is that I loose the console output on so many python programs. From Jupyter Notebook to AWS GRC (remote-codecommit).
-=-=-=-=-= ANSWER =-=-=-=-=-
After much frustration, it turns out the problem was related to account privileges.
The behaviour above occurred when a user with elevated rights executed Python.
When I log out and run with another user that is a local admin, it now behaves normally.
I cant tell you the exact difference between elevated rights and local admin, but there is something in the permissioning that effects how Python is run on Windows.
This happened to me when the current directory of the terminal didn't exist (was deleted/renamed after the terminal was started).
Solution: cd to some directory.
Find you python folder and select python.exe and create a shortcut for it.
Example Image
There's probably a better way, but this is a simple workaround.

How to run a python program using sourcelair?

I'm trying to run a python program in the online IDE SourceLair. I've written a line of code that simply prints hello, but I am embarrassed to say I can't figure out how to RUN the program.
I have the console, web server, and terminal available on the IDE already pulled up. I just don't know how to start the program. I've tried it on Mac OSX and Chrome OS, and neither work.
I don't know if anyone has experience with this IDE, but I can hope. Thanks!!
Can I ask you why you are using SourceLair?
Well I just figured it out in about 2 mins....its the same as using any other editor for python.
All you have to do is to run it in the terminal. python (nameoffile).py
Antonis from SourceLair here.
In SourceLair, you get a fully featured terminal, plus a web server for running your Python applications.
For simple files, as you correctly found out, all you have to do is save the file and run it through your terminal, using python <your-file.py>.
If you want to run a complete web server, you can check out our server configuration guide here: https://help.sourcelair.com/webserver/configure-your-web-server/
Happy hacking!

Python's (version 2.7.2) Idle does not execute any commands (command prompt works fine!!)

I'm trying to run python (version 2.7.2) on my computer (windows vista 32bit). It's always worked until now when Idle just does not respond to any commands.
Any commands entered (even very simple ones) have no output/do not get computed! See image:
Python works fine when I run it using command line though!
I've tried re-installing it a few times but it just doesn't help! Also tried running it from C:\Python27\Lib\idlelib\idle.py and I get the following message before the same unresponsive IDLE pops up again! See image:
Any help would be greatly appreciated.
Thanks
Try
print 1+2
You need to do something with the result.
A few suggestions:
IDLE starts a subprocess and connects to it over TCP port 8833. Is this port being blocked by a firewall on your computer?
Are there any files whose name clash with built-in Python modules? This page mentions problems with files called string.py.
Is the file config-keys.def under C:\Python27\Lib\idlelib missing or does it have its permissions set so that nobody can read it? I found that if I removed this file or restricted the permissions on it, IDLE became unresponsive as you described. If I then replaced it or reset the permissions, IDLE started working again. (Other config-*.def files in this folder might also need to be checked.)
This looks like the bug described here: http://bugs.python.org/issue14409
Your config file for key bindings is corrupt. Try renaming your ~/.idlerc folder to something else and restart IDLE.

Categories

Resources