I've written a script to rename my photos according to the date they were recorded. It runs on mac and uses the CLI exiftool by phil harvey.
The command that create problem is the following:
os.popen("exiftool " + file path)
I wrote the script using Pycharm CE. I used the exiftool because it yielded the best results and was the easiest to use at the time. With the command mentioned above, I got all the metadata nicely formatted by the exiftool and it only needed to be separated and put in a list. I tried everything in the console of Pycharm CE before I wrote the script.
The script and the console of Pycharm both worked fine. However, I tried recently to run the script with the IDLE from python. The script failed because the return from the console was always an empty string. Upon further research I used the subprocess.run()method. The error was
CompletedProcess(args='exiftool PATH', returncode=127, stdout=b'', stderr=b'/bin/sh: exiftool: command not found\n')
The output was also empty.
My questions are now:
Why does the Console and the interpreter of Pycharm CE find the exiftool but the console and the IDLE of python don't?
Is there a way to include the installation location of the exiftool so it is found by the os.popen() / subprocess.run() methods in the IDLE and the console?
Many thanks for your help
AliSot2000
At your command prompt, type which exiftool to find the full path to the executable. Then, instead of just calling exiftool in your Python script, use the full path.
Turns out, using which exiftool was indeed the solution.
I deinstalled python, reinstalled the newer version and tried the fix, proposed in the comment. (Using said command in Terminal and calling the command with the full path) It worked in the IDLE once I installed Python 3.7. I ran previously Python 2.7 on my MacBook.
I still don't understand why 2.7 wouldn't work.
Anyway thanks for the tip.
Related
I have a CodeDeploy which deploys application on Windows instances. I have a Python script which is running as part of ValidateService hooks. Below is the code I have in that script:
print("hello")
So, I have removed everything and just printing hello as part of this script. When this script is called by CodeDeploy I get below error:
My appspec.yml file:
...
ValidateService:
- location: scripts/verify_deployment.py
timeout: 900
I tried getting some help on Google but got nothing. Can someone please help me here.
Thanks
As Marcin already answered in a comment, I don't think you can simply run python scripts in CodeDeploy. At least not natively.
The error you see means that Windows does not know how to execute the script you have provided. AFAIK Windows can't run python natively (like most linux distros can).
I am not very accustomed to CodeDeploy, but given the example at https://github.com/aws-samples/aws-codedeploy-samples/tree/master/applications/SampleApp_Windows, I think you have to install python first.
After so much of investigations, I found my answer. The issue is little misleading, there is nothing to do with Code format or ENOEXEC. The issue was due to Python path. While executing my script, CodeDeploy was unable to find Python (Though I had already added python.exe in Environment variable path).
Also, I found that CodeDeploy is unable to execute .py file due to Python path issue. So, I created a PowerShell script and invoking Python script from there. Like below:
C:\Users\<username>\AppData\Local\Programs\Python\Python37-32\python.exe C:\Users\<username>\Documents\verify_deployment.py
It executed Python script successfully and gave me below output:
hello
I am trying to compile a .tex file in a Python script using pdflatex. The command pdflatex filename.tex works when I run it from the command line on Windows. However, attempting to run os.system("pdflatex filename.tex") just spits out 1 into the Python console and does not compile a pdf. I've also tried putting in the full file path similar to this person solved their problem but the same thing happens. Similarly, subprocess.call(['pdflatex', 'filename.tex']) just outputs a 1 and does not do anything.
It seems someone else has encountered the same problem in this thread, but on Mac instead of Windows. (But regardless of the operating system, they didn't find an answer.)
Why might this be happening?
EDIT: I've just discovered a solution. The script runs successfully (using the os.system approach) when I run the .py file using the command line. Previously I was attempting to run the script from RStudio, both using reticulate::source_python(filename) and also line-by-line via the reticulate REPL. Seems like the problem may actually be coming from R's reticulate package rather than anything to do with Python.
Fortunately RStudio has a terminal window so this doesn't end up being too inconvenient!
I'm using VS Code for a Python project using a virtualenv. I switched my deafult terminal from powershell to cmd as VS Code was not happy executing powershell scripts.
Now when I open a terminal in my project it opens cmd (as desired), but automatically tries tor run .../Scripts/Activate.ps1, which it doesn't like. I want it to run .../Scripts/Activate.bat as we are in cmd. Runnning it manually for now, but would be nice if I didn't have to.
No doubt there is a setting somewhere to change this, but I cannot find it. Any ideas?
This is a problem related to the Python extension, it should be fixed in the last update.
You can get some information from here.
I was normally using python3.7.3 on my system(Windows 10). A couple of days earlier I noticed that the command prompt won't run any of my python programs. It did nothing, no response. I thought there is a problem displaying the output stream so I ran an infinite loop(and was expecting to terminate the process, ctrl^c) but again no response. Even python --version command won't work. I uninstalled python3.7.3, downloaded the latest python3.8.5, and again the same problem. image from my cmd line
please help me out. I use sublime text so I prefer running my codes through cmd.
Update: Here is another snap of my command line after running commands in one answer and comments.
Also, I think the problem lies within the PATH setting but PATHs are already added.
image to enviornment variables, image to system variables
It is possible you failed to add python to your path in the installer.
Image displaying adding python to your path in the installer
You also may have forgotten to disable the path limit in the final set up screen.
Image displaying increase path limit in the installer
If you navigate to C:\Users\chira\AppData\Local\Programs\Python\Python38-32 then run python --version do you get any output?
I am right now in the same directory in which the file "lookup.csv" is residing.
I have tried following commands in Python 2.7:
import subprocess
subprocess.Popen("lookup.csv", shell = True)
The above is producing the following error:
lookup.csv : not found
I have double-checked for the working directory, tried lot of available troubleshooting options given in StakExchange, tried the same in Windows (and surprisingly it was working there), what more can I do?
There's no reason why this should work on Windows because lookup.csv clearly is a file which you want to open with open whereas subprocess.Popen creates a new process for working with the lookup.csv binary. Maybe Windows handles process failure differently.