I ran this command to convert my script from .py to .exe:
pyinstaller.exe -w -i .\icon.png --add-data='icon.png;.' .\gui_script.py
and after adding in some poorly added packages the GUI opens via my tkinter script. But when I run code using the tkinter window in Windows, every time there's a subprocess.run or os.system function it opens up a new terminal window. Is there any way to suppress these? Or at least make them minimized or not noticeable?
Here's a piece of the gui_script.py that combines two files which opens an external terminal window.
import os
os.system('copy cDNA.fa+ncRNA.fa transcriptome.fa /b')
I started using python tools for the merging of files:
with open('transcriptome.fa','wb') as transcriptome_file:
for fasta_file in ['cDNA.fa','ncRNA.fa']:
with open(fasta_file,'rb') as current_fasta:
shutil.copyfileobj(current_fasta, transcriptome_file)
as well as downloading of larger files:
with requests.get('http://ftp.ensembl.org/pub/current_fasta/'+species+'/cdna/'+cDNA_file_name, stream=True) as cDNA_request:
with open('cDNA.fa.gz', 'wb') as cDNA_gz_file:
shutil.copyfileobj(cDNA_request.raw, cDNA_gz_file)
Despite this I still need to run an external program, blast, so there I used subprocess.run with the creationflag = subprocess.CREATE_NO_WINDOW argument like this:
if os.name == 'nt':
blast_db_run = subprocess.run(['makeblastdb',
'-in', fasta_file,
'-dbtype', 'nucl',
'-out','blast_db'],
capture_output=True,
creationflags = subprocess.CREATE_NO_WINDOW)
Used the if statement since creationflags doesn't work in a non-windows environment apparently.
Related
So basically I am running a script in Python that executes other 5 .py scripts as well, just like this:
exec(open('statcprs.py').read())
exec(open('dragndownf.py').read())
exec(open('lowprbubble.py').read())
exec(open('wshearstr.py').read())
exec(open('slices.py').read())
These .py files uses Paraview (another software) to run some stuff, so If I only run "statcprs.py", it will open Paraview's terminal and run the script. The problem is, from the first one "statcprs.py" to the second one "dragndownf.py" it doesn't interrupt the software, and it continue running it, interefering with scripts from both .py files.
I would like to execute the first one, stop and then start the second one from scratch without connection between them. is this somehow possible?
I think the problem is this line (line 1) which opens the terminal:
#!/usr/bin/env pvpython
The following will execute a list of python scripts in the same folder as the driver script:
import os
from pathlib import Path
import subprocess
import sys
scripts = [
'statcprs.py',
'dragndownf.py',
'lowprbubble.py',
'wshearstr.py',
'slices.py',
]
parent = Path(__file__).resolve().parent
for script in scripts:
script_path = parent / script
subprocess.call([sys.executable, script_path])
I have a python script running a command in the console. Everything works fine in the IDE, but after compiling it into an exe using pyinstaller (pyinstaller -F -i "C:\xampp\htdocs\organaizer\1.ico " websockets.py ) the command does not run. Error up VCRUNTIME140.dll' 14.12 is not compatible with this PHP build linked with 14.29 in Unknown on line 0. I notice that the window appears for a second and immediately disappears. I use Python 3.7. An example of a command that does not run in exe
import subprocess
import os
os.system('php artisan websockets:serve')
Tell me what the problem may be.
import subprocess
subprocess.call(['php', 'artisan', 'websockets:serve'])
I have made a folder using python3 script, and to apply multiple attributes (+h +s) to the folder I have to run ATTRIB command in Command Prompt.
But I want to know how it can be done from the same python3 script.
import os
os.makedir("C:\\AutoSC")
# Now I want the code to give the same result such that I have opned CMD and writen following command
# C:\> attrib +h +s AutoSC
# Also show in the code, necessary imported modules
I want the folder to be created and immediately hidden as system folder.
Which is not visible even after show hidden files.
Use the subprocess module or use os.system to send commands directly to OS.
import subprocess
subprocess.run(["ls","-l"])# in linux, for windows, it may change.
import os
os.system('attrib +h +s AutoSC')
I am new to Python and Multiprocessing.
Summarized issue: I am running a .py executable which contains a Pool.map(function,list_args) the function it calls contain the line os.system() which it executes a .csh file in the same directory as the initial .py executable. This .csh executable creates a new folder and moves the working directory into it. I believe this where my code fails, I believe that the os.system() does not wait for the .csh executable to finish.
(Ubuntu is the OS on my computer).
Here is part of the code:
import sys
import os
import multiprocessing as mp
import time
def phenix(FILES):
os.system("mkdir temp_"+str(FILES))
time.sleep(1)
os.system("cp 5k10_only_atoms.pdb.mtz "+str(FILES)+" temp_"+str(FILES)+"/")
retval = os.getcwd()
time.sleep(1)
os.chdir(str(retval)+"/temp_"+str(FILES))
time.sleep(1)
os.system("./phenix.get_cc_mtz_pdb 5k10_only_atoms.pdb.mtz "+str(FILES)+" scale=True fix_xyz=True >> grabado")
os.chdir(retval)
#THE USER INPUTS VALUES FOR THE VARIABLES cores AND list_files
if __name__ == '__main__':
p = mp.Pool(cores)
p.map(phenix,list_files)
The command line
./phenix.get_cc_mtz_pdb 5k10_only_atoms.pdb.mtz .....and so on
Runs some calculations comparing values insides the files 5k10_only_atoms.pdb.mtz and FILES (another file e.g. "file-01"). It is this command line phenix.get_cc_mtz_pdb that creates another folder (called temp_dir) and moves the working directory into it to do some calculations and write out files.
Again I am pretty sure that this is where something goes wrong because the phenix command never does anything besides creating a folder named temp_dir. It is only when phenix (a .csh executable) tries to change the working directory that os.system() does not wait for any return and my .py executable continues on to the next command.
Is their some way to let my phenix executable finish its job with out os.system() not waiting for it to finish?
NOTE: I am not able to modify this phenix (.csh) executable. Also the phenix command line does work when I run it directly on the terminal.
I'm trying to use py2exe to compile a python script into an executable.
I've set up the setup.py file just like it's described in documentation:
from distutils.core import setup
import py2exe
setup(console=['agent.py', 'test.py'])
The agent.py file simply uses subprocess.Popen to open another script:
import sys
import subprocess
print 'is this working?'
child = subprocess.Popen([sys.executable, 'test.py'])
The test.py file is
while 0 == 0:
print 'test'
When running this as a python script, it works fine. When running as a py2exe-compiled executable, it does not run.
When I try to change the file reference in agent.py from 'test.py' to 'test.exe', running the compiled agent.exe simply prints 'is this working?' on an infinite loop. What have I done wrong?
sys.executable points to agent.exe instead of python.exe when run as compiled executable. You need to change your Popen to:
child = subprocess.Popen(['test.exe'])
when running compiled executable. You can use hasattr(sys, "frozen") to determine whether you're in frozen (py2exe) or not (Python script) mode.
That didn't quite work, but all I had to do was replace your answer with the full path name. Thanks! This worked:
app_path = os.path.realpath(os.path.join(
os.path.dirname(sys.executable), 'test.exe'))
child = subprocess.Popen(app_path)