How can I run many python scripts at once? - python

I'm working on some python scripts using PyCharm. Running scripts from PyCharm works fine, but I tried bundling them up with a batch file and cmd just goes nuts:
C:\Users\White Python\Desktop\Fran\theconfluence\graphs\leaderboard>python htmlcreator.py
Traceback (most recent call last):
File "htmlcreator.py", line 4, in <module>
w = open(str(Path(__file__).parents[2]) + "/week.txt", "r")
File "C:\Users\White Python\AppData\Local\Programs\Python\Python38-32\lib\pathlib.py", line 617, in __getitem__
raise IndexError(idx)
IndexError: 2
C:\Users\White Python\Desktop\Fran\theconfluence\graphs\leaderboard>cd ..\retention
C:\Users\White Python\Desktop\Fran\theconfluence\graphs\retention>python creategraph.py
['C:\\Users\\White Python\\Desktop\\Fran\\theconfluence\\graphs\\retention', 'C:\\Users\\White Python\\AppData\\Local\\Programs\\Python
\\Python38-32\\python38.zip', 'C:\\Users\\White Python\\AppData\\Local\\Programs\\Python\\Python38-32\\DLLs', 'C:\\Users\\White Python\
\AppData\\Local\\Programs\\Python\\Python38-32\\lib', 'C:\\Users\\White Python\\AppData\\Local\\Programs\\Python\\Python38-32', 'C:\\Us
ers\\White Python\\AppData\\Local\\Programs\\Python\\Python38-32\\lib\\site-packages']
Traceback (most recent call last):
File "creategraph.py", line 9, in <module>
w = open(str(Path(__file__).parents[2]) + "/week.txt", "r")
File "C:\Users\White Python\AppData\Local\Programs\Python\Python38-32\lib\pathlib.py", line 617, in __getitem__
raise IndexError(idx)
IndexError: 2
Other scripts which did not require importing modules worked fine. Help!

Is your html creator a script? Or more like module? If it's like a module the try:
python -m htmlcreator

Related

How to solve "KeyError: 'cpu'" error when trying to generate configFileName.xml with Gem5toMcpat?

Hello I am trying to generate configFileName.xml by using the following command in Gem5toMcpat parser which is installed on ubuntu 20
python Program.py stats.txt config.json ARM_A9_2GHz.xml
but it showed me this error
Traceback (most recent call last):
File "Program.py", line 964, in <module>
main()
File "Program.py", line 38, in main
countCores(sys.argv[2])
File "Program.py", line 70, in countCores
noCores = len(configfile["system"]["cpu"])
KeyError: 'cpu'

Getting OSError when running script

I am trying to set up the ChirpSDK, but every time I configure and run the code, I get this error:
Traceback (most recent call last):
File "test.py", line 3, in <module>
chirp = ChirpSDK()
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/chirpsdk/chirpsdk.py", line 395, in __init__
self.read_chirprc(block)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/chirpsdk/chirpsdk.py", line 501, in read_chirprc
raise IOError('Could not find a ~/.chirprc file')
OSError: Could not find a ~/.chirprc file
Exception ignored in: <function ChirpSDK.__del__ at 0x10fa31af0>
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/chirpsdk/chirpsdk.py", line 422, in __del__
self.close()
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/chirpsdk/chirpsdk.py", line 470, in close
if self._sdk:
AttributeError: 'ChirpSDK' object has no attribute '_sdk'
I realize that the error is saying that my .chirprc file is not being recognized, but I have no idea how to remedy this. I created a .chirprc file in my /Users/username/ path, and named it c.chirprc (as the Chirp getting started article suggests), but I am still getting this error. Is there another part that I am missing? Am I reading the instructions wrong?
Thanks
The Chirp configuration file should be placed at /Users/<username>/.chirprc on macOS.
If you run ls -l ~/.chirprc in the terminal, do you get any results? If it displays no such file or directory then you have not created the file correctly.

Python code not working from cron job but works from command line via virtualenv

I am receiving different errors which I cannot determine the issue. It seems as though it has to do with the configparser.py NoSectionError(section). This code runs fine from the command line in the virtualenv.
Traceback (most recent call last):
File "/usr/lib/python3.5/configparser.py", line 1135, in _unify_values
sectiondict = self._sections[section]
KeyError: 'token'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/lvensel/projects/worklion01/worklion01/wl_cron.py", line 15, in <module>
wl_post_projects.post()
File "/home/lvensel/projects/worklion01/worklion01/wl_post_projects.py", line 15, in post
import wl_get_background_jobs
File "/home/lvensel/projects/worklion01/worklion01/wl_get_background_jobs.py", line 12, in <module>
oauth, token = wl_secure_token.fetch_token()
File "/home/lvensel/projects/worklion01/worklion01/wl_secure_token.py", line 17, in fetch_token
values = wl_get_ini.get_values()
File "/home/lvensel/projects/worklion01/worklion01/wl_get_ini.py", line 13, in get_values
'token_url': config.get('token', 'token_url'),
File "/usr/lib/python3.5/configparser.py", line 778, in get
d = self._unify_values(section, vars)
File "/usr/lib/python3.5/configparser.py", line 1138, in _unify_values
raise NoSectionError(section)
configparser.NoSectionError: No section: 'token'
Let me guess on what potentially happens:
Cron jobs are run by root
virtualenv is run by your user with a custom python environment.
root does not know about your virtualenv, then cannot match your user's python environment, thus your script fails. Probably with some cannot import or alike errors.
Have a look at replies here.

Python execvp error

I wrote the following two pieces of code:
The first one is called_Process.py
print("Hello Python!!")
closeInput = raw_input("Press Enter to exit")
print "Closing calledProcess"
The second program is calling_Process.py which calls the above program:
import os
import sys
program = "python"
print("Process Calling")
arguments = ["called_Process.py"]
os.execvp(program, (program,) + tuple(arguments))
print("Finished calling called_Process!!")
When I run calling_Process.py on Windows using python 3.6.0, I get the following error:
Process Calling
Traceback (most recent call last):
File "C:/Users/ND/Desktop/calling_Process.py", line 14, in <module>
os.execvp(program, (program,) + tuple(arguments))
File "C:\Users\ND\AppData\Local\Programs\Python\Python36\lib\os.py", line 623, in execvp
_execvpe(file, args)
File "C:\Users\ND\AppData\Local\Programs\Python\Python36\lib\os.py", line 668, in _execvpe
raise last_exc.with_traceback(tb)
File "C:\Users\ND\AppData\Local\Programs\Python\Python36\lib\os.py", line 658, in _execvpe
exec_func(fullname, *argrest)
FileNotFoundError: [Errno 2] No such file or directory
>>> os.environ()
Traceback (most recent call last):
File "<pyshell#6>", line 1, in <module>
os.environ()
TypeError: '_Environ' object is not callable
Can someone help me understand what is causing this error?

What's wrong in python script?

What's wrong in python script?
Code:
import os
import shutil
import getpass
os.mkdir("C:\\dtmp")
shutil.copy("C:\\path\\to\\bb-freeze-script.py","C:\\dtmp")
os.chdir("C:\\dtmp")
shutil.copy("C:\\path\\to\\main.py","C:\\dtmp")
os.system("python bb-freeze-script.py main.py")
os.mkdir("C:\\Program Files\\Directories v0.6")
os.chdir("C:\\")
shutil.rmtree("C:\\dtmp")
print getpass.getuser()
Error:
Traceback (most recent call last):
File "bb-freeze-script.py", line 8, in <module>
load_entry_point('bbfreeze==0.97.3', 'console_scripts', 'bb-freeze')()
File "C:\Python27\lib\site-packages\bbfreeze-0.97.3-py2.7-win32.egg\bbfreeze\__init__.py", line 24, in main
f.addScript(x)
File "C:\Python27\lib\site-packages\bbfreeze-0.97.3-py2.7-win32.egg\bbfreeze\freezer.py", line 410, in addScript
s = self.mf.run_script(path)
File "C:\Python27\lib\site-packages\bbfreeze-0.97.3-py2.7-win32.egg\bbfreeze\modulegraph\modulegraph.py", line 241, in run_script
co = compile(file(pathname, READ_MODE).read()+'\n', pathname, 'exec')
File "C:\dtmp\main.py", line 14
^
IndentationError: expected an indented block
Operating system -- Windows XP
Here's a quick walkthrough on how to read tracebacks. It's pretty easy.
Looking through your code, all of it is calling Python builtin modules. It's safe to say they're not causing the error, so the only thing left is the os.system call. Sure enough, you're calling python through said call (why would you not just import the module you want to call?).
The traceback confirms that the error is in the other Python you are calling:
Traceback (most recent call last):
File "bb-freeze-script.py", line 8, in <module>
load_entry_point('bbfreeze==0.97.3', 'console_scripts', 'bb-freeze')()
Next, read through the lines of the transcript to burrow through the call stack and find out exactly where the error occurred.
File "C:\Python27\lib\site-packages\bbfreeze-0.97.3-py2.7-win32.egg\bbfreeze\__init__.py", line 24, in main
f.addScript(x)
File "C:\Python27\lib\site-packages\bbfreeze-0.97.3-py2.7-win32.egg\bbfreeze\freezer.py", line 410, in addScript
s = self.mf.run_script(path)
File "C:\Python27\lib\site-packages\bbfreeze-0.97.3-py2.7-win32.egg\bbfreeze\modulegraph\modulegraph.py", line 241, in run_script
co = compile(file(pathname, READ_MODE).read()+'\n', pathname, 'exec')
until you get to
File "C:\dtmp\main.py", line 14
IndentationError: expected an indented block
There you go, the error is in line 14 of main.py, where you should have had an indent but didn't.

Categories

Resources