How to translate a file from ui to py for pyside2? - python

I am trying to translate a file from a ui file in python
I am writing a team
pyside-uic "C:\test.ui" -x -o "C:\test.py"
in team squad, but it tells me that there is no such team.
Changed to "pyside2-uic" but still did not help
Tell me how to fix it?
Python 3.7.6 and Pyside2.
I tried to use
import sys, pprint
from pysideuic import compileUi
pyfile = open("[path to output python file]\output.py", 'w')
compileUi("[path to input ui file]\input.ui", pyfile, False, 4,
False)
pyfile.close()
but module pysideuic not found.
What else can i do?
I haven’t installed pyside2-tools or pyside-tools for some reason, so if I need to download them somewhere, tell me how. I already tried downloading through pip but it didn’t work.

I'm not sure that I fully understood your question as "team squad" isn't clear for me.
But I'm sure that you need to install pyside2-tools as UI compiler is a part of this package.
And I want to mention that pyside-uic was removed starting from some python version (I think 3.8, but not sure).
With actual version you should use following command (linux example, but for windows it is very similar):
uic -g python -o <ouput_python_file> <input_ui_file>

<resources>
<include location="ui.files.qrc"/>
</resources>
actually, ui is folder, like this:
D:\qt5_design\project\ui\files.qrc
pyrcc5 files.qrc -o ui.files.py

Related

PythonKit can't find PYTHON_LIBRARY for Python3

I'm using PythonKit in my Swift project for MacOS. At the moment I'm using Python 2.7 but from MacOs 12.3 it isn't no more supported so I'm trying to migrate to Python 3 but it doesn't work.
func applicationDidFinishLaunching(_ notification: Notification) {
if #available(OSX 12, *) {
PythonLibrary.useVersion(3)
}
else {
PythonLibrary.useVersion(2)
}
let sys = Python.import("sys")
print("Python \(sys.version_info.major).\(sys.version_info.minor)")
print("Python Version: \(sys.version)")
print("Python Encoding: \(sys.getdefaultencoding().upper())")
sys.path.append(Bundle.main.resourceURL!.absoluteURL.path)
let checker = Python.import("checkLibrary")
_ = Array(checker.check())
}
This is the error message:
PythonKit/PythonLibrary.swift:46: Fatal error: Python library not found. Set the PYTHON_LIBRARY environment variable with the path to a Python library.
The code fail on MacOs 12 on line 9th line (let sys = Python.import("sys")), so I can't interact so sys in any way.
I've already tried to disable sandbox and Hardened Runtime but is seems useless.
I was having the same issue.
where python3
which python3
type -a python3
I could clearly see that Python3 was present using any of the above commands from terminal. Python3 wasnt something that I directly installed, (probably something I added during an install of XCode) but I could see it located at "/usr/bin/python3"
I had already removed the sandbox and disabled the hardened runtime.
Adding the environment variable to XCode did not work and Google ultimately told me to do what had already been done.
Finally, I decided to just perform a fresh install, following the blog as guidance.
https://www.dataquest.io/blog/installing-python-on-mac/#installing-python-mac
https://www.python.org/downloads/macos/ (direct URL for Python download)
After installing, everything worked as expected.
PythonLibrary.useVersion(3)
PythonLibrary.useLibrary(at: "/usr/local/bin/python3")
I could use either of the above methods, without adding the environment variable to the XCode scheme.
Hopefully that helps

pyinstaller creating EXE RuntimeError: maximum recursion depth exceeded while calling a Python object

I am running WinPython 3.4.4.3 with pyinstaller 3.2 (obtained via pip install pyinstaller).
Now I've got some really simple Qt4 code that I want to convert to EXE and I've run into problem that I cannot solve.
The Code:
import sys
import math
from PyQt4 import QtGui, QtCore
import SMui
import numpy as np
from scipy.interpolate import InterpolatedUnivariateSpline
class SomeCalculation(QtGui.QMainWindow, SMui.Ui_MainWindow):
def __init__(self):
super(self.__class__, self).__init__()
self.setupUi(self)
self.setWindowTitle('Some Calculation')
self.calculate.clicked.connect(self.some_math)
def some_math(self):
a_diameter=self.a_diameter.value()
b_diameter=self.b_diameter.value()
complement=self.complement.value()
angle=self.angle.value()
preload=self.preload.value()
### ONLY MATH HAPPENS HERE also defining X and Y ####
interpolator = InterpolatedUnivariateSpline(X, Y)
### MORE MATH HAPPENS HERE ####
self.axial.setText(str(axial))
self.radial.setText(str(radial))
def main():
app = QtGui.QApplication(sys.argv)
window=SomeCalculation()
window.show()
app.exec_()
if __name__=='__main__':
main()
I try to run pyinstaller file_name.py and I'm getting:
RuntimeError: maximum recursion depth exceeded while calling a Python object
Now if there's a few things that I have found out that also affect the issue:
1) If I comment out this line: from scipy.interpolate import InterpolatedUnivariateSpline
2) Creating EXE file from another different script that uses Scipy.Interpolate (RBS, but still) - works like a charm.
3) If I try to convert it to EXE using WinPython 3.5.1.1 + pyinstaller obtained the same way, and it's the same 3.2 version of it - it generates my exe file no problems.
I want to understand what's causing the error in the original case and I cannot find any answer on google unfortunately, most of the fixes I could find were related with matplotlib and not interpolation though.
This worked for me
Run pyinstaller and stop it to generate the spec file :
pyinstaller filename.py
A file with .spec as extension should be generated
Now add the following lines to the beginning of the spec file :
import sys
sys.setrecursionlimit(5000)
Now run the spec file using :
pyinstaller filename.spec
Mustafa did guide me to the right direction, you have to increase the recursion limit. But the code has to be put to the beginning of the spec file and not in your python code:
# -*- mode: python -*-
import sys
sys.setrecursionlimit(5000)
Create the spec file with pyi-makespec first, edit it and then build by passing the spec file to the pyinstaller command. See the pyinstaller manual for more information about using spec files.
Please make sure to use pyinstaller 3.2.0, with 3.2.1 you will get ImportError: cannot import name 'is_module_satisfies' (see the issue on GitHub)
i'd try to increase recursion depth limit. Insert at the beginning of your file:
import sys
sys.setrecursionlimit(5000)
Even until March 2020, this issue has not been solved yet. As per some people's explanation, I increased setrecursionlimit in .spec file and tried to build it, but it did not work.
Through googling, I found out that this issue is caused by conflict of latest version of openpyxl and pyinstaller. Older version of openpyxl, such as 2.3.5 version, does not cause this issue.
As such, solution for this issue is as follows.
pip uninstall openpyxl
pip install openpyxl==2.3.5
Sometimes even the limit 5000 is not enough. It helped me to set limit to 20000. (in file 'filename.spec')
import sys
sys.setrecursionlimit(20000)
make new environment with pipenv and install just the requirements package.
(unused package which you have on your environment will cause the increase of the size of .exe file and make this error happen )
i try with python 3.8 and it worked
You can make changes to the recursion limit in the following manner:
import sys
sys.setrecursionlimit(1000)
I was facing the same issue. I tried most of the things suggested here. But, I could not solve the issue on my laptop. What worked for me is summarized below:
Open Anaconda prompt.
Activate your environment using conda activate my_env.
Navigate to your project folder from the Anaconda command prompt using cd your_folder_directory.
Run pyinstaller --onefile my_python_file.py
This should not create any recursion error.
This will create a dist folder in your project directory. Your executable will present in this folder.
install pyinstaller last developer version:
pip uninstall pyinstaller
pip install https://github.com/pyinstaller/pyinstaller/archive/develop.zip

PyQt5 error during "python3 configure.py": fatal error: 'qgeolocation.h' file not found

MAC OSX 10.9, Python 3.5, sip-4.17, PyQt-gpl-5.5.1, Qt5.5.1
Hi,
trying to build PyQt on my system I did the following steps:
download/install Qt5.5.1 libraries
download/unpack SIP
download/unpack PyQt
install SIP:
python3 configure.py -d /Library/Python/3.5/site-packages --arch x86_64
make
sudo make install
tried to install PyQt:
python3 configure.py -d /Library/Python/3.5/site-packages
--qmake /.../Qt5.5.1/5.5/clang_64/bin/qmake
Configuration stopped with:
/Users/werner/OpenSource/PyQt/sip/QtPositioning/qgeolocation.sip:28:10:
fatal >error: 'qgeolocation.h' file not found
#include <qgeolocation.h>
^
1 error generated.
make[1]: *** [sipQtPositioningcmodule.o] Error 1
make: *** [sub-QtPositioning-make_first-ordered] Error 2
I tried to finish installation doing
make
sudo make install
anyway. But the installation doesn't seem to be complete (e.g. uic, pyuic5 are missing). Here is what my installation directory looks like:
>ls /Library/Python/3.5/site-packages/PyQt5
QtBluetooth.so QtSensors.so
QtCore.so QtSerialPort.so
QtDBus.so QtSql.so
QtDesigner.so QtSvg.so
QtGui.so QtTest.so
QtHelp.so QtWebKit.so
QtMacExtras.so QtWebKitWidgets.so
QtMultimedia.so QtWidgets.so
QtMultimediaWidgets.so QtXml.so
QtNetwork.so QtXmlPatterns.so
QtOpenGL.so _QOpenGLFunctions_2_0.so
QtPrintSupport.so _QOpenGLFunctions_2_1.so
QtQml.so _QOpenGLFunctions_4_1_Core.so
QtQuick.so
I couldn't find any useful information when searching for other discussions, so I hope someone can give me a hint on what I'm (maybe stupidly) doing wrong. Thank you for taking the time to read this.
If you don't need this module, the better way to solve that is disabling it on configure.
python configure.py --disable=QtPositioning
Just yesterday, I also met such a problem. And this is what I do to solve it:
Create a header file qgeolocation.h in /PyQt-gpl-5.5.1/QtPositioning, and copy the content into it from this website. Then I go sudo make and sudo make install successfully.
Though I do not know whether it is right to solve this problem, fortunately, I installed the PyQt and entered eric6. Hope you make successfully, too.
Adding the location.h header file for me on OSX 10.11.1.
I had the problem in both PyQt-gpl-5.5.1 and PyQt-gpl-5.5.2, but after adding the
file, was able to build.
The way of creating a qgeolocation.h in /PyQt-gpl-5.5.1/QtPositioning worked for me. The QtPositioning.so was created.
You can also take the header file from your qt source folder (you have installed the source files together with binaries, right?), it is located here:
/Src/qtlocation/src/positioning/qgeolocation.h
and then just copy it into:
/PyQt-gpl-X.X.X/QtPositioning/qgeolocation.h
as follows. It should solve the problem in 99.9% cases.

Any pyinstaller detailed example about hidden import for psutil?

I want to compile my python code to binary by using pyinstaller, but the hidden import block me. For example, the following code import psutil and print the CPU count:
# example.py
import psutil
print psutil.cpu_count()
And I compile the code:
$ pyinstaller -F example.py --hidden-import=psutil
When I run the output under dist:
ImportError: cannot import name _psutil_linux
Then I tried:
$ pyinstaller -F example.py --hidden-import=_psutil_linux
Still the same error. I have read the pyinstall manual, but I still don't know how to use the hidden import. Is there a detailed example for this? Or at least a example to compile and run my example.py?
ENVs:
OS: Ubuntu 14.04
Python: 2.7.6
pyinstaller: 2.1
Hi hope you're still looking for an answer. Here is how I solved it:
add a file called hook-psutil.py
from PyInstaller.hooks.hookutils import (collect_data_files, collect_submodules)
datas = [('./venv/lib/python2.7/site-packages/psutil/_psutil_linux.so', 'psutil'),
('./venv/lib/python2.7/site-packages/psutil/_psutil_posix.so', 'psutil')]
hiddenimports = collect_submodules('psutil')
And then call pyinstaller --additional-hooks-dir=(the dir contain the above script) script.py
pyinstall is hard to configure, the cx_freeze maybe better, both support windows (you can download the exe directly) and linux. Provide the example.py, In windows, suppose you have install python in the default path (C:\\Python27):
$ python c:\\Python27\\Scripts\\cxfreeze example.py -s --target-dir some_path
the cxfreeze is a python script, you should run it with python, then the build files are under some_path (with a lot of xxx.pyd and xxx.dll).
In Linux, just run:
$ cxfreeze example.py -s --target-dir some_path
and also output a lot of files(xxx.so) under some_path.
The defect of cx_freeze is it would not wrap all libraries to target dir, this means you have to test your build under different environments. If any library missing, just copy them to target dir. A exception case is, for example, if your build your python under Centos 6, but when running under Centos 7, the missing of libc.so.6 will throw, you should compile your python both under Centos 7 and Centos 6.
What worked for me is as follows:
Install python-psutil: sudo apt-get install python-psutil. If you
have a previous installation of the psutil module from other
method, for example through source or easy_install, remove it first.
Run pyinstaller as you do, without the hidden-import option.
still facing the error
Implementation:
1.python program with modules like platform , os , shutil and psutil
when i run the script directly using python its working fine.
2.if i build a binary using pyinstaller. The binary is build successfully. But if i run the binary iam getting the No module named psutil found.I had tried several methods like adding the hidden import and other things. None is working. I trying it almost 2 to 3 days.
Error:
ModuleNotFoundError: No module named 'psutil'
Command used for the creating binary
pyinstaller --hidden-import=['_psutil_linux'] --onefile --clean serverHW.py
i tried --additional-hooks-dir= also not working. When i run the binary im getting module not found error.

Convert pyQt UI to python

Is there a way to convert a ui formed with qtDesigner to a python version to use without having an extra file?
I'm using Maya for this UI, and converting this UI file to a readable python version to implement would be really great!
You can use pyuic4 command on shell:
pyuic4 input.ui -o output.py
For pyqt5 you can use
pyuic5 xyz.ui > xyz.py
or
pyuic5 xyz.ui -o xyz.py
If you are using windows, the PyQt4 folder is not in the path by default, you have to go to it before trying to run it:
c:\Python27\Lib\site-packages\PyQt4\something> pyuic4.exe full/path/to/input.ui -o full/path/to/output.py
or call it using its full path
full/path/to/my/files> c:\Python27\Lib\site-packages\PyQt4\something\pyuic4.exe input.ui -o output.py
The question has already been answered, but if you are looking for a shortcut during development, including this at the top of your python script will save you some time but mostly let you forget about actually having to make the conversion.
import os #Used in Testing Script
os.system("pyuic4 -o outputFile.py inpuiFile.ui")
Quickest way to convert .ui to .py is from terminal:
pyuic4 -x input.ui -o output.py
Make sure you have pyqt4-dev-tools installed.
I'm not sure if PyQt does have a script like this, but after you install PySide there is a script in pythons script directory "uic.py". You can use this script to convert a .ui file to a .py file:
python uic.py input.ui -o output.py -x
You don't have to install PyQt4 with all its side features, you just need the PyQt4 package itself. Inside the package you could use the module pyuic.py ("C:\Python27\Lib\site-packages\PyQt4\uic") to convert your Ui file.
C:\test>python C:\Python27x64\Lib\site-packages\PyQt4\uic\pyuic.py -help
update python3: use pyuic5 -help # add filepath if needed. pyuic version = 4 or 5.
You will get all options listed:
Usage: pyuic4 [options] <ui-file>
Options:
--version show program's version number and exit
-h, --help show this help message and exit
-p, --preview show a preview of the UI instead of generating code
-o FILE, --output=FILE
write generated code to FILE instead of stdout
-x, --execute generate extra code to test and display the class
-d, --debug show debug output
-i N, --indent=N set indent width to N spaces, tab if N is 0 [default:
4]
-w, --pyqt3-wrapper generate a PyQt v3 style wrapper
Code generation options:
--from-imports generate imports relative to '.'
--resource-suffix=SUFFIX
append SUFFIX to the basename of resource files
[default: _rc]
So your command will look like this:
C:\test>python C:\Python27x64\Lib\site-packages\PyQt4\uic\pyuic.py test_dialog.ui -o test.py -x
You could also use full file paths to your file to convert it.
Why do you want to convert it anyway? I prefer creating widgets in the designer and implement them with via the *.ui file. That makes it much more comfortable to edit it later. You could also write your own widget plugins and load them into the Qt Designer with full access. Having your ui hard coded doesn't makes it very flexible.
I reuse a lot of my ui's not only in Maya, also for Max, Nuke, etc.. If you have to change something software specific, you should try to inherit the class (with the parented ui file) from a more global point of view and patch or override the methods you have to adjust. That saves a lot of work time. Let me know if you have more questions about it.
I got some errors when I try to convert UI to PY and finally I found this solution.
First of all, if you couldn't find the pyuic5.bat file copy this code and paste it on your cmd:
C:\Users\Monster>cd Desktop
C:\Users\Monster\Desktop>python -m PyQt5.uic.pyuic -x trial.ui -o trial.py
And the problem has been solved easily!
Update for anyone using PyQt5 with python 3.x:
Open terminal (eg. Powershell, cmd etc.)
cd into the folder with your .ui file.
Type:
"C:\python\Lib\site-packages\PyQt5\pyuic5.bat" -x Trial.ui -o trial_gui.py
for cases where PyQt5 is not a path variable. The path in quotes " " represents where the pyuic5.bat file is.
This should work!
For Ubuntu it works for following commands;
If you want individual files to contain main method to run the files individually, may be for testing purpose,
pyuic5 filename.ui -o filename.py -x
No main method in file, cannot run individually... try
pyuic5 filename.ui -o filename.py
Consider, I'm using PyQT5.
open cmd in directory where you have your file and type:
pyuic5 –x "filename".ui –o "filename".py
I've ran into the same problem recently. After finding the correct path to the pyuic4 file using the file finder I've ran:
C:\Users\ricckli.qgis2\python\plugins\qgis2leaf>C:\OSGeo4W64\bin\pyuic4 -o ui_q gis2leaf.py ui_qgis2leaf.ui
As you can see my ui file was placed in this folder...
QT Creator was installed separately and the pyuic4 file was placed there with the OSGEO4W installer
In case that you are using Pyside6, there is a 'uic' binary file (in windows, an exe file) in /Lib/site-packages/PySide6/

Categories

Resources