How can I make sure the windows update package installed successfully - python

I write a code in python that simulates a Windows Update installation.
the code is below:
subprocess.call(["c:\Windows\System32\wusa.exe","C:/Users/adib/Downloads/WindowsUp.msu", "/quiet")
Now, I would like to know when the installation over and make sure the update ran successfully..
how can I do that through the script?
thanks!!

Windows update has a COM API that can be used to scan for and install updates. VBScript is listed as explicitly supported; python may also be able to access COM interfaces. Detailed examples in VBscript can be found in Microsoft's documentation.
For more information You should take a look at this topic: Download / Install Windows Updates from Python

Related

Portable Python/IPython

I am currently starting a business where I will be providing support to clients directly on their business offices. I need to be able to go to different computers and be able to run custom python scripts, my question is if there's a way to make my python environment portable?
Assuming that your users are running Windows, I see two options here.
If you have already defined which scripts you will be running, compile them into exe files using py2exe, that way you can just plug a USB and run them as needed. (the caveat is that some antivirus will automatically block the unsigned executables)
The other option is to use WinPython, that is a full python environment with a lot of packages already preinstalled that ives in it's own directory. In case you need to install a new package, just use the Powershell or CMD that comes with it and use the preinstalled "pip".
I found something interesting here Portable Python. I use that method to create portable Python 3.9 and 3.10 and everything works so have a look.

How do I get Python code to run in RStudio? No Python installed in the system

I'm working on a research project where the data is stored in a remote Windows desktop. The desktop does not have Python, it only has Rstudio, but most of the research conducted in this topic was in Python. I want to benchmark already existing implementations, but I can't run the code on the data because there's no Python and this will not change. As far as I understand, tools like reticulate still need an underlying Python interpreter in the system to work and I am not allowed to do that.
Has anyone come up with a smart solution that does not involve me manually translating the python code to R? Any R packages that can read python? Any other out-of-the-box ideas on how to get that code to run on the data?
Can't install Python on Windows? Just Use WinPython
WinPython is a free open-source portable distribution of the Python programming language for Windows 8/10 and scientific and educational usage.
Since it is portable, it is a zero install option. This is probably the best option for you.
https://winpython.github.io/
Once you have WinPython on the machine, if you want to use it with RStudio, you'll need to configure reticulate to use it.
Say you have (1) the remote Windows Desktop that does not have Python and (2) the local computer you work on.
Use the remote Windows Desktop (1) as a git repository, clone that repository on your local machine, make changes to it and run locally using Python, then submit the code to the remote repository again.

How do I check what's going on after every instruction at runtime?

I'm new to the whole IDE thing. I code on competitive coding websites and practice there.
So my question is, what tools are available to check what variable holds what at each instruction during runtime and where the program flow is, in order to debug?
I have VS code installed idk if it has that feature.
If You're using Python. Then in order to be able to debug Your program You would need to:
Install VS Code Python extension
Visit the official Debugging documentation provided by the extension Official Debugging documentation
But If You're debugging a single file and You installed the Python support for VS Code it should be as simple as pressing F5 to start debugging.
Please note that if You require any packages installed in order to perform successful debugging You either need to create a Virtual Environment using Python venv and activate it everytime You work on a specific project. Or You can install the packages globally (which is not ideal)

How to install Polynote on Windows?

I've been searching around the Internet for a while but I have not been able to find detailed instructions on how to install Polynote (The polyglot notebook
with first-class Scala support.) for Windows with mixing multiple languages, Python and Scala.
Github Link for Polynote.
Official Website.
According to Official Website:
Polynote is currently only tested on Linux and MacOS, using the Chrome browser as a client. We hope to be testing other platforms and browsers soon. Feel free to try it on your platform, and be sure to let us know about any issues you encounter by filing a bug report
I would really appreciate it if anyone here can share his/her method if he/she
had successfully installed Polynote on Windows, either from Virtual Machines
(VMware/Virtualbox) or directly.
You could install Polynote on Windows with Ubuntu's subsystem for Windows. To do that, you have to:
Enable Windows Developer mode: Settings > Update & Security > For Developers > Developer Mode.
On Windows Features turn on Windows Subsystem for Linux.
Search for Bash on Ubuntu on Windows in your local search and you will find it.
Otherwise, you can skip the third step by installing Ubuntu 18.0.4 LTS from Window Store which is free and you can run linux commands there. You can actually install any Linux software and it works just as if it was native.
Having installed Ubuntu for Windows, you can just go through the steps on official documentation through the link which you provided us and you will be fine.
Might be a bit late but still maybe helpfull if you can't on WSL or if you easily want to keep polynote up-to-date.
I used docker to run polynote on Windows. Currently I'm reworking the Dockerfile I wrote to automatically update polynote on new releases. But as of now the script to run Polynote works for polynote version (0.3.11). https://github.com/moritzbaumotte/polynote-windows-inofficial
Here you only need docker-compose and docker installed. You can download the repository and execute the batch script. It will create a working docker image and run it, then you can access polynote on http://localhost:8192
The issue with the official docker images imo is the binding to 127.0.0.1 which needs to be 0.0.0.0, hence the config.yml in my repository.

How to read from the serial port in python without using external APIs?

I have to read a stream which is sent from a homemade device over the serial port. The problem is that it should be deployed on a machine where I don't have access to install anything new, which means I have to use the python standard libraries to do this. Is this possible, and if so, how can I manage this.
If it turns out to be almost impossible, I will have to get someone to install pySerial, but I would really appreciate it if it could be done without this.
If there is differences in Linux/Windows, this is on a Windows machine, but I would really appreciate a cross platform solution.
On Unix-like operating systems, the serial port work just like a file, and you simply open it and read or write bytes. There are some extra calls you can make to set the baud rate and whatnot, but that's essentially all there is.
On Windows, you open the serial port like a file, but you must use some particular ways of accessing it that are slightly different from what Python uses for normal files. Unfortunately it is difficult to successfully access a Windows serial port using only native Python libraries.
The pyserial library provides a uniform, cross-platform way of accessing serial ports. It relies on ctypes, which is in the standard library since Python 2.5, so you may be able to include pyserial with your application and just use that.
You say you don't have access to install anything new. I'm guessing it is a permissions issue - i.e. you can't obtain elevated administration access and pip install/conda install fails.
If you have any kind of normal user login access to the machine (which I presume you must have either directly or indirectly in order to put your script on to the machine in the first place) then you can use a virtual environment to install the modules that you need. This can all be done from a normal user account.
Just Google for "python virtual environment" and you'll find all you need.
If you are using Anaconda Python it's slightly different. Google for "conda environment".
If you can't even obtain a command prompt on the host PC - e.g. you zip up the files and give them to someone else to deploy - you can still use a virtual environment. You'll just have to zip up the virtual environment along with your script. With Anaconda you can arrange for the environment to be created in the same directory as your project by using the -p switch. I presume pipenv has something similar.
Or you could package everything up with pyinstaller, which creates a stand-alone runtime with all the modules included.

Categories

Resources