I want to download a file then compress it. In my code, I have a subprocess command to download a file THEN I have a shutil command to compress it. But when executed, the shutil command runs first.
Note: "MyDownloadScript.pl" is a Perl script that downloads the needed file. For the purposes of this task, I have to download with this script.
subprocess.Popen(['perl', 'C:\\gitrepo\\BuildScripts\\MyDownloadScript.pl', '-branch', 'BranchName'])
shutil.make_archive(('{}\\OutputZIP'.format('outputPath'), 'zip', 'C:\\startingFolder', 'startingFile.dmg')
Despite the ordering of the functions in the code, the shutil command always runs first. Here's what happens what I run the script in different scenarios:
1) If no files exist:
Script complains it can't find the .dmg file
.dmg file is downloaded after
No ZIP produced
2) If I run the script again right afterwards (when the .dmg exists)
ZIP file is created from .dmg
.dmg is RE-DOWNLOADED
Why are these functions running seemingly out of order? Any ideas/suggestions would be much appreciated.
subprocess.Popen() is non-blocking. So it spawns a process and immediately goes to the next line in your script. Try subprocess.call() instead:
subprocess.call(['perl', 'C:\gitrepo\BuildScripts\MyDownloadScript.pl', '-branch', 'BranchName'])
shutil.make_archive(('{}\OutputZIP'.format('outputPath'), 'zip', 'C:\startingFolder', 'startingFile.dmg')
Related
Im trying to create a python script with executes a series of python and sql scripts.
Some need to be executed using one python executable and some using another.
I've tried
from subprocess import call
call([r"C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\pythonw.exe", r"C:\Path\to\python\file\blabla.py"])
And
call([r"cd C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3", "pythonw.exe", r"C:\Path\to\python\file\blabla.py"])
But the script isnt being executed.
I think the problem might be "How to execute an .exe file in windows terminal including full path to it"?
Please check my code. It is working well in my side.
from subprocess import call
call([r"C:\Python38\python.exe", r"E:\python\hello.py"])
As i think, the problem is that you use pythonw.exe.
if you use pythonw.exe, you can see any log in terminal.
Pythonw is useful for running script with GUI.
I have two python files
1) main file which doing the work a
2)Running unittests for main file.
I want to convert them into an .exe file such that whenever .exe run it will execute the unittest file first then main file.Any help or suggestion on this.
So what I would recommend doing in this case is having the unit test be called inside of the main file, so that if you were to run the main file itself; it would run the unit test; then once you have done this use cx_Freeze and write a script, making sure you include your unit test as a module within the script.
cx_Freeze documentation can be found here: https://cx-freeze.readthedocs.io/en/latest/
I am trying to install pumba from the OS release page. Once it is downloaded, I try running
pumba --help
It gives a command not found error.
Can anyone suggest what am I missing? The amd_64 file has all read, write and execute permissions.
If the name of the file is pumba_linux_amd64, you have to use that. Additionally, since the file is (assuming) not in your $PATH, you can't launch it directly.
If your file is in your current directory, run
./pumba_linux_amd64
I have a python script where I need to create an executable via pyinstaller. Successfully created the exe, but shows the above error while running.
I have already searched on the web and tried many solutions but none of them is working. tried with # -*- coding:utf-8 -*- in the first line of the script but fails.
using Python3.7, PyInstaller3.5
Can anyone help me with this?
Ensure you are not calling the executable using python again.
As in
python long-path-to-the-converted-scrip\script.exe
It is a common mistake, due to the fact that you used python to run the script before, then you try to recycle the same command but forget to delete the python call. The long path to the script (now converted to exe) obfuscates the fact that python is no longer needed at the beginning...hence your error.
Resolution: Please execute the exe without python command.
Example: If you have converted test.py, please go to the directory Current Directory/dist/test/ and either double-click on test.exe or run test.exe from command line.
I'm just starting out in python programming and I've noticed after running my python script python text.py few times, there are no .pyc files created. I understand .pyc are only created if its imported but how does text.py still run from command line if there is no .pyc file?
To expand on Rufflewind's answer: the rationale for not writing a .py for start-up scripts is twofold. First, when files are being developed, writing a .pyc file wastes startup time when the file will be ignored on the next run. Second, if a script is large enough that compile speed is noticeable and might matter, stable code can and perhaps should be moved to an imported module. Indeed, for production use, it is standard practice to reduce a startup script to two statements, an import and main() call, as in idlelib.__main__.
""
IDLE main entry point
Run IDLE as python -m idlelib
"""
import idlelib.PyShell
idlelib.PyShell.main()