pyuic5 not finding file - python

I am learning PyQt5, and while converting a ui to py, it throws this error:
Error: No such file or directory: "Disaster.ui"
The file name is Disaster.ui. The command is:
pyuic5 -x Disaster.ui -o abc.py

The error occurs because the file Disaster.ui does not exist in the current folder (i.e. wherever you're executing pyuic5 from). To prove this, execute dir *.ui.
To fix it, either cd to the relevant folder, or use an absolute path instead.

Related

Pyinstaller failed to execute script: FileNotFoundError: No file or directory: 'C:\\Users\\etc'

I have a python file I am converting to exe via Pyinstaller. The coversion runs fine with no error, however when I run the exe file I get error in line 13 of the python file (line is import librosa). Then I get a bunch of files and then a
FileNotFoundError: No file or directory: 'C:\\Users\\johnny\\Appdata\\Local\\Temp\\_MEI70722\\librosa\\util\\example_data\\registry.txt'.
Also the python file itself runs fine.
Any help would be appreciated
PyInstaller tries to find all the dependencies, however this file is not imported but loaded so it misses it. You can simply force it to add it:
--add-data [path to your python]/Lib/site-packages/librosa/util/example_data;librosa/util/example_data
With The full command be like :
pyinstaller --onefile [YourScript].py --add-data [path to your python]/Lib/site-packages/librosa/util/example_data/registry.txt;librosa/util/example_data
You'll need to specify the data files as PyInstaller hooks.
Create a folder "extra-hooks", and in it a file "hook-librosa.py"
paste these 2 lines in "extra-hooks/hook-librosa.py":
from PyInstaller.utils.hooks import collect_data_files
datas = collect_data_files('librosa')
Then tell PyInstaller where to locate this file with adding 1 of the following to your PyInstaller command:
--additional-hooks=extra-hooks
--additional-hooks-dir "[PATH_TO_YOUR_PROJECT]/axtra-hooks"
The 2nd one worked for me, and I was using auto-py-to-exe, built on PyInstaller.
I guess the file doesn't exist. Open a file manager and copy the directory.
In the PyInstaller, you should type in the python file's name and then --onefile. It makes an .EXE file (if you are on windows) with all the imported files within. You can learn more here: https://pyinstaller.readthedocs.io/en/stable/usage.html

Can not run exe packed by pyinstaller

I use windows 10 and python2.7.
I have use PyInstaller to pack a program into exe. But I can not run the .exe file.
error:
raise FileNotFoundError('Tcl data directory "%s" not found.' % (tcldir))
IOError: Tcl data directory "C:\Users\test\AppData\Local\Temp\_MEI10~1\tcl" not
found.
[4072] Failed to execute script pyi_rth__tkinter
That's python error which means your program is running.
Check your code to see why it does not find the file you are mentioning.
Note: If you use relative paths consider that it matters where the .exe file is executed.
This is the process home directory.
You should use the following command:
pyinstaller main.py --add-data 'tcl;./tcl' #linux separator use 'tcl:./tcl'
Note: left 'tcl' is in the main.py's directory, right 'tcl' is target directory which is exe genrated directory. if right 'tcl' not existing will be created!

set path for python command in shell(mac)

I want to run python command as follows, without the whole path of pyahp or other scripts. It reported the error. I have to add the whole path, ie .../site_packages/ that is tedious. How can I run it directly?
[~] python pyahp
/Library/Frameworks/Python.framework/Versions/3.6/Resources/Python.app/Contents/MacOS/Python: can't open file 'pyahp':
[Errno 2] No such file or directory
I trid to add pythonpath, however it failed.
export
PYTHONPATH="$PYTHONPATH:/Library/Frameworks/Python.framework/Versions/3.6/lib"

Python can't run absolute script?

I encountered such a weird situation:
naivechou#naivechou/~>python test.py
test
naivechou#naivechou/~>pwd
/home/naivechou
naivechou#naivechou/~>python /home/naivechou/test.py
C:\toolchain\python\python.exe: can't open file '/home/naivechou/test.py': [Errno 2] No such file or directory
My working directory is /home/naivechou/, test.py is in there.
If I run test.py with absolute path, I'll get an error message of No such file or directory.But everything will be fine if I enter that directory and then run it. What's wrong with python?
Try moving into the folder where the python script is located and do a "ls" command there in Linux. if windows then do 'dir'. if you see the required file there then execute the following command
C:\location_where_the_script_is> python yourfile.py
For commands entered on the command line, Windows doesn't recognize forward-slashes as directory separators.
Your second example is looking in the current directory for the literal filename /home/naivechou/test.py, and of course such a filename does not exist.
Use backslashes instead, as is the Windows way:
python \home\naivechou\test.py

How to set the correct path for a file in VIM?

Whenever I hit :pwd in vim the command always returns the path C:\Windows\system32, even if I'm in a Python file from the desktop. So whenever I run :!python % the command returns
python: can't open file '\Users\myname': [Errno 2] No such file or directory.
But if I set the path with the command :cd %:p:h and then run the same python command the Python file executes correctly. So basically I'm wondering how do I get vim to correctly set the path for every file that I open.
(i.e. if I'm in a file located at the desktop :pwd returns ~\Desktop\ or if I'm in a file in the home directory :pwd returns C:\Users\MyName\).
You can set autochdir:
:set autochdir
With this setting the current working directory will follow the file that you're editing.
See :help 'autochdir', and particularly this note:
Note: When this option is on some plugins may not work.

Categories

Resources