py2exe generator not working - py2exe

I ran this setup.py file
from distutils.core import setup
import py2exe, sys, os
sys.argv.append('py2exe')
setup(
options = {'py2exe': {'bundles_files': 1}},
windows = [{'script': "Driverscript.py"}],
zipfile = None,
)
This creates the executable file and packages but it wont run every time i try to run it it says that it encountered an error and had to close every time. Is there something else i need to do first or something wrong with my setup.py file? all input is greatly appreciated thanks

What's the output of your error log? That could mean a lot of things. I'm assuming you're compiling a windowing application? Are you running this application on Windows? You might want to run the application from the command line and see if you get any errors.

Related

Error: Unable to import package 'kivy_gradient.Gradient', while trying to run the exe file using pyinstaller

I imported #:import Gradient kivy_gradient.Gradient in my .kv file. The app is working fine without any error.
When I try to convert the file to exe using pyinstaller using : pyinstaller --hidden-import kivy_gradient.Gradient main.py -w. Then modifying my specs file as:
from kivy_deps import sdl2, glew
a.datas += [('Code\filename.kv','location\filename.kv','DATA')]
Tree('folder_location')
*[Tree(p) for p in (sdl2.dep_bins + glew.dep_bins)]
And finally building my exe file using pyinstaller main.spec -y command.
When I try to run the exe file it show the error: Unable to import package 'kivy_gradient.Gradient'. Please help me, I have been struggling for long.

Python modules not working in IDLE

Working on Automate The Boring Stuff project and having trouble with pyperclip and IDLE. pyperclip is successfully downloaded and works fine in Terminal but when I import pyperclip in IDLE, I get the below error.
UPDATE - This is happening with other modules - anything I've installed in the terminal aren't importing into IDLE.
import pyperclip
Traceback (most recent call last):
File "", line 1, in
import pyperclip
ModuleNotFoundError: No module named 'pyperclip'
I figure I have the module saved in the wrong folder somehow. Below are the sys.path outputs from my Terminal and IDLE.
In terminal:
'/anaconda/bin',
'//anaconda/lib/python36.zip',
'//anaconda/lib/python3.6',
'//anaconda/lib/python3.6/lib-dynload',
'//anaconda/lib/python3.6/site-packages',
'//anaconda/lib/python3.6/site-packages/Sphinx-1.5.1-py3.6.egg',
'//anaconda/lib/python3.6/site-packages/aeosa',
'//anaconda/lib/python3.6/site-packages/IPython/extensions',
'/Users/andrewricardo/.ipython']
In IDLE:
sys.path
['', '/Users/andrewricardo/Documents', '/Library/Frameworks/Python.framework/Versions/3.6/lib/python36.zip', '/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6', '/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/lib-dynload', '/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages']
There are multiple paths here - how do I effectively move the pyperclip module to the correct place?
OR - Is there something else going on here?
Each python installation and uses its own .../lib/site-packages for 3rd party modules, and you have two. If you ran the non-anaconda python in the terminal, the same that is running IDLE, it would have the same problem. Indeed, that python is the source of the ImportErrors.
Option 1: Separately install all packages you want to use with the non-anaconda python (and IDLE) in its own site-package directory. In IDLE Shell, get the path to its executable
>>> import sys; sys.executable
Save are remember the resulting 'python-path'. Then in the terminal, run
python-path -m pip install package-name
for each package.
Option 2 (uses a little known feature of site-package directories): in
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages
add a file name, for instance, anaconda.pth, containing one line.
//anaconda/lib/python3.6/site-packages
(I have no idea why the double / or if it is really needed; I just copied it from your question.) This makes the anaconda python site-packages an extension of the framework python site-packages. Since both are for 3.6, one copy should work for both.
Had this same issue and googled
'why is importing pyperclip in my python file giving an "modulenotfounderror"but working fine in the idle'
and this page came up. then i also checked this [installed Pyperclip, trouble importing to IDLE.
I am new to python, had the same issue using the same book after pip installing pyperclip here's what I did to solve this issue.
I copied the pyperclip-1.7.0-py3.7.egg-info and pyperclip folders from
C:\Users\USER\AppData\Local\Programs\Python\Python37\Lib\site-packages into the C:\Users\USER\Anaconda3\Lib\site-packages folders and C:\Users\USER\AppData\Local\Programs\Python\Python37 folders and it worked. Hope this helps. If it doesn't. Try this code in your text editor because that's what I did using Atom and how i was able to solve it.
import sys
print(sys.executable)
Then copy the pyperclip-1.7.0-py3.7.egg-info and pyperclip folders into the path that the above code gives you.

cx_freeze builds Mac program that runs from command line but dies when clicked

I have a Python 2.7/PyQt4 program that I am attempting to freeze with cx_freeze. The program also uses requests, serial, xml.etree.ElementTree, and collections. Using the unmodified setup.py generated by cxfreeze-quickstart-2.7, I can successfully build as both a console program (python setup.py build) and an .app (python setup.py bdist_mac) in Yosemite using Python from macports. If I run the program directly either from the app bundle or the dist:
$ build/MacDISE-1.0.app/Contents/MacOS/macdise
$ dist/macdise
It runs exactly as expected. If I open from the command line:
$ open -a /Users/jeffemandel/macdise/build/MacDISE-1.0.app
I get the dreaded
LSOpenURLsWithRole() failed for the application /Users/jeffemandel/macdise/build/MacDISE-1.0.app with error -10810.
I worked through a number of potential issues raised by Dan McCombs (distutils.util.get_platform, sys.arg), but these don’t seem to be the problem. Through brute force trial and error, I found that if I put all of my code in a separate module, simply importing that module (without actually invoking it) causes the 10810 error, so I figured it was finding a library when run from the command line, but not from the app. I put the dist directory on a thumb drive and ran it on another Mac that doesn't have Python, Qt4, etc installed, and got this:
packages/cx_Freeze/initscripts/Console.py", line 27, in <module> File "macdise.py", line 4, in <module>
File "ExtensionLoader_PyQt4_QtGui.py", line 11, in <module>
ImportError: dlopen(/Volumes/NO NAME/dist/PyQt4.QtGui.so, 2): Library not loaded: /opt/local/Library/Frameworks/QtGui.framework/Versions/4/QtGui
Referenced from: /Volumes/NO NAME/dist/PyQt4.QtGui.so
Reason: image not found
When I look in dist, there is a file QtGui that is the same size as the one in /opt. So it seems the failure is dlopen(PyQt4.QtGui.so) returning a hard-coded path to the QtGui library. I'm guessing the solution is simple, but I haven't stumbled across it yet.
Update: I looked at the libraries in build/Contents/MacOS/PyQt4.*.so with otool, and these all have #executable_path (as opposed to hard-coded paths in dist). My stupid. So I repeated the process of moving the program, only using the MacOS folder rather than the dist folder, and executing macdise from the command line on my wife's MBP. The problem turned out to be in the way I was looking for the included_files. I changed this to:
if getattr(sys, 'frozen', False):
uiName = os.path.join(os.path.dirname(sys.executable), "tabDISE.ui" )
else:
uiName = "tabDISE.ui"
and it runs. What would have saved me a day would be a way to automagically dump the error message generated when executing from the command line to the console log. If someone knows how to do this, it would be a big help.

py2app throws [errno 35] Resource Not Available during unconditional imports

I'm using python 2.7 installed via macports, pyobjc, cocoa and notably scipy (via FlowCytometryTools) with py2app to create a small mac application. Py2app's setup.py run with sudo python setup.py py2app completes nicely with -A for testing, but is unable to complete when running without that parameter to create a full .app build.
The build process will get a variable distance through the unconditional imports and then give error: [Errno 35] Resource temporarily unavailable and immediately exit. The number of unconditional import lines that complete before the error occurs changes. The longest run so far was seen when running immediately after a reboot. I've tried running with and without removing the previous build/dist folders to no effect.
Modules not found (unconditional imports):
...
* builtins.int (Cython.Build.Inline, Cython.Compiler.ExprNodes, IPython.utils._tokenizeerror: [Errno 35] Resource temporarily unavailable
My setup.py looks like this:
import sys
sys.setrecursionlimit(1500) #required to avoid recursion triggered early exit in py2app while compiling scipy. (default is 1000)
from setuptools import setup
APP = ['FlowMac.py']
DATA_FILES = ['FlowMac_Main.xib']
OPTIONS = {'argv_emulation': True}
setup(
app=APP,
data_files=DATA_FILES,
options={'py2app': OPTIONS},
setup_requires=['py2app'],
)
and the imports section of my python file FlowMac.py looks like this:
from Cocoa import *
from Foundation import *
from AppKit import *
from FlowCytometryTools import * #file/data handling via scipy and pandas
from pylab import * #graphing histograms
Commenting out both the FlowCytometryTools and the pylab imports allows the py2app build to complete but of course renders the program nonfunctional.
What is happening?
How can I get more information on which resource is unavailable?
was hitting a recursion limit a clue to my problem?
I'm running Yosemite on a MacBook Pro with 8GB RAM, so I'm very surprised to be hitting a wall here.
Thanks for your time.
UPDATE 4/29/2015:
Importing everything works fine if I remove my .xib from the datafiles array of the py2app launcher setup.py. A blank file with just import Cocoa, Foundation and Appkit works fine. Importing the xib with any one of FlowCytometryTools, pylab, scipy, matplotlib, numpy does not work. pylab and FlowCytometryTools rely on the other three, and any one of scipy, matplotlib or numpy brings in py2app recipies for the other two. One of these recipies isn't working with the xib, but I don't know why...
No experience with py2app, but I am wondering if you tried generating a more minimal version of the code that would fail to aid troubleshooting?
Maybe having FlowMac.py include nothing but the import statements:
import Cocoa
import Foundation
import AppKit
import FlowCytometryTools
import pylab
Also could you narrow it down to whether the problem appears due to pylab or due to FlowCytometryTools? (By commenting them out individually?)
From my testing, this error seems to be caused by the log output itself from py2app. Try redirecting standard error to a file:
python setup.py py2app 2>error_log
This should work around the error.

making a python program executable

from distutils.core import setup
import py2exe, sys, os
sys.argv.append('py2exe')
setup(
options = {'py2exe': {'bundle_files': 1}},
windows = [{'script': "single.py"}],
zipfile = None,
)
in this setup file for py2exe where it says single.py is that where I place the name of my program?
I don't know your py2exe tool, but we usually use this way to convert py to exe:
Download and install Standard Python Software:
http://www.python.org/download/
Download PyInstaller via link below:
http://pyinstaller.python-hosting.com/
Unpack the archive, that you have downloaded!
In this examople, the directory of the unpacked files:
In the <UNPACKED_FILES_DIR> directory, run Configure.py.
It must be run before trying to build anything.
Create a spec file for your project:
python Makespec.py -F -p <PYTHON_LIB_PATH> <PYTHON_SCRIPT>
-F: Produce a single file deployment.
-p <PYTHON_LIB_PATH>: Set base path for import (like using PYTHONPATH).
( e.g.: C:\Program Files\Python24\Lib\ )
<PYTHON_SCRIPT>: Path to python script.
6 Build your project!
python Build.py <SPECFILE>
<SPECFILE>: Path to the specfile, that have been created in step 4!
The full path to <SPECFILE>:
<UNPACKED_FILES_DIR>/<PYTHON_SCRIPT>/<PYTHON_SCRIPT>.spec
The binary file will be placed in the directory of <SPECFILE>.
If you can restrict your code, then Shed Skin, PyPy, or Cython make true, fast executables.
Py2exe, PyInstaller, or bbfreeze can package Python up to 2.7 into single executables.
Cx_Freeze packages Python up to 3.x into an executable plus many other files.
Yes. Are you making a windowing application or a console application? See the example setup.py files that came with py2exe.

Resources