Python to exe: py2exe issues with pkg_resources - python

I've built an application in Python that I'd like to distribute to my enterprise and installing Python on each machine is unfortunately not an option. I'd like to convert the application to an .exe so that users can run my application with shortcut on their desktop.
This is my first attempt at distribution, so please forgive my lack of knowledge on the subject. I'm having issues with py2exe when I attempt to convert my .py script to a .exe.
My setup.py script looks like this:
from distutils.core import setup
import py2exe
import numpy
import matplotlib
setup(console=['inpho.py'],
data_files=matplotlib.get_py2exe_datafiles()
)
After I run python setup.py py2exe, I get the expected dist and build directories. However, if I run my application, now called InPho.exe, a cmd window opens and I immediately get an error: ImportError: No module named pkg_resources.
My first thought is that my setup.py script is wrong, I just do not know how to properly write one. In my inpho.py script, I use import the following:
pandas
Tkinter
pyodbc
sqlalchemy
sqlite3
datetime
tkMessageBox
os
shutil
Any help is greatly appreciated!

Py2exe might not handle some of the dependencies out of the box. Try this advice from the py2exe tutorial on how to handle import errors in this case: Dealing With ImportError

I had some similar issues with py2exe. I was able to fix them by downgrading setuptools to version 19.2.
You can see more information about this setuptools issue here: https://github.com/pyinstaller/pyinstaller/issues/1781

Related

from setuptools.errors import OptionError ImportError: cannot import name 'OptionError' from 'setuptools.errors'

i am trying to create an executable using cx_freeze. and when i run
python setup.py build i get the following error:
from setuptools.errors import OptionError
ImportError: cannot import name 'OptionError' from 'setuptools.errors'
I am working in anaconda. I tried reverting to a previous cx_freeze version with no luck.
This a a new problem two month ago when i created another virtual envieonment i didn't have this problem. This is why i'm guessing it could be maybe a version issue. However i can't seem to find the correct version to install.
i also checked other related issues however i didn't find a solution that works for me. If you have an idea please let me know!
Thank you
It's difficult to tell without additional info, package versions, a more complete trace, etc.
I ran into this same error during a build post-upgrade of cx_Freeze but after already having setuptools installed. Reinstalling setuptools to the most current version (65.6.3) corrected the error in my case. I'm running cx_Freeze version 6.13.1 if it helps move you past the error.
Typically, Python errors of the sort ImportError: cannot import name ... indicate circular dependencies, e.g.,: https://stackoverflow.com/a/9252628/9975319 - it could be that the order of imports cx_Freeze does changes across builds causing the dependencies to import incorrectly but I haven't dug deeper into it.

unable to import module pyautogui

I am working on OS X
Ive looked at many different threads and haven't found a solution. Maybe I haven't been installing things properly from the start either. I want to import the module pyautogui into my project but it is saying it can't find it. I did a pip install in terminal and in the pycharmterminal as well. I have found the file directory and verified that it is available. But yet I am still not able to access it in my project. On some of the threads I read something about init.py, do I need to put that in my project. If so is there code in that py file or do I just create a python file named init.py
On Mac OS and some Linux distros, you may need to type pip3 install package-name.

DateEntry widget is not working after creating an executable using pyinstaller [duplicate]

I'm trying to install python application on Windows with pyinstaller where I'm using tkcalendar. Application is working but the tkcalendar.Calendar isn't.
When I'm running application without installation everything works but if I do this, Calendar widget does not appear.
I think that pyinstaller sees this module but he has problems with modules that tkcalendar is using.
I tried to run pyinstaller with --path=/.../python/Lib/site-packages but this didnt worked. Also copying module files to application directory didn't help.
The issue does not come from tkcalendar but from the fact that PyInstaller does not detect second level imports. A way to solve this issue is explained in tkcalendar's documentation in the HowTos section:
When bundling an application with PyInstaller, there is an
issue with the
detection of the babel dependency of tkcalendar. This can be fixed by
using the --hidden-import option:
$ pyinstaller --hidden-import babel.numbers myscript.py
or by editing the .spec file:
hiddenimports=["babel.numbers"]
Add following code to your python script, while bundling with pyinstaller
import babel.numbers
If anyone found the same problem.
In tkcalendar 1.5.0 there is problem with import in calendar.py.
Locate the tkcalendar folder (probably /.../python/Lib/site-packages/tkcalendar) and under calendar.py add an additional import for the missing module:
import calendar
from babel.dates import format_date, parse_date, get_day_names, get_month_names
from babel.numbers import * # Additional Import```

Cannot import livestreamer module in python

I am new to python and just tried to import the live streamer module (http://livestreamer.readthedocs.org/en/latest/api.html) in Python.
The module is installed at:
/Library/Python/2.7/site-packages/livestreamer-1.8.0-py2.7.egg
My script is pretty much one line:
from livestreamer import Livestreamer
Error:
ImportError: cannot import name Livestreamer
I searched the web for similar issues, but couldn't find any related to this module, but apparently it's a circular dependent import...? I don't know how to fix this.
Note: My script works when it's just:
import livestreamer
I'd say the modules doesn't contain a class called Livestreamer, but the documentation says so.
Did you properly installed Livestreamer.? R u experienced any error ..?
Try running this command from the package
pip install setup.py

py2exe not making exe?

I am following the tutorial for py2exe from this site http://www.py2exe.org/index.cgi/Tutorial
this is the setup code:
from distutils.core import setup
import py2exe
setup(console=['script.py'])
when I type in cmd:
python setup.py install
I get this:
running install
running build
my script works fine and I even tried it for simple scripts such as
print "hello world"
I was able to use py2exe before without any problems but for some reason it stop working for me. I even tried to reinstall the module but it still won't do anything. Any idea's from those brilliant minds on stack overflow?
To build an exe, the command is:
python setup.py py2exe

Categories