py2exe cannot import from six.py - python

I'm trying use py2exe on a program that imports urlparse from six.moves.urllib_parse. Here is the program:
# hello.py
from six.moves.urllib_parse import urlparse
print('hello world')
And here is my setup.py:
from distutils.core import setup
import py2exe
setup(console=['hello.py'])
Running hello.py works fine. When I compile hello.py into an exe using python setup.py py2exe, a hello.exe file is produced. However, when I run hello.exe I get an error saying:
ImportError: No module named urlparse
I'm using Python 2.7.
With Python 3.4, I get an error saying KeyError: 'six.moves' when running python setup.py py2exe.
How can I stop these errors from occurring?

The problem is just that py2exe doesn't detect the modules that are proxied through six, so they're not bundled.
All you have to do is add the module in question (urlparse) to your includes in your setup.py:
options={
"py2exe": {
...
"includes": ["urlparse"],
...
That way the module will be packaged, and when six tries to import it, it will work.

py2exe released a new version recently that fixes this problem:
Changes in version 0.9.2.2:
- Added support for six, cffi, pycparser, openssl.
Using this version I was able to create an .exe and run it successfully.

Related

shotgun_api3 not working in PyInstaller exe build

This is my run.py file, it works perfectly fine if you run it manually with something like py -3 run.py
import shotgun_api3
I use Python 3 to build the .exe using PyInstaller:
py -3 -m PyInstaller run.py
The build completes successfully. When I try to run the .exe I get this error:
ModuleNotFoundError: No module named 'xmlrpc'
So I tried adding import xmlrpc above the import shotgun_api3 in my run.py, then the error changed to this:
ModuleNotFoundError: No module named 'xmlrpc.client'
Definitely not the best solution, but I managed to build the executable. I had to remove httplib2 and six from shotgun api, pip-installed them by myself and updated imports in shotgun.py.
I had to add them as hidden imports as well as a few others:
pyinstaller --hidden-import urllib2 --hidden-import xmlrpc --hidden-import xmlrpc.client --hidden-import xmlrpclib --hidden-import cookielib main.py

no module named disutils.core

I have installed the 64 bit version of the Anaconda python distribution on my Windows 64 bit machine. I am trying to cythonize a python script and I get an error at the following line:
from disutils.core import setup
ImportError: No module named disutils.core
I tried
import disutils
ImportError: No module named disutils
Based on the information at the following link :
https://pypi.python.org/pypi/setuptools#windows-7-or-graphical-install
I downloaded and ran ez_setup.py
I still get the same error. Can anyone help me solve my problem ?
from disutils.core import setup
should be:
from distutils.core import setup
You have spelled it disutils and distuils both missing a t
import distuils should be distutils

Py2app Problems : Setup Tools

I've recently installed the latest version of Py2app on my Mac Os X (10.5.8), and I've watched some tutorials on YouTube such as: http://www.youtube.com/watch?v=Zip9H_dLdhI, and http://www.youtube.com/watch?v=5Ehhts9HhE8, but when I copy their main setup code, it gives me an ImportError:
Traceback (most recent call last):
File "/Users/CarlProject/Rectangles Backup.py", line 7, in <module>
from setuptools import setup
ImportError: No module named setuptools
This is my setup code, copied and edited from the first YouTube video:
"""
Usage:
python setup.py py2app
"""
from setuptools import setup
APP = ['Rectangles.py']
DATA_FILES = [('', ['fonts'])]
setup(
app = APP,
data_files = DATA_FILES,
setup_requires = ['py2app'],
)
My Python version is 2.7.5, and I'm using Pygame. The Py2app is the latest: 0.7.3. Yes, everything is on my desktop, and I've installed setuptools 0.9.8 Help!
Just incurred in the same problem but found the solution.
"For ease of distribution, you may wish to have your setup.py script automatically ensure that setuptools is installed. This requires having a copy of ez_setup in your project, which can be obtained from here:"
http://peak.telecommunity.com/dist/ez_setup.py
(Save it in your project directory with .py extension)
"Once this is done, you simply add the two line ez_setup preamble to the very beginning of your setup.py:"
import ez_setup
ez_setup.use_setuptools()
Source: https://pythonhosted.org/py2app/examples.html
You need to install setuptools.
Download it from here and then check this out to learn how to install it:
Python Setuptools, easy_install setup mac

python and py2app mac osx 10.7

i want to create .app application by Py2app, i was installed Py2app on my mac os x lion by terminal and copy "gtkapp.py" (the name of my app that used PyGTK) and "setup.py" but when i run the setup.py get this error:
from setuptools import setup
and
ImportError: cannot import name setup
what problem?
Be sure the py2app binary is in your path. A simple way around this is to use MacPorts for your py2app isntallation.

How Can I Make A Windows Executable With Pyserial?

I am trying to make an executable of a Stackless Python 2.6 program. The setup file is
from distutils.core import setup
import py2exe
setup(console=['controller.py'])
and I run it with
python setup.py py2exe
However, when I try to run it, it raises an ImportError and says that there is no module named serial. When I try:
python setup.py py2exe --includes serial
or
python setup.py py2exe --includes pyserial
the build fails with an ImportError. Do you have any ideas?
Had same issue. Upgrading pyserial to 2.5 solved the problem: exec built without additional "includes" contains pyserial.

Categories