py2exe can't find msvcp90.dll - python-2.7

I'm working on converting a simple GUI script written with Python 2.7 and Pyqt4 into a standalone executable using py2exe. I keep getting "no such file exists" errors, and I've managed to fix a few, though this one seems stubborn. It can't find msvcp90.dll, and returns an error message with a short traceback to distutils and then back to my py2exe script, which isn't very enlightening.
I've installed the MS C++ redistributable runtime, as recommended in
py2exe fails to generate an executable
but my script still can't locate the .dll. Below is my py2exe script, with the name of my script blocked out:
from distutils.core import setup
from py2exe.build_exe import py2exe
import sys, os, zmq
sys.argv.append('py2exe')
os.environ["PATH"] = \
os.environ["PATH"] + \
os.path.pathsep + os.path.split(zmq.__file__)[0]
setup(
options = {'py2exe':{'bundle_files':1,"includes":["zmq.utils",
"zmq.utils.jsonapi","zmq.utils.strtypes"]}},
console = [{'script':"#######.py"}],
zipfile = None
)
I've already fixed an issue with zmq (which isn't ever used by my script, or my GUI, for that matter, as far as I know). What am I doing wrong?

Right, I've managed to get my app to build, and although the question is now moderately old, it's my hope this is eventually of use to someone.
Firstly, py2exe is probably the wrong tool. It's old and AFAICT unmaintained. Consider PyInstaller instead. Using PyInstaller is literally as simple as installing it, installing PyWin32, and then going python %path_to_pyinstaller%/pyinstaller.py --onefile --windowed source.py. PyInstaller deals with all the mess of side by side assemblies and so on without you having to do anything.
In short, use PyInstaller.
However, to answer your question, this worked for me:
The question you've linked to - in particular this answer is the right start. Find the right DLLs and copy them to C:\Python27\DLLs
Ditch your existing setup.py file. If you're not using zmq, there's no reason to import it. Also, for a windowed application you want windows= not console=. My file goes (for packaging show.py):
#!/usr/bin/python
from distutils.core import setup
import py2exe
setup(options={'py2exe':{'bundle_files':1}},
windows=['show.py'])
(This is pinched off http://www.blog.pythonlibrary.org/2010/07/31/a-py2exe-tutorial-build-a-binary-series/)

Related

how do i fix "No module named 'win32api'" on python2.7

I am trying to import win32api in python 2.7.9. i did the "pip install pypiwin32" and made sure all the files were intalled correctly (i have the win32api.pyd under ${PYTHON_HOME}\Lib\site-packages\win32). i also tried coping the files from C:\Python27\Lib\site-packages\pywin32_system32 to C:\Python27\Lib\site-packages\win32. I also tried restarting my pc after each of these steps but nothing seems to work! i still get the error 'No module named 'win32api''
Well, turns out the answer is upgrading my python to 3.6.
python 2.7 seems to old to work with outside imports (I'm just guessing here, because its not the first time I'm having an import problem)
hope it helps :)

py2exe fails to resolve ibm_db dependency (DLL)

I am trying to create an EXE using py2exe for a desktop app I wrote with python 2.7.
The app utilizes ibm_db (v2.0.7), which installs to site-packages as an .egg folder.
The contents of the ibm_db.py file are very short, as the logic itself is implemented in the DLL:
import os
if 'clidriver' not in os.environ['PATH']:
os.environ['PATH'] = os.environ['PATH'] + ";" + os.path.join(os.path.abspath(os.path.dirname(__file__)), 'clidriver', 'bin')
def __bootstrap__():
global __bootstrap__, __loader__, __file__
import sys, pkg_resources, imp
__file__ = pkg_resources.resource_filename(__name__,'ibm_db_dlls\ibm_db.dll')
__loader__ = None; del __bootstrap__, __loader__
imp.load_dynamic(__name__,__file__)
__bootstrap__()
When I ran py2exe on the project, the dependency on ibm_db wasn’t properly handled (the DLL wasn’t taken into the dist), so running the exe file stumbles upon the following error:
...
File "ibm_db.pyc", line 10, in <module>
File "ibm_db.pyc", line 6, in __bootstrap__
ImportError: No module named pkg_resources
I tried to copy the DLL manually into the dist folder (both directly and under ibm_db_dlls subfolder), but it’s of no use.
I found this page, and realized that py2exe has an issue with eggs:
http://www.py2exe.org/index.cgi/ExeWithEggs
As far as I understand, unzipping the egg is not the way to go in my case, because my program does use pkg_resources (through ibm_db.py). Still, I tried installing ibm_db via easy_setup with the --always-unzip option, but the installation gave me this error:
Not a URL, existing file, or requirement spec: '--always-unzip'
and it was still installed as an .egg.
So I’m looking at the “Including .egg files in your dist directory” option, and wondering whether it can help. And if so – where to start?
I’m using this simple setup.py for running py2exe:
from distutils.core import setup
import py2exe
setup(console=['MyApp.py'])
What is this “TurboGears” mentioned there? It doesn’t look like something I’m using in my app.
Any advice will be appreciated.
Thanks.

Using pyinstaller on parmap causes a tkinter matplotlib import error. Why?

Update
If I try downgrading from Pyinstaller 3.2 to 3.1 I instead get the following traceback when I try to run the executable.
I tried adding --hidden-import=collect_submodules('pkg_resources._vendor') to pyinstaller as noted here but it had no effect. Same error. This appears to be due to an issue with setuptools. I'm using 26.0.0. Downgrading to 19.3 that many sources say fixes the issue does indeed fix this issue but then I'm back to the issue I have below.
I have a python 2.7 pyqt4 project I'm trying to turn into an .exe using pyinstaller. I use:
pyinstaller --additional-hooks-rir=. --clean --win-private-assemblies pipegui.py
pipegui.py can be found on github here
I get a working executable and the app appears functional. Here is what the terminal spits while pyinstaller is freezing. However the app crashes when I run particular parts of my program. It crashes and the terminal goes in a loop continually outputting the same traceback below with "Poolworker-X" at the very top continually incrementing:
As you can see tkinter is implicated, despite the word "tkinter" appearing nowhere in my project (using pyqt4). I am making use of matplotlib though and from answers discussed here and here I have added the following to the top of pipegui.py my main script:
from Tkinter import *
import Tkinter
import FileDialog
This however seems to be a step in the wrong direction because after freezing with this (and the same flags as before) my executable wont even open and instead I get this:
Here is pyinstaller's pretty-much identical output while freezeing. Remember all I did was add those 3 import statements above. That's it.
I also tried pyinstaller --additional-hooks=. --clean --win-private-assemblies --hidden-import=Tkinter pipegui.py and it made no difference. I'm completely perplexed as to why trying to import tkinter is doing this. Will fixing this traceback lead me closer to solving the other?
I only figured out after trying all this that the only parts of my executable that are crashing are parts that make use of parmap multiprocessing. Classes that make use of matplotlib but not parmap are working fine.
So please note my question is how the first traceback can be fixed and also why are both matplotlib and tkinter popping up in the traceback despite my code where the crash occurs making use of niether?
Extra notes
I use --clean --win-private-assemblies to fix error code 14001 as per here
Repiklis provided the solution in the comments. Further note that as of January 15 2017 Pyinstaller version 3.2.1 was released. I now use this and it solves this issue along with others like this and this that I could previously only solve by using the developer version. So I highly recommend upgrading to the latest version if you haven't already.

Importing Numpy in embedded Python c++ application

I would like to have a script invoke numpy from a c++ embedded python runtime by setting the runtime path to know about the numpy module located within site-packages.
However I get the error:
cannot import name 'multiarray'
from \Lib\site-packages\numpy\core__init_.py on the line
from . import multiarrray
I have tried to set the os.path to be xxx\numpy\core but it still cannot seem to find the multiarray.pyd file during the import statement
I have read through similar questions posed but none of the answers seem relevant to my case.
I am using Python 3.4.4 (32 bit) and have installed Numpy 1.11.1 using the wheel
numpy-1.11.1-cp34-none-win32.whl
python -m pip install numpy-1.11.1-cp34-none-win32.whl
Completed without any errors.
Seems like the failure message maybe more general than just an incomplete PYTHONPATH?
Also think it might be broader than Numpy in that ANY .pyd based package that is imported from the embedded environment will have this problem?
Any help appreciated.
Did you ensure all your NumPy includes: \numpy\core\include\numpy\ were present during the build? That's the only time I get those types of errors was if the build couldn't find all the NumPy includes... although during embedding I found that the numpy entire directory (already built on your build machine) has to be inside a directory under Py_SetPath(python35.lib;importlibs); assuming importlibs is a directory with NumPy inside and anything else you want to bundle.
Seems like the answer was to install python 3.4.1 to match the python34.dll version of 3.4.1.

Spynner -- No Module named cookielib

I have written the below mentioned basic script using Python Spynner.
It works fine when running through IDLE.
However, when I try to convert it into exe using Pyinstaller and run the exe, It gives me the following error.
ImportError: No module named cookielib
I have searched a lot for solution but couldn't find any. Any help would be appreciated.
I am using Python2.7 (windows 7 32 bit)
Here is the code,
import spynner
b=spynner.Browser()
b.hide()
b.load('http://www.google.com')
b.snapshot().save('file.png')
b.close()