We have written a python script to run within a forced speech alignment program. The speech alignment program was written with python but is run as an image through a Virtual Machine. The script instructs the program to align all of the files in a designated folder that is shared between the Virtual Machine and the computer's hard drive.
The command line of the VM image points to the shared folder where the files and the python script are located. It successfully opens the python script but once we try to open the directory specified in the script it says that there is no such file found. Would this have anything to do with the fact that it is being run in the virtual machine?
Here is the part of the script that points to the directory:
import sys
import os
def main():
direct=r'/Desktop/Shared/sf_VM_Shared/faseAlign/F3'
for file in os.listdir(direct):
and here is the error message:
ubuntu#BCE:~/Desktop/Shared/sf_VM_Shared/faseAlign/F3$ python3 FASE.py
Traceback (most recent call last):
File "FASE.py", line 19, in <module>
main()
File "FASE.py", line 9, in main
for file in os.listdir(direct):
FileNotFoundError: [Errno 2] No such file or directory: '~/Desktop/Shared/sf_VM_Shared/faseAlign/F3'
Related
for the thesis work on forensic analysis I should try to automatically delete a file created and placed in the "system32" folder.
This is the code I ran:
os.system("C://Windows//System32//update.exe")
os.chmod("C://Windows//System32//update.exe", stat.S_IRWXU)
os.remove("C://Windows//System32//update.exe")
The error is as follows:
Traceback (most recent call last): File "C:\Users\xxxx\PycharmProjects\Tesi\main.py", line 5, in <module> os.chmod("C://Windows//System32//update.exe", stat.S_IRWXU) PermissionError: [WinError 5] Accesso negato: 'C://Windows//System32//update.exe'
How can I run it with the right permissions?
Depends on how you are running the Python interpreter. If you are using Powershell, you can Right-click the Powershell icon and run it as Administrator. After this, any Python script you run from that shell will also run with admin rights.
When using the qtmoden library with python.
It works fine when running the code in VS Code.
But after using pyinstaller, it doens't anymore. When opening teh generated .exe file, it states that it does not have access to files located in - C:\Users\MyUsername\AppData\Local\Programs\Python\Python37-32\Lib\site-packages\qtmodern\resources
When running the .exe aplication it errors stating:
Traceback (most recent call last):
File "my_filename.py", line 262, in (this number differs depending on my app/code)
File "qtmodern\styles.py", line 70, in dark
File "qtmodern\styles.py", line 23, in _apply_base_theme
FileNotFoundError: [Errno 2] No such file or directory: " 'C:\sers\MyName\AppData\Local\Temp_MEI166802\qtmodern\resources/styles.qss'
[36020] failed to execute script my_filename
Anybody any idea how to get this fixed?
How to make sure pyinstaller also takes these 2 stypes.py files into account?
I tried adding data with pyinstaller via the --add--data command and including paths with --paths command, But the error message stays the exact same.
I have this Python code: https://github.com/andreagrandi/aoc_2019/tree/master/aoc
which runs perfectly from the terminal (Python 3 required) if I do for example: python aoc_03.py
But if I try to run it from VSCode, taking advantage of the Python extension and integration, I get this error:
(aoc) ➜ advent_of_code_2019 git:(master) /Users/andrea/.virtualenvs/aoc/bin/python /Users/andrea/Documents/advent_of_code_2019/aoc/aoc_03.py
Traceback (most recent call last):
File "/Users/andrea/Documents/advent_of_code_2019/aoc/aoc_03.py", line 70, in <module>
with open('aoc_03_input.txt', 'r') as file:
FileNotFoundError: [Errno 2] No such file or directory: 'aoc_03_input.txt'
My guess is that when invoked from VSCode, the script is run from a different path, so it cannot find the file aoc_03_input.txt which is located in the same folder of the script.
How do I tell VSCode to run my script from the /Users/andrea/Documents/advent_of_code_2019/aoc/ folder, so that it will be able to find my input file?
Thanks
Actually, I should have tried more before asking this question, because I just found the solution, but at this point I will write it here in case it can be useful to anyone:
If I change the path in this way:
with open('./aoc_03_input.txt', 'r') as file:
The file is being open correctly when I run the code in VSCode and when I run it from the terminal. Tested under OSX (but it should work under Linux too. Not sure about Windows).
I need some help troubleshooting something that should be easy to figure out. I have the following files in this folder on my computer: C:\Users\theda\Documents\Python\CANSLIM Script
run_script.bat
client_secrets.json
credentials.json
settings.yaml
These same files (except for the .bat file) plus my Python code are in this folder: C:\Users\theda\PycharmProjects\CANSLIM_Script
.bat file code:
cmd /k python C:\Users\theda\PycharmProjects\CANSLIM_Script\canslim_script.py
When I run my script by double-clicking on run_script.bat, it is able to find my client_secrets.json file and authenticate me with Google Drive. However, when I run the same .bat file through Windows Task Scheduler, I am getting the following Traceback:
Traceback (most recent call last):
File "C:\Program Files\Python37\lib\site-packages\oauth2client\clientsecrets.py", line 121, in _loadfile
with open(filename, 'r') as fp:
FileNotFoundError: [Errno 2] No such file or directory: 'client_secrets.json'
Where do I need to place my credentials/settings/etc. for PyDrive when running a Python script with a .bat file through Windows Task Scheduler? Or, how can I figure out where it is looking for the file?
I was able to get this to work by supplying a location to my auth and settings files using the following lines of code. Hope it helps someone:
secrets_file = os.path.normpath("C:/Users/theda/Documents/Python/CANSLIM Script/client_secrets.json")
settings_file = os.path.normpath("C:/Users/theda/Documents/Python/CANSLIM Script/settings.yaml")
gauth = GoogleAuth(settings_file=settings_file)
GoogleAuth.DEFAULT_SETTINGS['client_config_file'] = secrets_file
I have created a little script that I want to run as an executable on Mac and Windows.
I created the executable as one file using --onefile and I want to work with files in the same directory as the executable.
In windows os.getcwd() works fine after using pyinstaller but on mac it reverts to the base path:
> /Users/User
Traceback (most recent call last):
File "test.py", line 93, in <module>
FileNotFoundError: [Errno 2] No such file or directory: '/Users/user/Invoices/'
[62121] Failed to execute script test
logout
When I run it as a .py file however it gets the right directory on mac as well.
I have tried changing os.getcwd() to os.path.realpath(__file__) yet it still gives the wrong path when converted with pyinstaller.
I want to be able to move the executable around on mac and work with whatever directory it is in.
It turns out that the following works:
dir_path = slash.join(sys.argv[0].split(slash)[:-1])
this works only when using the executable on mac. On windows I still use os.getcwd and when running the python script as well.