I created a Python script that uses the Todoist API to export my task list to a list of strings (I want to paste them as Discord messages) and it works fine if I run the command on the Terminal window, but if I run the same command using AppleScript, an error is thrown, saying No module named todoist.api.
Here's the code: (I have only one line)
do shell script "$HOME/tasks.sh"
The shell scripts runs the python scripts I need, but the problem is in the imports of those files, which are:
from datetime import date, datetime, timedelta
from todoist.api import TodoistAPI
import pyperclip
import os
import MyTodoist
in the first file (tasks.py) and
from datetime import date, datetime, timedelta
from todoist.api import TodoistAPI
import pyperclip
import os
in the second file (MyTodoist.py)
The final goal is to store the result of a function in tasks.py in a variable in my script, but I don't know how. Can someone help me please?
Related
I'm a bit turned around on how to execute a shell script file in a Linux environment via Python's subprocess command in Streamlit. Any assistance on what I'm missing is appreciated.
I'm using a shell script called 0_texts.sh to run Pylanguagetool for a grammar check of one text file and return corrections in another text file, like so:
cd /home/user/dir/TXTs/
pylanguagetool text_0.txt > comments_0.txt
This script runs correctly in the Linux terminal, writing a comments_0.txt with appropriate grammar checks from text_0.txt.
I need to create a Python/Streamlit app that runs these shell scripts. In attempting to run this shell script, I've written script.py below:
import os
import subprocess
import sys
subprocess.run(['bash','/home/user/dir/Scripts/0_texts.sh'])
I then run script.py in Streamlit via the code below, keeping with Streamlit's documentation on using subprocess here.
import streamlit as st
import os
import subprocess
import sys
def app():
button1 = st.button("Click me")
if button1:
p = subprocess.run([f"{sys.executable}", "/home/user/dir/pages/script.py"])
st.write(p)
When I execute the script.py via Streamlit, the 0_txts.sh script executes, writing comments_0.txt in the correct directory and providing the following traceback: CompletedProcess(args=['/usr/bin/python3', '/home/user/dir/pages/script.py'], returncode=0). However, the comments_0.txt output contains the error input file is required, as if it can't properly access or read text_0.txt. I've tinkered around trying to find the problem, but have hit a brick wall.
Any suggestions on what I'm missing, or paths forward? Any help greatly appreciated.
I need to launch a program within a python script that has an argument.
Code is:
from datetime import date, timedelta
import os
yesterday = (date.today() - timedelta(days=1)).strftime('%m%d%y')
os.system('"E:/Bootdrv/AlohaTs/Bin/grind.exe /yesterday"')
Any help?
for calling a program with python i use subprocess lib
https://docs.python.org/3/library/subprocess.html
from subprocess import call
call("service camera restart")
this restart a linux service
I'm writing an auto-testing script right now. My build environment is Linux with Python 3.
My program stuck when it runs to the command:
os.system('cp '+ file_name + ' '+ usb_port)
where it reports:
cp: cannot create regular file `/dev/usb/lp0': No such file or directory
I have manually checked that two file exist. (well i should say that the usb port is indeed connected and working properly by using path.exist command)
I've separated this troubling command to another file,and it works fine without any error report.
my program involves following library:
import serial
import time
import os
import threading
import queue
import multiprocessing as mp
from datetime import datetime
from configparser import SafeConfigParser
I have following code as custom python script:
#!/usr/bin/env python
import sys
import re
from sys import stdin
sys.stdout.write(DOC_FILENAME)
How can I use this as custom command in Geany to get current document name and path ?
Is "geanypy" needed to be installed to run this command ?
I have this line of import in my python code:
from project.lib.framework.test_cases import TestCase
and it works fine when I run it from command line. However, if I try to run it from my IDE (Active state komodo), I get an error:
ImportError: No module named project.lib.framework.test_case.
Can anyone tell me why?
Because you changed the import statement?
In the first example, you are importing from project.lib.framework.test_cases, but in the second, you appear to be importing from project.lib.framework.test_case. Notice the missing s at the end.
Other then that, assuming you are using the same python binary, there should be no difference between an IDE and a command line for import statements.