I have a big python program which contains a lot of python files, images, etc.
I tried to create an executable file of all the program, but it does not success.
I am using PyQt5, Tesorflow and many other classes.
I hope anyone can help to create an exe for my final univesity project.
Thank You a lot.
Here is a link with a sample. and here a nice article.
basically, you get a tool like pyinstaller:
pyinstaller --onefile <your_script_name>.py
If you have more than 1 file, as you say in your answer then you can use compile all:
compileall.compile_dir(dir, maxlevels=10, ddir=None, force=False, rx=None, quiet=0, legacy=False, optimize=-1, workers=1)
as shown here
Have a look at this Git project that uses IronPython
and this web page that has a step by step for IronPython
Good luck
Related
I have a data file inputpy.xlsx and I am converting this file to an opl input language(1 and 0) called outputpy.xlsx, and I have a working opl model that takes my outputpy.xlsx file and outputs to an excel file(oploutput.xlsx) from cplex ide.
However, my problem is I am currently running both of them separately.
First I am running python code to make outputpy.xlsx and than I am using cplex ide to make oploutput.xlsx.
My question is :
How can I call/run my cplex code from my python code, after I created the outputpy.xlsx in python? I don't want to run python code and then run the cplex ide separately.
what I find online is some suggest using python API or doccplex, I am not sure the difference between them. I believe that using python API I have to change the cplex code for the python language, and I also can't find the nice tutorial for this.
Do you have suggestions?
Thank you in advance.
One very simple way to do this is to use oplrun instead of the IDE. Using oplrun you can run a project and/or mod file from the command line. Then you can invoke this from Python using subprocess.popen() or just os.system() (see this related question).
The description of oplrun can be found in the reference documentation in chapter IDE and OPL > oplrun command line interface
In order to run OPL directly from Python you could have a look at the doopl package.
I have a few test files residing in test/ directory which has an __init__.py file. The test files are basically Python files but have the extension as .thpy (Python test files). Each of these tests internally use unittest.
For code coverage purposes, I'm using the trace module. coverage.py, unfortunately would have been ideal but at this time, doesn't give information on the number of line hits per line.
unittest and trace are not really compatible. unittest.py doesn't play well with trace.py - why?
For example: I have a file name cluster_ha.thpy. From the solution given for the above question, I need to mention module='cluster_ha' inside cluster_ha.thpy but because of the extension, Python doesn't look at it as a Python module.
Is there any way to get around this? Is there a hack that can make other extensions to be considered as a Python module? Or perhaps, there's another module out there which can help me get code coverage?
How do I cross-compile a QT application for a Freescale Hummingboard(imx6(arm))?
There are some guides around, but I've not been able to complete one with success.
The following (and more) guides give me a compile error on ./configure
http://forum.solid-run.com/linux-on-cubox-i-and-hummingboard-f8/qt5-3-on-hummingboard-t2072.html
https://community.freescale.com/docs/DOC-94066
When I run the ./configure command (With recommended commands, I've tried this with a lot of possibilities for commands but got none working). I got a compile error for all the external libraries QT uses (zlib, libjpeg, libpng, etc.). So it's a dead end from there.
I've tried a lot more stuff, I don't even remember all the stuff I've tried, but I got nothing working.
I'm trying to use mini-distribution for the Hummingboard. It's a system without window manager that is able to run QT applications (QT5). The build tool I'm trying to use is gcc-linaro-arm-linux-gnueabi, I'm using QT Creator. I've got QT working on the Hummingboard, I just can't compile anything for it.
I managed building an application for the IMX6 finally. Here is how I did it for other's. It's not an optimal solution but it is an solution.
I use Buildgear to build mini-distirbution as OS (Google it, not enough links with my reputation). I append my own application to this mini-distribution to also build it. This is done by placing creating a folder in the buildfiles/cross/cross-hummingboard folder and adding a buildfile (mine look like this http://pastebin.com/bZkJUiry). In this folder I also place a .tar of the project files (including the .pro). To get it to build I add "qt-gui" as a dependency to the fs (buildfiles/cross/cross-hummingboard/fs) by adding it to the list of depends.
I then run buildgear build fs, which will create an (Tarred) image including my (working) qt-application! I then extract the ./qt-gui executable and ssh it to the Hummingboard.
Of course this is all a bit cumbersome so I made a script that automates this all: http://pastebin.com/jFM6rZyY
It copies and Tars sources, compiles it together with the fs, extracts the executable, ssh's the file to the hummingboard and runs it. Takes about 3 minutes building but it works which is what counts for me at this point.
I am writing an extension for the Scratch text editor application on Elementary OS Luna. But the documentation is practically non-existent for extension creation and I have no idea how to proceed after writing my main code for the extension.
I've already written the extension. I cannot use or test it yet as it needs to be "installed". I spent hours looking for docs but they do not exist. I did however, find a comment on the scratch launchpad page that says
Generally you have to generate a pluginname.so file and put it in
lib/scratch/plugins/pluginname with a pluginname.plugin file
Great. This seems like the last part of creating an extension for Scratch. What is a .so file, and how do I generate one? I've already created the other necessary files like the .plugin file and the .vala file.
Yes, I have searched for .so files but all I found were random things about it like using it with C, or C++ headers but obviously that won't work for me, since I'm using Vala?
How do I generate a .so file? What do I generate it from?
I think the The Vala tutorial could be helpful on creating the actual Shared library or Shared Object.
You can use the autotools, cmake or you can compile and link a shared library directly from the command line, quoted from the Vala tutorial:
Compilation and linking using Command Line
Vala is not yet capable of directly creating dynamic or static
libraries. To create a library, proceed with the -c (compile only)
switch and link the object files with your favourite linker, i.e.
libtool or ar.
$ valac -c ...(source files)
$ ar cx ...(object files)
or by compiling the intermediate C code with gcc
$ valac -C ...(source files)
$ gcc -o my-best-library.so --shared -fPIC ...(compiled C code files)...
From the Scratch Wiki
Due to browser security restrictions, Scratch 2.0 cannot interact with
hardware devices directly. Instead, hardware extensions come with a
helper app, a separate application that the user must install and run
on their computer. Scratch communicates with the helper app via HTTP
requests, and the helper app talks to the hardware. In the future,
some extensions may package their helper apps as browser plugins.
Here are the steps for creating and testing a Scratch extension:
Create an extension description file
Create your helper app and start it
Open the Scratch 2 Offline Editor
Import the extension description (shift-click on "File" and select "Import Experimental Extension" from the menu)
The new extension blocks will appear in the More Blocks palette
Test your extension and iterate!
Helper apps can be written in any language that supports server sockets, such as Python, Node.js, Java, C, etc.
Like you I've chased around the wiki but I cannot find an example with source. So all I can do is to address your question generally.
If you look at Build .so file from .c file using gcc command line you'll see how a simple .so can be created. However what code goes into a Scratch extension I don't know. Sorry.
Edit: More googling and I've found a sample from Nathan Dinsmore on GitHub that doesn't use C rather it uses JavaScript, and though it doesn't create a .so extension, it does have what appears to be a full description of creating an extension. He also provides a couple of tutorials.
Edit++ : And here is another sample written in Java.
I have installed Qt designer 4.8.2, Pyside, and Python 3.3. When I create a form with Qt designer I am not able to see the code when clicking on view code. The error message is:"Unable to launch C:\Qt\4.8.2\bin\uic".
I have the pyuic under C:\Python33\Lib\site-packages\PyQt4\uic. Please help.
Just create a directory where it search for uic.exe file and copy existing uic.exe file to that directory.
My example :
When I clicked View Code it shows Error asking for file uic.exe in path
C:\python374\Lib\site-packages\pyqt5_tools\Qt\bin\bin
But I found uicexe file is in C:\python374\Lib\site-packages\pyqt5_tools\Qt\bin folder
So I created another bin folder and copied uic.exe into that folder . That solved my problem.
If you were looking to generate python code, you would do this from the console. So, if you saved your file from the program as 'untitled', the default, run this:
pyuic5 -m untitled.ui -o untitled.py
Making sure your working directory is the file location of 'untitled.ui'. It will then spit untitled.py into the same place.
Create a folder called bin inside the folder and move the exe inside uic.exe. It shows the code when click the view code from the QT designer.
Although you can certainly use Qt Designer for creating UIs for PySide/PyQt, you should be aware that it is primarily a C++ tool - it doesn't have any built in support for Python. So the "View Code..." command you refer to only produces C++ code - which is probably not much use to you if you intend using PySide or PyQt.
Qt Designer UI files are in an XML format (they usually have a .ui extension).
To use them with Python, there are basically two options:
Load the .ui files directly into your application.
Convert the .ui files into Python modules using an external tool.
There are several differences between PySide and PyQt in how these two options are implemented.
For PyQt, the full documention for both options can be found here.
For PySide, the documentation for option 1 can be found here - but it does not look like there is any documentation for option 2. However, the external tool for PySide (which is called pyside-uic) works very similarly to the one for PyQt (which is called called pyuic4).
If you need more general information about how to get started using Qt with Python, try the PySide Wiki or the PyQt Wiki.
To make
Form -> View code
work, directly from Qt Designer using either Qt4 or Qt5, you can just create a symbolic link from where Qt Designer is looking, pointing to where your pyuic5.exe executable is. With your example, it would be:
mklink /H "C:\Qt\4.8.2\bin\uic.exe" "C:\Python33\Lib\site-packages\PyQt4\pyuic4.exe"
Which is:
mklink /H "Path\to\uic.exe\file\Qt\designer\is\looking\for" "Path\to\actual\location\of\pyuic4.exe\or\pyuic5.exe\file"
Make sure the folder where "C:\Qt\4.8.2\bin\uic.exe" will reside exists obviously.
For Linux computers
If anyone still stuck with this problem and you are using Linux.
You can find the required uic file in venv-path/python3.x/site-packages/PySide2/uic
Copy this file, and create a new folder bin inside the Qt folder.venv-path/python3.x/site-packages/PySide2/Qt/bin
now place the uic file there, such that, the final uic path is:
venv-path/python3.x/site-packages/PySide2/Qt/bin/uic
Note::
venv-path is the path to you python virtual-environment.
3.x is the appropriate version of the Python in the virtual-environment. (In my case it's 3.8)
Final Result:
python -c "import os; import PySide6; src = PySide6.__path__[0]; dst = src + '/bin'; os.mkdir(dst) if not os.path.exists(dst) else None; os.symlink(src + '/uic.exe', dst + '/uic.exe')"
I had the same error\warning message on Windows with pyside6-designer, I just run the above line as administrator and everything now works as expected (The line, simply creates a link of the uic.exe inside a bin-folder under the Pyside6 module's folder).