Error in simple wxpython execution example - execute

As a totally wxpython newbie, I’ve unsuccessfully tried to execute this example:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import wx
if __name__ == '__main__':
app = wx.App(False)
pid = wx.Execute('echo blabla', wx.EXEC_ASYNC)
print(pid)
It returns pid = 0, i.e., the command could not be executed. I am using Python 3.7.5 with wxPython 4.1.0 on Windows 10. What am I missing?
Thanks in advance.

Running your example result in an error for me:
Execution of command 'echo blabla' failed (error 2: the system cannot
find the file specified.)
Adding cmd /c to the start of the command string results in the following output:
11412
blabla
The full code is:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import wx
if __name__ == '__main__':
app = wx.App(False)
pid = wx.Execute('cmd /c echo blabla', wx.EXEC_ASYNC)
print(pid)

Related

CronR bad minute error errors in crontab file, can't install

Hope you are fine. I was testing the Cron scheduler in my Mac through my r Studio. I am getting this error. Googling I dont seem to find a proper answer So I have no idea.
library(cronR)
fichero <- "local_path/GetDetailsAgents.R"
cmd <- cron_rscript(fichero)
cron_add(command = cmd, frequency = 'weekly',at = '14:00', days_of_week = 3,
id = 'MyId1', description = 'foo foo')
Error:
Adding cronjob:
---------------
## cronR job
## id: MyId1
## tags:
## desc: foo foo
weekly /Library/Frameworks/R.framework/Resources/bin/Rscript '/local_path/GetDetailsAgents.R' >> 'local_paths/GetDetailsAgents.log' 2>&1
"/var/folders/ts/jzrp60111c9_dd27gmw9jcnm0000gn/T//RtmpIuVXQJ/file91e6274555":4: bad minute
crontab: errors in crontab file, can't install
Mac Os: 13.1
Do you have any suggestion?
Followed this video: https://www.youtube.com/watch?v=qgC81rJ_chs
This code: https://github.com/jgQuantScripts/Scheduling-R-Scripts-MacOS/commit/10d7b5b5be028e3bbbdad7ff87ccaccb30867375
This documentation: https://www.rdocumentation.org/packages/cronR/versions/0.6.2/topics/cron_add
This Post: Bad Minute error Crontab

crontab error "ImportError: No module named request" python runs OK in terminal - fails in crontab

I am having difficulty in a running python script that calls module "requests" in crontab. This was fine a few days ago and then I had to change my authentication for Google (to send emails), then "requests" stopped working in crontab. The python script runs fine in a terminal but will not execute in crontab. "requests" is available and when I type "pip3 show requests" the following is displayed (note I replaced my user name with "user"):
$pip3 show requests
Name: requests
Version: 2.27.1
Summary: Python HTTP for Humans.
Home-page: https://requests.readthedocs.io
Author: Kenneth Reitz
Author-email: me#kennethreitz.org
License: Apache 2.0
Location: /home/user/.local/lib/python3.6/site-packages
Requires: certifi, idna, urllib3, charset-normalizer
A simplified version of the python file I would like to execute in crontab is:
#!/usr/bin/env python...
# -*- coding: utf-8 -*-
import requests
print ('End of code')
The file test_request.py executes fine in a terminal.
I created a bash script called test_request.sh based on directions from this stack overflow page:
"ImportError: No module named requests" in crontab Python script
That bash script is this:
#!/bin/bash
echo test_request.sh called: `date`
HOME=/home/user/
PYTHONPATH=/home/user/.local/lib/python3.6/site-packages
cd /home/user/Documents/bjg_code/
python ./test_request.py 2>&1 1>/dev/null
When I try to run the bash script in a terminal or in crontab I receive this error:
$bash test_request.sh
test_request.sh called: Sat Jun 11 14:18:46 EDT 2022
Traceback (most recent call last):
File "./test_request.py", line 4, in <module>
import requests
ImportError: No module named requests
Any advice would be welcomed and appreciated.
Thank you in advance.

Retrieve output from a shell call to python in a makefile: is there a missing step?

I have the following makefiles:
# bash version
SHELL:=/usr/bin/env bash
H:=$(shell pwd)
install:
#echo "$H::make.$#: not implemented!"
And a python3 version:
SHELL:=/usr/bin/env python3
H:=$(shell "import os,sys; print(os.getcwd(),file=sys.stdout)")
install:
#print("$H::make.$#: not implemented!")
The bash version works perfectly, whereas the python3 version works, persay. However, the path variable $H is empty.
A check of the python expression in the shell call confirms it is working python code:
python3 -c "import os,sys; print(os.getcwd(),file=sys.stdout)"
//works
How does one comply with the expected behavior in that shell call so that make picks up the output?
That is not what the shell command you wrote actually does.
This:
SHELL:=/usr/bin/env bash
H:=$(shell pwd)
causes the equivalent of:
/usr/bin/env bash -c 'pwd'
to be run.
So, this:
SHELL:=/usr/bin/env python3
H:=$(shell "import os,sys; print(os.getcwd(),file=sys.stdout)")
causes the equivalent of this to be run:
/usr/bin/env python3 -c '"import os,sys; print(os.getcwd(),file=sys.stdout)"'
to be run. A string in Python is just a no-op statement, so this does nothing.
Remove the quotes:
H := $(shell import os,sys; print(os.getcwd(),file=sys.stdout))

Run shell script from within an R script on a windows machine

I have a R-script within which i call a shell script using system command and use the paste command to pass arguments to the shell script ( on unix machine) and i now would like execute the same R-script on a windows machine and am struggling to get it working
Here are the steps i followed
R code
source('C:\\Users\\xxxx\\Documents\\R\\R-3.5.2\\ms\\ms\\MS_Config.R')
if(is.null(git_version) | git_version == "" | length(git_version) == 0){
print('ERROR: EXECUTION STOPPED !!!')
print('PLEASE SPECIFY GITHUB TAG_ID')
stop()
}
print("test4444")
print(enable_data_pull)
print (getwd())
system(paste('C:\\Users\\xxxx\\Documents\\R\\R- 3.5.2\\ms\\ms\\MS_ALLM_Parallel_Runner.sh -c ', num_cores,
'-s ', snapshot_dt,
'-p ' , local_storage_path,
'-t ', tag,
'-g ', git_version,
'-y ', enable_data_pull
))
print ("after shell script execution")
I tried the following, but did not succeed
Installed cygwin and called the rscript from the cygwin terminal(PATH variable is updated to include R and its binaries)
rscript "C:\Users\xxxx\Documents\R\R-3.5.2\ms\ms\MS_Model_Kickoff.R"
Below is the error message that i see after the r-script attempts to run the shell script
'CreateProcess' failed to run 'C:\Users\xxxx\DOCUME~1\R\R-35~1.2\ms\ms\CONRM_~1.SH -c 25 -s 201811 -p C:\Users\xxxx\Documents\Test -t Analytical -g verModelRefit2.2.2 -y N'
what does the above error mean and how do i fix this and execute the shell script within from the R-script on windows machine?r

Problem: Google Colab import libraries and authorization to use google drive takes too long?

I execute this part of code in google colab, to authorize me so to get access to my drive folders
!apt-get install -y -qq software-properties-common python-software-properties module-init-tools
!add-apt-repository -y ppa:alessandro-strada/ppa 2>&1 > /dev/null
!apt-get update -qq 2>&1 > /dev/null
!apt-get -y install -qq google-drive-ocamlfuse fuse
from google.colab import auth
auth.authenticate_user()
from oauth2client.client import GoogleCredentials
creds = GoogleCredentials.get_application_default()
import getpass
!google-drive-ocamlfuse -headless -id={creds.client_id} -secret=
{creds.client_secret} < /dev/null 2>&1 | grep URL
vcode = getpass.getpass()
!echo {vcode} | google-drive-ocamlfuse -headless -id=
{creds.client_id} -secret={creds.client_secret}
But when it comes to the part of copy and paste the verification code from the given url, execution doesn't end, so to move on the next block. What is the problem?even though I am still connected.
Following this tutorial, I've been using this for the past few days, and what has worked for me is the following:
1.- In a single cell run:
from google.colab import auth
auth.authenticate_user()
2.- Follow the link, copy and paste the generated password
3.- In another cell run:
from oauth2client.client import GoogleCredentials
creds = GoogleCredentials.get_application_default()
import getpass
prompt = !google-drive-ocamlfuse -headless -id={creds.client_id} -secret={creds.client_secret} < /dev/null 2>&1 | grep URL
vcode = getpass.getpass(prompt[0] + '\n\nEnter verification code: ')
!echo {vcode} | google-drive-ocamlfuse -headless -id={creds.client_id} -secret={creds.client_secret}
4.- Again, follow the link, copy and paste the new generated password
5.- Proceed to mount your drive and work with your files!
This looks like an issue other folks are encountering being discussed here: https://github.com/googlecolab/colabtools/issues/231
Do you also see any 400s or errors on the JS console?
Recently I made a new effort and seems to work, in order to mount your drive to the colab-notebook use these lines instead,
from google.colab import drive
drive.mount('/content/gdrive')
Run it,
Click on the link accept and copy-paste the given code, hit enter done! Much simpler from the previous way I've asked about which by the way it still not working.
After pasting in your generated code, hit enter on the keyboard. It will continue to buffer until you do.

Resources