Execute python executable and script inlucing full path - python-3.x

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.

Related

Python not getting invoked by Powershell

I am working on some automation where a python script need to be executed by a PowerShell script.
If I execute the python from the PowerShell (e.g., ISE), it all works fine. In the actual flow, the PowerShell function is first executed by the Application which uses this PowerShell script, which in turn must invoke the python script being called in that PowerShell function.
However, every time App executes this PowerShell, the python is not being invoked at all.
The Environment variables are also set properly.
Not sure where to look for errors. Any leads ?
I am simply calling the python script as:
py "C:\Program Files\<some location>\script.py" $arg1 $arg2
which error you are getting?
can you elaborate more?
have you tried with "python" instead
My bad. I guess i should have done a bit more troubleshooting. The issue was because of a Python module which was not installed for all user (including the one which application uses to invoke the script). Once installed, it works fine.

What exactly is main.py in python and how do I use it to create a one file executable using pyinstaller?

I am currently working on a demo project while learning python and decided to use Tkinter as a user interface for my system. After finishing on the GUI and setting up a MySQL database I tried to use pyinstaller and py2exe to create a standalone .exe but it creates only one executable for one python file and I have 6 python files.
After research I found that most people with multiple python scripts have one main.py file that runs all their scripts and they use this to create a standalone .exe. So since this seems to be the solution but my question is, what is this main.py file and how do I write it so that when I create a .exe it runs my program and still has all the scripts working?
all my python scripts
The first script that I want to execute when run my program is Login.py

SyntaxError: Non-UTF-8 code starting with '\x90' in file .\score_python.exe on line 1, but no encoding declared;

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.

Popen doesn't run my exe

(Python 3)
I'm trying to use popen in a little script to run an executable
The executable is at :
https://github.com/Gorov/FCM_nips_workshop
I'm on windows and by modifying a little the github README command I can run easily the program using
RE_FCT ../data/SemEval.train.fea.sst ../data/SemEval.test.fea.sst predict.fea.fullnerpair.onlyne.txt ../data/vectors.nyt2011.cbow.semeval.filtered 5 0.005
The exe is RE_FCT and all the following text is just arguments
So using a terminal it works just fine and display informations while runing
But when I try to make it run using my little python script, it does nothing. Actually something seems runing but it never ends and doesn't display anything
Here's my code
import subprocess
command = ['RE_FCT', '../data/SemEval.train.fea.sst', '../data/SemEval.test.fea.sst ', 'predict.fea.fullnerpair.onlyne.txt', '../data/vectors.nyt2011.cbow.semeval.filtered', '5', '0.005']
process = subprocess.Popen(test, cwd="fcm", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
process.wait()
print() #sometimes it helps
Note that I'm already running another exe with similar code and it works
Thanks in advance
Just solved it
I don't know exactly what is going on but the problem is with the process.wait(), I just deleted it and replaced the Popen function with the run fonction and it works
The difference between those two is that popen allows the script to run immediatly after you call it by creating a process, while using run you have to wait for the task to end

How to used sdaps setuptex command in python program

I used sdaps command setup_tex to create a sdaps project in linux command line:
kashif#crunchbang:~$ sdaps /tmp/project setup_tex example.tex
which created project directory successfully, Now i want to use this command in my python program by executing this instruction:
sdaps.setuptex.setup.setup(survey, cmdline)
but don't know what exactly argument I should give to successfully execute to create project directory.
Anyhow i manage to create project by using os package i.e
import os
os.system("sdaps /tmp/project setup_tex example.tex")
but still i need standard documentation of sdaps usage with example so that i could make my own changes.

Resources