I use IPython very frequently and happily. Somehow, cutting text from the shell using the keyboard shortcut, Ctrl + X, is broken. Actually, I have a few different installations of IPython. In some of the installations, the shortcut works; in the others, it doesn't work.
What might be the reason for this? Where should I look into?
You say you have multiple instances installed -- are these all on different machines? What operating system(s) are they running? If you access them remotely, what operating system are you running?
Do you get to them using ssh? Do you run something like screen, either locally or remotely, or both? There are lots of things that can interfere with your terminal settings, especially when you're working remotely.
I'm almost certain that iPython doesn't have anything to do with it -- though you might want to check the version numbers, to see if working and non-working environments are running different versions.
More likely, it is something in the terminal emulation layer, but you'll likely have to do some detective work of your own to find out what piece is causing it.
Take it one step at a time -- try to cut from a local shell, to make sure that works. Then connect to a remote machine, and cut from that shell. Start screen, if that's your normal way of doing things, and test from that shell. Then start ipython. If it stops there, then see if you can find another application on the same machine that's linked against gnu readline, and try that. You may find that none of the console apps cut proplerly on that machine, or you may find that they work, but not under screen. Or you may find that something in the terminal settings stops everything from working as soon as you ssh in.
You may also have some luck. if you can find out what terminal the remote machine thinks you are using ( echo $TERM ) by copying the termcap file from a working machine to one that doesn't. That's a bit more involved for these forums, though -- I'd repost at that point on serverfault.com or superuser.com
I hope that at least gives you a starting place -- terminals are finicky, and difficult to get right. Most people seem to not bother, as long as everything mostly works.
Related
I have a bunch of python script that run on a scheduled basis in a windows 10 based system, sometimes after windows 10 automatic update, the OS will ask for a restart to finish the update and after some time it would restart automatically if not done manually which might mess with automated python script runs.
I am looking for a pythonic solution where I would query the OS if it needs a restart and upon getting the appropriate response I would trigger the appropriate solution
import necessary_libraries
isRestartRequired = check_if_restart_is_needed() // returns true or false
if isRestartRequired == True:
notifyUser()
Is this programmatically possible with python?
The following seems to work for me:
Install the PowerShell script Reboot pending:
Install-Module -Name PendingReboot
Check it works in Powershell:
Test-Pending Reboot
Call it from python using:
import subprocess
def restart_needed()->bool:
"""Uses Windows Powershell tool to figure out if a windows
reboot is pending. True indicates one is due."""
cmd:list[str]=["powershell","-Command","Test-PendingReboot"]
res:bytes=subprocess.run(cmd,capture_output=True)
output_text:str=res.stdout.decode("utf-8").strip()
restart:bool=output_text.endswith("True")
return restart
I personally don't think there is a dedicated library for that. I also don't think you should check that for updates individually, as that will likely require searching for the information about each and every update online (https://learn.microsoft.com/en-us/answers/questions/308547/how-to-know-if-a-windows-update-will-require-a-reb.html).
So you'll likely have to figure out a way how to determine whether Windows is going to reboot or not, and then manually perform that check (by running a system command or utility) in Python. Now your question sounds more like "Which mechanisms Windows use to reboot the machine during the update, and how to check whether any of them is invoked". Please note that there might be a bunch of such mechanisms, and they are most probably undocumented and may change in future. You can learn the basics on MS website, but they don't provide good amount of details there (https://learn.microsoft.com/en-us/windows/deployment/update/how-windows-update-works).
You can check the list of possible reboot status locations in How can I check for a pending reboot? (it looks quite promising), and implement these checks in Python afterwards using some function that allows you to check the output (Running shell command and capturing the output).
If you decide to use that approach, please capture a PC that requires a reboot and verify that one of the 4 sources mentioned in the answer indeed contains the reboot flag. I did it for my laptop yesterday - it was pending reboot, and some entries indeed contained that marker. Make sure you check that for your infrastructure as well.
P.S. If you have full control upon your entire infrastructure, you might look into PowerShell Gallery PendingReboot module mentioned in the referenced SO post (if it's installed on the machine, you can use just one command instead of four), or make yourself familiar with brilliant (and completely useless probably) opinion of MSDN guy https://devblogs.microsoft.com/oldnewthing/20151203-00/?p=92261 : In this specific case, the idea would be to change the design from “Install the update, and then postpone the reboot until a convenient time” to “Wait for a convenient time, then install the update and reboot immediately.”
I'm lost with Python. After troubleshooting with a friend through Discord for literally months I am about to give up. This is my last attempt at trying to get Python fixed on my Windows 10 laptop.
I'm using a Lenovo Legion 5, bought the laptop in November 2020. I've not been able to get anything related to Python to run in the CMD window. I can run Python no problem, but nothing I have installed through pip has ever worked. I can use virtualenvs, but only through PyCharm for example. Python has never really worked through the command line.
Yes I tried reopening the CMD window, rebooted the system many times, ran the CMD as administrator, installed the path variables for both Python and esptool.py but nothing seems to help.
I honestly don't know where to start because none of the 250+ websites I've visited to so far that suggested a fix for any kind of issue I've been experiencing with Python has been working. I can run Python fine by the way, just none of the things installed through pip will work.
Let's start with a use-case:
I'm trying to run esptool.py so installed it with pip install esptool. This install worked fine, and I can confirm it is installed with pip show -f esptool.
However, when running esptool.py version it told me:
'esptool.py' is not recognized as an internal or external command, operable program or batch file.
So I added the local folder from the previous step to the %PATH% variables, after running esptool.py version it gave me a popup asking me with what kind of program I should open this, I didn't select to open with this kind of program from now on. This makes it so that I do not get an error, what now happens is that another window quickly opens and then exits without an error code. So I have no clue what's happening.
What should happen is that it should tell me which version is installed in the CMD window.
There have been a few other things going on with my Windows 10 install, for one, the username that I used during the installation wasn't used to create the user directory. Windows 10 somehow instead chose a name that was related to the first 5 characters of my email address, which is totally strange as I haven't used that string in the installation of Windows 10 at all. This was a fresh install on a new laptop.
Now, after an update of Win10 my user icon doesn't display anymore and I had to change ownership of the 'Windows Apps' folder in order to be able to access it. Changing the ownership also changed the name I now see on the login screen when I boot up the laptop. It changed from the 5 first chars of my email address to my full name in the login screen, only because I took ownership of this folder so I could access it.
There have been a lot of things going on that I think should not be changing all the time, things to do with administrator rights, ownership, etc.
Now, since opening esptool.py doesn't open it, but also doesn't show me an error, I'm clueless and the only thing I can think of is doing a fresh system install, but I have a bunch of projects going on for which I need this laptop in working order and I don't have the mental health (due to corona) left to do a fresh system install. I'm worn down. Not in a dramatic way, I just don't have the spare energy to go through the whole process. So I'm hoping someone can point me in the right way to troubleshoot why my Python doesn't want to work natively.
What happens when running esptool.py version is that I can see it opens a Python window, but without showing any content it closes within a few milliseconds.
What is going on, how do I continue? I hope someone knows how to troubleshoot my system, to find the core of the problem.
It apparently was rather simple. First of all, thanks for the replies! And second of all, thanks for pointing me to superuser.com I wasn't aware of the site and will continue there.
The fix was to use python -m pip install esptool as suggested by Valentin Kuhn.
To answer AKD, I have a lot of experience with programming on my MacBook, but I'm not experienced with actually maintaining the system side, I'm a creative user. It's just that ever since I got a Windows laptop it's been nothing but trouble and after months of chatting about each individual issue with people on Discord nobody has been able to find a solution. I'm not expecting a GUI, just a simple "esptool.py v3.0" was the answer I was expecting from the command line.
Now what I don't understand is that I've never found any hint to anyone suggesting python -m. I will get on superuser to find out more about why the standard instructions that work for most people, don't work for me.
Sorry for using the wrong site for my question, I came on here through another related question and it was past my bedtime and I wasn't thinking clear.
I'm using mac osx mavericks (fully updated) and while looking for a pyscripter alternative, I decided to download CodeRunner from the app store.
I've noticed that certain programs I create in one application, don't always run the same in the other environment.
For example, there are times when I create a program using CodeRunner, but when I open the exact same program in the IDLE environment, it spits back an error. Usually complaining about the syntax or logic of the program. And the other way around can sometimes occur as well.
Is this normal behavior? Should I be saving the program in a different format? I assumed that since I'm coding in Python, the code would behave the same regardless of the environment I use.
The different programs probably have different definitions of tabs and whitespace.In IDLE, you can use Format->Tabify/Untabify menu options to change between tabs and spaces. When you click on these menu options, you prompted for the columns per tab, which will default to 4(At least on my machine). Hope this helps!
I was wondering how I could run a quickly application using pycharm. The way which I would hope to do it is instead of saying:
$ quickly run
In the terminal, I would Hope that I could instead just say something like
$ python bin/myapp.py
(That is the suggestion here, but it doesn't seem to work for me). That would mean I wouldn't have to do any weird setup on the python interpreters. However, if I need to, I can adjust pycharm's settings.
Ok, I found the answer when looking to add an interpreter. go to run > edit configuration.
I don't know if this is necessary, but I just set the working directory for the project interpreter to be the application one (it might do this by default).
Down below that, there is a place with a + icon above it. Click there to add an external tool.
The necessary settings for that tool is program: "quickly" and parameters: "run" (both without quotes).
Again, I'm not sure if it's nessecary to set the working directory here, but I did it just to be safe.
I wrote a small app and I am using pynotify to show some messages to the user.
It all works fine here in arch, but when I tested it in Ubuntu, the behaviour was very weird.
Because of the way Ubuntu shows notifications (as what seems to be a rip of of growl), I can't click on them, or interact with them in any way, for that matter.
The biggest problem, however, is that it only shows one notification at a time, and has to wait (a long time, by default) untill one of them goes away to show the next one.
Given the nature of the little app I'm writing (a simple monitor that runs a command every time a file is changed), the results must appear to the user in real time.
I have tried to set a small timeout with message.set_timeout(), but Ubuntu just seems to ignore it.
--
So, here is my question: Am I the only one to notice that? Am I doing something wrong?
If not, is there any way to change that behaviour in Ubuntu? Any workaround?
Thanks in advance for your time
Yes, Ubuntu 9.10 replaced upstream's notification-daemon with their own notify-osd, and generally made a mess of things.
You can ensure notification-daemon is installed (via whatever your favorite package manager front-end is) and use it in favor of notify-osd:
$ sudo mv /usr/share/dbus-1/services/org.freedesktop.Notifications.service /usr/share/dbus-1/services/org.freedesktop.Notifications.service.disabled
$ sudo mv /usr/share/dbus-1/services/org.freedesktop.Notifications.service.notify-osd /usr/share/dbus-1/services/org.freedesktop.Notifications.service
Unfortunately this will get overwritten whenever the package is updated... it's already using a dpkg-diversion so it's hard to re-divert it permanently.