backend module executed while starting python flask server app - python

I am new to Python Flask and Python.
I use Python 3.7 and Ubuntu.
I have done export FLASK_APP=emptst
And have been executing an online application. It was running fine
In the same environment I have a pure python program & I executed it from command prompt.
I think while executing this the python flask server was listening. It is a localhost server
After this I have stopped the server and ran the python online again.The server came up But it started executing the python program that I executed from command line.
And when I removed the program from the mflask directory it is giving the following error.
Traceback (most recent call last):
File "/home/ss/anaconda3/envs/test/lib/python3.7/site-packages/flask/cli.py", line 240, in locate_app
__import__(module_name)
File "/home/ss/mflask/emptst_new.py", line 2, in <module>
import recognize_faces_video_file1_200119
ModuleNotFoundError: No module named 'recognize_faces_video_file1_200119'
Pls advise. Basically i need it to run the online application emptst and not execute the batch application which it executes currently, whenever i start the server

Related

Running python file within a shell script : module not found error

I'm beginner to both bash and python.
I'm working in Ubuntu env.
to be short, I've created a shell script 'format_data.sh' that runs python file 'proc_ko.py' within it.
#!/bin/bash
...
python path/to/python/file/proc_ko.py
...
And the python file 'proc_ko.py' imports a module called khaiii
from khaiii import KhaiiiApi
api = KhaiiiApi()
...
But when I try to execute 'format_data.sh', I get this import error from python file.
Traceback (most recent call last):
File "media/sf_projet/pe/pe/PROGRAMME/SCRIPTS/proc_ko.py", line 5, in
from khaiii import KhaiiiApi
ImportError: No module named khaiii
which doesn't occur when I execute python file independently.
Python file 'proc_ko.py' itself doesn't have any error and 'khaiii' is well installed.
so I don't understand why import error occurs only through the shell script.
If u need more details to figure out, I'll be happy to provide. Thanks in advance for help.

pywin32 cannot debug if project is packed into .exe

I have my project installed as a windows service and everything worked smoothly. I had some errors with using venv and pywin32, but eventually figuret that out. Stackoverflow link
However when I use pyinstaller to make onefile executable from it problems start occuring.
I use following command to create executable:
[Path_to_my_venv_pyinstaller] --onefile --hidden-import win32timezone myservice.py
Then I am executing it from cmd with install arg, service is installed.
However next step, executing it with start arg fails. Error message:
Starting service [Service_Name]
Error starting service: The service did not respond to the start or control request in a timely fashion.
So I tried debugging it with ``debug``` argument. It works normally, when I install service without executable, from source files. When service is installed from executable I am getting following error.
Debugging service [Service_Name] - press Ctrl+C to stop.
Traceback (most recent call last):
File "[Service]\[Service_Folder]\service.py", line 48, in <module>
File "lib\site-packages\win32\lib\win32serviceutil.py", line 640, in HandleCommandLine
File "lib\site-packages\win32\lib\win32serviceutil.py", line 461, in DebugService
AttributeError: module 'servicemanager' has no attribute 'Debugging'
[14252] Failed to execute script service
I found similar topic on stack, unanswered, link here. So the problem indeed lays in installing service from pyinstaller executable.
I have no idea, how to track error on this, Event Viewer does not display anything more than i could see from console.
Is there other way to debug a service?

Pywinauto script compiled as exe using Pyinstaller executes locally but not remotely from the cmd line using PSEXEC

I have a requirement whereby the navigation and control of a legacy application has to be automated - this automated method, packaged as a script, would need to be deployed via SCCM to our user base.
After some research, I've decided to use Python's PywinAuto module to achieve my goal.
I've managed to create a script that automates all the GUI steps as required and I've also packaged this script as an exe using the Pyinstaller module, but the issue i'm now having is the following: when running locally on both Windows 7 and Windows 10 machines, the exe executes successful. However, when triggering the exe remotely through either SCCM or PSEXEC, the exe fails to execute.
I've also wrapped the exe in a powershell script, but the same thing occurs when executing the script via PSEXEC or SCCM.
I'm running PSEXEC as the System user, which has full admin rights. The SCCM user has full admin rights aswell.
This is the Pyinstaller example script that I packaged into an exe, just for testing purpose:
from __future__ import print_function
import logging
from pywinauto import actionlogger
from pywinauto import Application
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("--log", help = "enable logging", type=str, required = False)
args = parser.parse_args()
actionlogger.enable()
logger = logging.getLogger('pywinauto')
if args.log:
logger.handlers[0] = logging.FileHandler(args.log)
app = Application(backend='uia').start(r'mspaint.exe')
dlg = app.window(title_re='.* - Paint')
dlg.close()
When running the exe locally from the the command line, the following appears indicating successful execution:
c:\Temp>pywinauto_test 2019-05-11 07:47:14,215 INFO: Started
mspaint.exe application. 2019-05-11 07:47:14,344 INFO: Closed window
"Untitled - Paint"
When running remotely through psexec, the following appears:
C:\Temp>pywinauto_test.exe 2019-05-11 07:29:38,221 INFO: Started
mspaint.exe application. [ 5516] Failed to executC:\Temp>e script
Pywinautopaint Traceback (most recent call last): File
"site-packages\pywinauto\application.py", line 256, in
__resolve_control File "site-packages\pywinauto\timings.py", line 458, in wait_until_passes pywinauto.timings.TimeoutError
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "Pywinautopaint.py", line
59, in File "site-packages\pywinauto\application.py", line
378, in getattribute File
"site-packages\pywinauto\application.py", line 259, in
__resolve_control File "site-packages\pywinauto\timings.py", line 436, in wait_until_passes File
"site-packages\pywinauto\application.py", line 201, in __get_ctrl
File "site-packages\pywinauto\findwindows.py", line 87, in
find_element pywinauto.findwindows.ElementNotFoundError: {'title_re':
'.* - Paint', 'backend': 'uia', 'process': 2844}
All known methods to run GUI automation remotely are listed in the Remote Execution Guide. It's not specific to PyInstaller or other py2exe-like tools. Mostly it's OS Windows restrictions and RDP features that can be workarounded by several ways.
Also ElementNotFoundError is often raised when default timeout to find window (5 sec.) is insufficient. For example, if remote virtual machine is slow. This might be unrelated to common remote execution problems.

key error when running local app example with dev_appserver.py

I am trying to run the appengine-endpoints-helloendpoints-python app locally using the google cloud platform SDK (which has been added to my path) using the command dev_appserver.py from the command line. It used to run perfectly, but now when I try, I get an error:
Error processing line 2 of
/Users/hannah/anaconda3/envs/py27/lib/python2.7/site-packages/grpc_google_pubsub_v1-0.8.1-py2.7-nspkg.pth:
Traceback (most recent call last):
File "/Users/hannah/anaconda3/envs/py27/lib/python2.7/site.py", line 161, in addpackage
exec line
File "<string>", line 1, in <module>
KeyError: 'google'
Remainder of file ignored
It's in a anaconda python2.7 environment. I've tried looking in site.py but I can't follow it back to a clear missing link.
The appcfg.py command used to deploy from the command line doens't work at all anymore. The command is not found.
bash: appcfg.py: command not found
As I said, I reinstalled and authorised the google cloud SDK and it is added to my path and that hasn't solved anything.
Oh finally, the error comes up whenever I run the dev_appserver.py command, not just with the example code from google.
Any tips would be appreciated

Import error with remote interpreter in pycharm

I am trying to run my code in the server using ssh remote interpreter.
The connection and the deployment work but when I want to import libraries located in the server it gives an import error
ssh://***#****.com:22/usr/bin/python -u
/home//main.py Traceback
(most recent call last): File
"/home//main.py", line 11,
in
from clplibs.clp import ContinuousLearningPlatform as clp ImportError: No module named clplibs.clp
Process finished with exit code 1
I've found a solution, the environment variables (including python path) should be defined from pycharm: Run/Debug configurations-> Environment variables. Pycharm won't use bashrc paths.

Categories