So, I have a python script, that I can run in cmd using python [path to script]
I have it set in scheduler, but it doesn't run through scheduler and finds an error. Cmd closes out before being able to read the error. I created a batch file to launch to script, and it shows an error that a package doesn't exist [lxml]. But, the package exists as the script will run when manually executed
Any thoughts?
Script scrapes data from a website, creates a dataframe, posts dataframe to a google sheet, then pulls the full google sheet that it posts to, turns that into a dataframe with all of the data, then creates a plotly graph, turns that plotly into an html file, then sends the html file to a SFTP server
Figured it out...
import sys
import platform
import imp
print("Python EXE : " + sys.executable)
print("Architecture : " + platform.architecture()[0])
#print("Path to arcpy : " + imp.find_module("arcpy")[1])
#raw_input("\n\nPress ENTER to quit")
Run this to get the proper path to your Python.exe, and place this in Program/Script.
Then you need to verify that EVERY directory in your script starts at C:/ and works its way through the full path.
Related
The following code takes in path to an image, removes the background, and saves it to desktop under a name the user decides:
from rembg import remove
from PIL import Image
input_path = input("Please Drag & Drop an image:") # Takes image path
output_name = input("Give it a name:")
output_path = rf'C:\Users\user\Desktop\{output_name}.png'
input_image = Image.open(input_path)
output = remove(input_image)
output.save(output_path)
It works fine when I run it in PyCharm. I copy the image file, the code executes flawlessly and the output is seen in the desktop. But when I run the code through CMD terminal, it asks for image, and I drag the image to the terminal and it copies the path and everything works well, but when I press enter to begin I get this error and I cannot figure out what is the issue:
Does anyone know what the issue is?
You may encounter the loadlibrary failed with error 126 when the problematic application does not have the privileges to access a protected system resource. In this case, launching the problematic application as an administrator may solve the problem. I would recommend running the CMD terminal as an administrator
I am trying to launch Winidea configuration stored on U: drive. I am able to execute this script using command promt. However when I am trying to execute this script using Jenkins, it is giving error related to dll. My code is
import isystem.connect as ic
import time
print('isystem.connect version: ' + ic.getModuleVersion())
# 1. connect to winIDEA Application
pathTowinIDEA = 'C:/winIDEA/iConnect.dll'
cmgr_APPL = ic.ConnectionMgr(pathTowinIDEA)
cmgr_APPL.connectMRU('U:/winIDEA/myconfig.xjrf')
debug_APPL = ic.CDebugFacade(cmgr_APPL)
ec = ic.CExecutionController(cmgr_APPL)
The error is coming at line
cmgr_APPL.connectMRU('U:/winIDEA/myconfig.xjrf')
Error is as follow
enter image description here
I am very new to external script and python and was trying with very simple code.
Trying to print the data from a csv file.
execute sp_execute_external_script
#language = N'Python',
#script=N'
import pandas as pd
import csv
data=open("C:/Users/xxxxxx/Desktop/xxxxxx/Python/Pandas/olympics - Copy.csv")
data=csv.reader(data)
print(data)'
But I get below error
"FileNotFoundError: [Errno 2] No such file or directory: "
when I run the same code in jupyter notebook this runs fine.
import pandas as pd
oo=pd.read_csv('C:/Users/xxxxxx/Desktop/xxxxxx/Python/Pandas/olympics - Copy.csv')
oo.head()
what am i missing in SQL ? Can anyone please help me with the syntax?
Also, are there any good resources where I can learn more of using python in SQL 2017?
The SQL Server you are calling when executing sp_execute_external_script (SPEES), where is that installed; on your machine, or?
Don't forget when you execute SPEES it runs from the SQL box, so unless it is on your machine, it won't work. Even if it is on your machine it may not have permissions to the directory your file is in.
If the SQL is installed on your box, I suggest you create a new directory which you five EVERYONE access to and try with that directory.
What I am trying to do
I have a front end system that is generating output. I am accessing this data(JSON) with a post request using bottle. My post receives the json without issue. I need to execute a backend python program(blender automation) and pass this JSON data to that program.
What I have tried to do
Subprocess - Using subprocess call the program and pass the input. In appearance seems to execute but when i check System Monitor the program is not starting but my server continues to run as it should. This subprocess command runs perfectly fine when executed independently from the server.
blender, script, and json are all string objects with absolute file paths
sub = subprocess.Popen([blender + " -b -P " + script + " -- " + json], stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=False)
C Style os.fork() - Same as above which i found reading pydoc that subprocess operates using these methods
Double Fork - From a posting on here tried forking from the server and then calling subprocess from that fork and terminating the parent of the subprocess to create an orphan. My subprocess command still does not execute and never shows up in System Monitor.
What I need
I need a solution that will run from the bottle server in its own process. It will handle multiple requests so the subprocess cannot block in the server. The process being called is fully automated and just requires sending the JSON data in the execution command. The result of the subprocess program will be string path to a file created on the server.
The above subprocess works perfectly fine when called from my test driver program. I just need to connect the execution to the webservice so my front end can trigger its execution.
My bottle post method - prints json when called without issue.
#post('/getData')
def getData():
json_text = request.json
print(json_text)
I am not sure where to go from here. From what i have read thus far, subprocess should work. Any help or suggestions would be very much appreciated. If additional information is needed please let me know. I will edit with more details. Thank you.
Relevant Information:
OS: Ubuntu 16.04 LTS,
Python 3.x
*EDIT
This isn't an elegant solution but my subprocess call works now.
cmd = blender
cmd += " -b -P "
cmd += script
cmd += " -- "
cmd += str(json)
sub = subprocess.Popen([cmd], shell=True)
It seems by setting shell=True and removing the stdout, stderr=PIPE allowed me to see output where i was throwing an unhandled exception because my json data was a list and not a string.
When using python for executing your scripts a process created by Popen.subprocess will unintentionally inherited and keeps open a file descriptor.
You need to close that so that process can run independently. (close_fds=True)
subprocess.Popen(['python', "-u", Constant.WEBAPPS_FOLDER + 'convert_file.py', src, username], shell=False, bufsize=-1, close_fds=True)
Alsso, u dont have to use shell for creating another process. It might have unintended consequences.
I had the exact same problem where bottle was not returning/hangs. It works now.
I'm trying to run a .sh file loading from a .py file in a PySpark's job but I receive a message always saying that .sh file is not found
This is my code:
test.py:
import os,sys
os.system("sh ./check.sh")
and my gcloud command:
gcloud beta dataproc jobs submit pyspark --cluster mserver file:///home/myuser/test.py
test.py file is loaded well but the system can't find check.sh file
I figure out that is something related with the file's path but not sure
I tried also with os.system("sh home/myuser/check.sh") and same result
I think that this should be easy to do so ... ideas?
The "current working directory" used by Dataproc jobs submitted through the API is a temporary directory with a unique name for each job; if the file wasn't uploaded with the job itself, you'll have to access it using your absolute path.
If you indeed added the check.sh file manually to /home/myuser/check.sh, then you should be able to call it using the fully qualified path, os.system("sh /home/myuser/check.sh"); make sure to start your absolute path with a /.