I recently downloaded an installed the following:
Python 3.2.5
CefPython 3
PySide - for handling the GUI of my CEF-powered app
cx_freeze - to make my app distributable
Now, the first three work just fine. If I run pyside.py in CefPython's examples directory, the app starts as it should. However, if I try to freeze the app using the instruction below, the app compiles, but with errors.
Command line instruction
C:\Python32\Lib\site-packages\cefpython3\examples\PySide>cxfreeze pyside.py --target-dir bin --base-name Win32GUI --include-modules atexit,PySide.QtNetwork
Error
Missing modules:
? _gestalt imported from platform
? _posixsubprocess imported from subprocess
? cefpython_py27 imported from __main__
? cefpython_py32 imported from __main__
? win32api imported from platform
? win32con imported from platform
? win32pipe imported from platform
Then, when I try to run the app, I get the following:
ImportError: No module named cefpython_py32
Problem here is that I can't seem to include the module in the command line instruction. cx_freeze simply cannot find it.
What do I need to do to get cx_freeze to find CefPython?
Note: cx_freeze imports all the necessary DLLs, from the Qt framework, to CefPython itself. They are all there. Which begs the question as to why it knows where the DLLs are, but not the libraries. Also note that I'm a Python newbie. I'm sure there's a simple explanation as to what I need to do. I have a feeling I need to copy something into cx_freeze's dist directory - I just don't know what that file would be. I naturally assumed it would be a .pyc file, but there are none...
Update (whilst I was compiling this question):
I also tried the following instruction:
C:\Python32\Lib\site-packages\cefpython3\examples\PySide>cxfreeze pyside.py --target-dir bin --base-name Win32GUI --include-modules atexit,PySide.QtNetwork,cefpython3
Note the added cefpython3. Now, it compiles it, but the EXE throws a cx_freeze error: Cannot get zipimporter instance Also, the above errors persist, and so I think that using cefpython3 is wrong in this regard.
Related
I think this is one of the many questions about missing modules and py2exe... anyway...
PylibUty is a local package located in C:\Dati\workspaces\PythonEclipse\APyLibUty\PyLibUty and referred in every .py file with:
import sys, os
sys.path.append(os.path.join(os.path.dirname("file"), '..'))
sys.path.append("C:/Dati/workspaces/PythonEclipse/APyLibUty")
from PyLibUty.pystr import randomString, insertStr
uuid is a Python package so I normally import it
_posixshmem I am not able to find what package I should install using pip/pipenv
resource: I installed both resource and pyresource using pip/pipenv bat nothing changed
What should I install or import to solve these problems?
This is the output produced running py2exe:
I did not find a solution to understand what modules I should add or install to clear the problems of py2exe, so I searched the web to find a different tool able to make exe files from Python sources. I found cx_freeze, actually it does not produce the errors I reported so at the moment I switched to cx_freeze. I will test it better but at the moment my problem is solved.
I am trying to freeze a Python script that contains an import from osgeo but the executable fails with an ImportError: No module named '_gdal'.
I've stripped down my script to just one line:
import osgeo
When running in Python (version 3.3.3) all is well. I've tried freezing with cx_Freeze and py2exe. Both report that there is a missing module: ? _gdal imported from osgeo (among others) but successfully freeze the script. Then the exe fails with the above ImportError.
I've tried importing _gdal in python and it works. I tried manually including the osgeo module in the freezing options but still get the same error.
There is a similar question here:
Importing GDAL with cx_Freeze, Python3.4
but maybe this isn't a cx_freeze issue because it also happens with py2exe (it has experimental support for python 3 now).
Does anybody know how to fix this?
I found a fix. I edited the osgeo\__init__.py file and modified line 13 like this: import osgeo._gdal. This works but only if the module osgeo._gdal is manually included when freezing. #Thomas K Your solution does the same thing I guess.
Note that the same modification must be applied both at osgeo.ogr (line 18) and osgeo.osr (line 18) modules if they are needed (import osgeo._ogr and import osgeo._osr respectively). This means that these must be manually included when freezing as well. My freezing command now looks like this: python cxfreeze.py module1.py --include-modules=osgeo._gdal,osgeo._ogr,osgeo._osr.
Thanks #Thomas K for your help.
I'm trying to compile a Python project (using Python 2.7 on Windows XP) into an EXE using PyInstaller with the default options. When I try to run the EXE, I get the message:
PyInstaller - ImportError: No module named win32api
I added the win32api path to the windows PATH environment variable (I do have Python Win32 Extensions installed) but it's not working. I'm pretty new to this and a little overwhelmed by all the options etc, and I really have no idea where to start (or what information would be useful to solving this problem.) I assume this is some little thing that I'm missing, but I haven't found anyone having precisely this problem online and any help would be greatly appreciated.
Ok, it looks like "import os" in one of my modules was causing this issue. I had no luck getting it to successfully use the win32api module, but since this was only being used to set the program name, I just commented this out and this particular issue is resolved. Thanks Luke for your help!
Im my Python file, I have imported the win32gui module like this:
import win32gui
I have also downloaded win32gui but don't know how to make my script run. How can I run my Python script which imports win32gui? When I run it, I get:
ImportError: No module named win32gui
Sorry for the newbie question but I'm trying to learn Python so don't know much about it.
When on a windows platform, I usually go for the executables. They should work all the time. Try perhaps one of the files listed here:
http://sourceforge.net/projects/pywin32/files/pywin32/Build216/
It's the most recent build. Choose the one appropriate to your Python's version.
this is a module from Marc Hammond's well-known pywin32 extension module, you can also get the source and compile it quite easily (I found I needed to do this because I needed a 64 bit build and couldn't find one at the time). The mercurial address to get it is:
http://pywin32.hg.sourceforge.net:8000/hgroot/pywin32/pywin32
there are visual studio project files in the .\pywin32\win32 directory...
I am bundling python source code with py2exe. The directory structure is as follows:
some_Mod.py
some_dir/another_dir/some_Mod.py
Inside the latter some_dir/another_dir/some_Mod.py I am trying to import the other Python Module with
from ..some_Mod import *
Using the import causes no problems with the python interpreter, but if I run the same constellation in the bundled package, I get an Exception:
ImportError: No module named some_Mod
Can somebody explain why?
Remark: Renaming the Modules is actually no problem, but I was just wondering, why py2exe cannot deal with this constellation.
If you have __init__.py files in each of those sub-directories then all import statements should work correctly.
Assuming that's not the problem, here's an excellent guide to importing best practices:
http://blog.habnab.it/blog/2013/07/21/python-packages-and-you/
In summary, never use relative imports - always absolute (see the link above for why).
Second (and I'm not entirely sure why), always keep your py2exe setup.py script in the exact folder where your main script is. I've tried modifying py2exe's 'script' option to allow my script to be somewhere else... but your exact problem happened to me. So, try making sure it is right where the main script is.
Finally, you can always give py2exe a little help. I usually have to add the root directory to the system path so the import statements are valid. Note, I'm not modifying sys.path in any of my application's code - only the py2exe script I use to build the exe.
At the top of my py2exe setup script:
import sys
sys.path.append(PATH_WHERE_PACKAGES_ARE)
# add any packages that need explicit importing here located in root directory:
import package1 # apparently it wasn't found...
import package2 # apparently same thing
Generally I don't import packages though, adding the project root where they exist usually is enough.
I'm not sure that py2exe now how to handle the from ..some_Mod import * syntax, check this to ensure that the some_Mod.py module is correctly packaged : python -m py2exe.mf -d some_dir/another_dir/some_Mod.py as explained in the py2exe FAQ