Single executable file created by py2exe not working - python-2.7

I've created a Python app using Pyqt4 to open up a dialog and do some image processing using opencv2. The app is working fine when executing the script as:
python script.py
To create a single executable file for the script, I'm using py2exe with bundle_files = 1 option. It is creating a single exe file but when clicking the file, a console appears stays for few seconds and a pop-up appears saying program has stopped responding.
I'm working on Windows with anaconda. Please help me with this.

Py2exe generates a logfile.txt in the same folder you first-time execute the generated .exe.
Check this logfile to debug.
Most of the time you need to exclude some dll`s and include at least sip-module;
In your setup.py file:
from distutils.core import setup
import shutil, py2exe
opts = {'py2exe': {'compressed': True, "dll_excludes": ["MSVCP90.dll"], "includes" : ["sip"]}}
setup(console=[{"script" : "main.py"}], options=opts)
shutil.rmtree('build', ignore_errors=True) #Remove the build folder
Personally I did not encounter the need to include PyQt4 modules for compilation..
And btw be glad that python is an interpreted language, otherwise you`ll have to worry about linking to libraries on every build (like in cpp.., which is annoying)
Greets Dr Cobra

Related

Can't run app exe on other machines, python2.7, fpdf, pyinstaller

I have an issue with running exe application from pyinstaller on other machines. It is looking for path on PC, where I built application:
console output
I use and added font in pyPDF in following way:
from fpdf import FPDF
pwd = os.path.realpath(os.path.dirname(sys.argv[0])) + "\\font\\DejaVuSansCondensed.ttf"
pdf = FPDF(orientation = 'L', unit = 'mm', format='A4')
pdf.add_page()
# Add a DejaVu Unicode font (uses UTF-8)
# Supports more than 200 languages. For a coverage status see:
# http://dejavu.svn.sourceforge.net/viewvc/dejavu/trunk/dejavu-fonts/langcover.txt
pdf.add_font('DejaVu', '', pwd, uni=True)
pdf.set_font('DejaVu', '', 18)
#then I use pdf.write() to write data
#save and close pdf file
pdf.output('C:\\Users\\' + getpass.getuser() + '\\Documents\\pdf_file' + time_stamp + '.pdf', 'F')
I tried to build it in following ways:
pyinstaller app.py
pyinstaller --onefile app.py
There is no issue on machine, where I build code. I suppose there is something in output method from fpdf or settings of pyinstaller, am I right?
I have to create pdf with unicode characters. I use latest versions of fpdf and pyinstaller modules.
I will be thankful for any help.
Thank you in advance,
There is no issue when you build it on your machine since you have DejaVuSansCondensed.ttf where python expects it to be. But when you compile with PyInstaller and run it on another system, it is looking in the same spot (which may not exist on other systems).
What I would suggest is to copy that ttf file to your current working directory and update the line font line to (or something similar that fits your code):
pwd = "DejaVuSansCondensed.ttf"
You also have to make sure that the .exe has access to that file, independent of system (relative to the exe). So you have to copy the ttf file to the same directory as your exe so that when you run it on another computer, your code will look in the directory that the exe is in and find the ttf file.

How to run django.setup() properly from within a stand-alone python file inside of a django app (on linux-ubuntu)?

Im trying to run a stand-alone python file in a django project. The problematic code is below (standalone.py):
import os
import django
# os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myproject.settings") tried as well
os.environ["DJANGO_SETTINGS_MODULE"] = "myproject.settings"
django.setup()
The error i receive is: 'No module named myproject.settings'. Somehow the project settings file is not being recognized.
The file runs just fine on my local machine however the problem occurs when running the file on a linux-ubuntu server.
This file is being run from within an app: myproject>myapp>standalone.py
When i move this file to the same directory that myproject resides in, the file runs just fine, so im assuming that the myproject.settings module is not being recognized from within the app directory.
As a temp fix:
sys.path.append('path_to_myproject/')
seems to resolve the issue, but definitely not something i want in production code. Any suggestions on how to resolve this issue? Thanks in advance
If the settings module is myproject.settings, then the outer myproject directory must be on the python path. If the script is in the outer myproject directory (the one that contains manage.py) then you don't need to do anything because the current directory is on the path. Otherwise, you have to manually add the directory to the python path.
The way to add something to the python path is sys.path.append(), so you can't avoid having that in production code (unless you use the PYTHONPATH environment variable instead). Perhaps you would be happier with adding the parent directory instead of hardcoding the path.
sys.path.append('..')

import oozie.common.file as file ImportError: No module named oozie

I am getting this error while importing a file from other module?Can anyone tell me what could be the reason.It is running fine in console but when I run it as a oozie job,command is failing.
Folder structure:
oozie/common/file.py
oozie/common/__init__.py
oozie/__init__py
my location from where i am trying to import:
oozie/mylocation/pjt.py
oozie/common/__init__.py
Command:
import oozie.common.file as file
Your python code will be moved from HDFS, where it is stored, into the local filesystem of a datanode where is executed.
Be sure you set all the files required into the oozie jobs, otherwise some of them will no downloaded into the selected datanode.
Remember that:
1) All the python system library must be installed on each datanode
2) Local libraries work if you set the PYTHON LIBPATH.
So you first line in your python script, should be something which set library path.
In my opinion to keep all classes into the same file the python ( if you can ) is the painless solution when you start them on oozie.
If you can start using Java.

PyQt: Running pyuic.py without command line

I am unable to use the command prompt due to security restrictions on my work PC and I am trying unsuccessfully to find a way to convert .ui files to .py without the pyuic4 batch file.
I have found the uic/pyuic.py program but have been unsuccessful in my attempts to run it from a python console.
Any help with this would be great.
Cheers.
Thanks ekhumoro,
Was able to implement the uic successfully, using compileUiDir, since I have multiple .ui files. Final code was:
from PyQt4 import uic
folderToConvert = r'filePathGoesHere'
uic.compileUiDir(folderToConvert,recurse=False)
This is a .py file that I run or call/execute prior to running the main program. Very handy!

Installing Qt Components for Windows

I am able to compile the source of qt-components just fine using the following steps:
Downloaded the tar.gz from http://qt.gitorious.org/qt-components/desktop/trees/master
Unpacked the components
Added path variable value to the environment variables for mingw and qmake
Ran the following command: qmake && make install
I can see that the above command exits successfully and copies the qml files and a few other folders to C:\Qt_2.8.0\Qt4.8.4\imports\QtDesktop
I then open up qtcreator and inside of my qml file, I type import QtDesktop 0.1, but it returns an error of module "QtDesktop" is not installed. If I hover over the QtDesktop import statement, it reads Library at C:\Qt_2.8.0\Qt4.8.4\imports\QtDesktop - Dumped plugins succesfully.
...so what I am doing wrong here?
Please note that I am constricted in using Qt4