Vision API Web Detection Script - python

I'm trying to run the sample web detection script (web_detect.py) for the Vision API but am not having any luck. See here for more details on the script.
I've saved the script into a separate python file. I then try to run the file in my python notebook using:
python web_detect.py "http://www.photos-public-domain.com/wp-content/uploads/2011/01/old-vw-bug-and-van.jpg"
... but I get the following error:
File "<ipython-input-15-b3220db6427b>", line 1
python web_detect.py "http://www.photos-public-domain.com/wp-content/uploads/2011/01/old-vw-bug-and-van.jpg"
^
SyntaxError: invalid syntax
See the image below for a screenshot. Any suggestions on what I'm missing and how I can get the file to run?
Thank you!
RE

You need to add an exclamation mark (!) prior to your whole python command so that the notebook will treat it as a command line execution.
I did test on my notebook using your input image and I got the expected response.
Command to run: !python web_detect.py http://www.photos-public-domain.com/wp-content/uploads/2011/01/old-vw-bug-and-van.jpg
Test:

Related

Run a basic command in Command Prompt using Apache spark with PySpark

I try to import data frame into spark using python pyspark. fro that I used jupter notebook and I write bellow code and i Got out put like below..
After that I want to run this in CMD fro that I save my python codes in text file and save as test.py (As python file) Then I Run that python file in cmd using python test.py command below the screen shot
So my task is completed but after 3 or 4 hours later I again try to do same process..Then unfortunately I got bellow error message can some one explain why its happens? because before its correctly worked, but after that its not work and I not did any changes between these two attempt. below have full error now have facing.
It looks that you have not set the Hadoop home (winutil.exe) in the command session which you have opened later.
The spark is unable to locate HADOOP_HOME. Check if you had set something different when you ran the command 1st time.

Is it possible to convert an entire PDF file to a bunch images using ImageMagick (Ubuntu, Python)?

I have a Python app which among others converts an entire PDF file to a few jpg.
In Pycharm it is implemented by the code:
import subprocess
subprocess.check_call(["magick",Platforma_IoT.pdf,Platforma_IoT.jpg], shell=True)
That code in Pycharm on Windows 10 works completely fine, it converts every page of a pfd to jpg. But now I want to run that code using Bash console. Unfortunately, I am getting an error in the Bash:
import-im6.q16: unable to open X server `' # error/import.c/ImportImageCommand/358.
./sd.py: line 3: syntax error near unexpected token `["magick","Platforma_IoT.pdf","Platforma_IoT.jpg"],'
./sd.py: line 3: `subprocess.check_call(["magick","Platforma_IoT.pdf","Platforma_IoT.jpg"], shell = True)'
I also tried that code:
import subprocess
subprocess.check_call(["convert","Platforma_IoT.pdf","Platforma_IoT.jpg"])
But I am getting the same error in the bash.
I just want to run code which converts every page of PDF to an image using bash console. How can I do that?
You met a wrong script interpretation. Use shebang to define the right interpretator:
#!/usr/bin/env python3
Or you can launch your script in python directly:
python3 script.py

Basic File Won't Run -> Unable to initialize device PRN

I am very new to Python, and have recently switched to VS Code from Jupyter Notebooks, and am trying to run some simple code but am getting an error.
I've looked around for the solution already, and I can find the same error message but nothing matches my issue.
I'm just doing very basic code:
msg = 'Hello World'
print('msg')
The error message I get is in the terminal and looks like this:
(base) C:\Projects\Python\Tutorial>print(msg)
Unable to initialize device PRN
As rayryeng said you need to run your code in a Python environment.
If you are using VS code there is Python REPL where you can run your code interactively. To activate it you can press Ctrl+Shift+P and type/find Python: Start REPL after that you will see terminal panel at the bottom of VS Code as on screenshot:
Sure, you need VS Code Python extension and Python itself installed in your system.
Alternatively you can run Python shell directly from your command line by typing python or python2/python3 depending on your installed version. Python must be in the PATH variable

Python Code to Automate Abaqus Run Script

Error with Subprocess addition
This is the error I get regarding the abaqus module
I'm quite new to python and so please don't mind if this question might seem silly.
So I have python file that does the function of opening an abaqus viewer and I have another python file that describes the functions I want to do in the abaqus viewer.
I need a piece of code that can automate the second script without me having to manually go into file>run script.
Script to Open Abaqus:
import os
import subprocess
os.startfile('Q:/win_apps/scripts/simulia/Abaqus/6.14-3/Use_these_if_not_working/abq6143_viewer.bat')
And then I have a python script that has the code regarding my output requests from abaqus viewer.
What line can I add to the above file to automatically take the second python script and run it?
When running Abaqus with the typical start up scripts you can pass Abaqus/Viewer a script to run from the command line:
abq6143 viewer noGUI=script.py
where you replace script.py with the name of your Python script. This will start up Abaqus/Viewer with no user interface, run the script, and then quit.
If you want the user interface to come up and automatically run your script you can use the script= command instead of noGUI:
abq6143 viewer script=script.py
I see that you're using a custom batch file to start up Abaqus/Viewer. Without seeing those contents I couldn't say exactly how you would integrate the above, but you will probably need to adjust the relevant line in the batch file with the noGUI or script command.

Command line within python script giving syntax error

I am trying to run a simple command line from python.
While the code works in Jupyter notebook it throws syntax error in Spyder.
Strangely if I run the same command line within test() below inside console it executes but script shows error.
Below is my code. TIA!
def test():
!start excel
test()
!start excel works in Jupyter notebook because the Jupyter shell is able to understand the ! prefix and run a native (Windows) command.
!: to run a shell command. E.g., ! pip freeze | grep pandas to see what version of pandas is installed.
But !start excel isn't valid python syntax. You need the exact python equivalent (for Windows at least):
import os
os.startfile("excel")

Categories

Resources