Python 2.7 Py2exe with Tkinter and matplotlib - python-2.7

I'm trying to create an executable using py2exe for my Tkinter widget using python 2.7. This is my setup.py file:
from distutils.core import setup
import Tkinter
import py2exe
import numpy
import matplotlib
import scipy
import FileDialog
includes = ['scipy.special._ufuncs_cxx',
'scipy.sparse.csgraph._validation'
]
#dll_excludes = ['libgdk-win32-2.0-0.dll','libgobject-2.0- 0.dll','libgdk_pixbuf-2.0-0.dll']
setup(
console=["home.py"]
,options={"py2exe":{'includes':includes
# ,'packages' : ['matplotlib','pytz']
# ,'dll_excludes': dll_excludes
}
}
,data_files=matplotlib.get_py2exe_datafiles()
)
The executable compiles fine, but when I try to run home.exe from the dist folder it gives me this message.......and I have no idea how to fix it (I thought doing import FileDialog would do it):
File "matplotlib\backends\backend_tkagg.pyc", line 7, in <module>
File "six.pyc", line 194, in load_module
File "six.pyc", line 108, in _resolve
File "six.pyc", line 79, in _import_module
ImportError: No module named FileDialog
Thanks very much

Related

No module named 'django.contrib.admin.templatetags.admin_static'

my django version is 3.0.5 and django-suit version is 0.2.28 but why does this error happen?
the whole error information is as follows:
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\suit\admin.py", line 8, in <module>
from suit.widgets import NumberInput, SuitSplitDateTimeWidget
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\suit\widgets.py", line 6, in <module>
from django.contrib.admin.templatetags.admin_static import static
ModuleNotFoundError: No module named 'django.contrib.admin.templatetags.admin_static'
I solved the problem.
Modify this fileļ¼š \Python38\Lib\site-packages\suit\widgets.py
# from django.contrib.admin.templatetags.admin_static import static
from django.contrib.admin import static
then rerun your program, maybe met problem below:
File "D:\Work_Station\Python38\lib\site-packages\suit\templatetags\suit_menu.py", line 17, in <module>
string_types = basestring,
NameError: name 'basestring' is not defined
modify the file : Python38\lib\site-packages\suit\templatetags\suit_menu.py
# from django.utils.six import string_types
from six import string_types

No module name found

I had created a python file which will pull the data from app dynamics for which i had imported the package from appd.request import AppDynamicsClient
it is working fine but now i want to convert it into .exe for which i am using py2exe in py2exe i am trying to include the package appdynamics but it is giving error package not found
from appd.request import AppDynamicsClient
from matplotlib.dates import date2num
import matplotlib.dates as dates
import matplotlib.pyplot as plt
import requests
these are the packages i am importing in main file which i am trying to convert it into .exe file
setup.py file
from distutils.core import setup
from distutils.core import setup
import py2exe
setup(console=['AD_API.py'],
options = {
"py2exe": {
'packages' :['requests','AppDynamicsClient','matplotlib']
}
}
)
ERROR MESSAGE:
ImportError: No module named AppDynamicsClient

import special module error

I am using python2.7.6. When I run this order:
import scipy.special as S
I get this error:
File "/home/liaoya/.local/lib/python2.7/site-packages/scipy/special/__init__.py", line 546, in <module>
from ._ufuncs import *
ImportError: libifport.so.5: cannot open shared object file: No such file or directory
How should I fix this?

AttributeError: 'module' object has no attribute 'Unpickler'

I am running a program in the SciTE text editor and it gets stuck at the import scipy as sp statement.
import pylab as pl
import numpy as np
import scipy as sp
import scipy.integrate as spi
import scipy.optimize as spo
import numpy.random as nr
import matplotlib.pyplot as plt
print "check"
#parameters to be used
rs=0.14
ra=0.0027
js=-0.033
ja=0.81
Mz=91.0
Tz=2.5
root_s=sp.linspace(20.,140.,200) #plotting sigma_A and sigma_S functions against centre of mass energies from 20GeV to 140 GeV
s=(root_s)**2
.....
.....
and I get this error message:
>pythonw -u "collisions.py"
3.14159265359
1.0
Traceback (most recent call last):
File "collisions.py", line 4, in <module>
import scipy as sp
File "C:\Python27\lib\site-packages\scipy\__init__.py", line 85, in <module>
from numpy import oldnumeric
File "C:\Python27\lib\site-packages\numpy\oldnumeric\__init__.py", line 14, in <module>
from compat import *
File "C:\Python27\lib\site-packages\numpy\oldnumeric\compat.py", line 106, in <module>
class Unpickler(pickle.Unpickler):
AttributeError: 'module' object has no attribute 'Unpickler'
>Exit code: 1
The odd thing is that my code works perfectly fine in the interactive qtconsole. I am new to programming, and I have not encountered such a problem elsewhere in the internet. And why is it that the values pi and 1.0 are returned even though there is no where in my code that is supposed to do that?

Pandas + Django + mod_wsgi + virtualenv

Pandas is producing 'module' object has no attribute 'core' when being imported under django and mod_wsgi inside a virtual environment. It works fine running under the django development server inside the virtual environment.
Other modules e.g.: numpy have no problems so I assume this means the virtual environment is set up correctly with mod_wsgi. Any advice would be appreciated.
staging.wsgi
import os
import sys
import site
PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
site_packages = os.path.join(PROJECT_ROOT, 'env/openportfolio/lib/python2.7/site-packages')
site.addsitedir(os.path.abspath(site_packages))
sys.path.insert(0, PROJECT_ROOT)
sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))
os.environ['DJANGO_SETTINGS_MODULE'] = 'openportfolio.settings_staging'
import pandas #triggers error
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
Error
Traceback (most recent call last):
File "/usr/local/web/django/www/staging/openportfolio/apache/staging.wsgi", line 22, in <module>
import pandas
File "/usr/local/web/django/www/staging/env/openportfolio/lib/python2.7/site-packages/pandas/__init__.py", line 12, in <module>
from pandas.core.api import *
File "/usr/local/web/django/www/staging/env/openportfolio/lib/python2.7/site-packages/pandas/core/api.py", line 6, in <module>
import pandas.core.datetools as datetools
AttributeError: 'module' object has no attribute 'core'
Python Path
['/usr/local/web/django/www/staging/openportfolio',
'/usr/local/web/django/www/staging',
'/Library/Python/2.7/site-packages/pip-1.0.2-py2.7.egg',
'/usr/local/web/django/www/staging/env/openportfolio/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg',
'/usr/local/web/django/www/staging/env/openportfolio/lib/python2.7/site-packages/pip-1.0.2-py2.7.egg',
'/usr/local/web/django/www/staging/env/openportfolio/lib/python2.7/site-packages/matplotlib-1.1.0-py2.7-macosx-10.7-intel.egg',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages',
'/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload',
'/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC',
'/Library/Python/2.7/site-packages',
'/usr/local/web/django/www/staging/env/openportfolio/lib/python2.7/site-packages']
So it turns out this was a Python path order issue. By running sys.path.reverse() in my wsgi config file, the code now runs.
Due to the order of Python path, the built in OS X numpy library must have been imported first over the virtual environment one causing the issue.
'RuntimeError: module compiled against API version 6 but this version of numpy is 4' was the error line I missed in my original post which could have helped debug the answer.