running package throws ImportError: No module named image - cx-freeze

Using cx_freeze under ubuntu 12.04. The generation of the package is
done without any errors but when I try to run the package as a
standalone, I get the following error:
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/cx_Freeze/initscripts /Console.py",
line 27, in <module>
exec code in m.__dict__
m m File "Setup_cx_freeze.py", line 3, in <module>
File "/usr/local/lib/python2.7/dist-packages/cx_Freeze/__init__.py",
line 4, in <module>
from cx_Freeze.dist import *
File "/usr/local/lib/python2.7/dist-packages/cx_Freeze/dist.py",
line 3, in <module>
import distutils.command.install
File "/usr/lib/python2.7/distutils/command/install.py", line 21, in <module>
from site import USER_BASE
File "/usr/lib/python2.7/site.py", line 562, in <module>
main()
File "/usr/lib/python2.7/site.py", line 540, in main
abs__file__()
File "/usr/lib/python2.7/site.py", line 100, in abs__file__
m.__file__ = os.path.abspath(m.__file__)
File "/usr/lib/python2.7/email/__init__.py", line 79, in __getattr__
__import__(self.__name__)
ImportError: No module named image
I think what to focus on is the last sentence. "ImportError: No module named image."
The application runs without any problems in pure python environment
So why do I get the Error when running it as a "freeze" package? The
fault is somehow introduced when generating the freeze-package.

I ended up fixing this by explicitly including the package "email.mime" in the setup.py script build exe options.

Missing 'image' is just first part of the problem. Try to add this to your code:
from email.mime.image import MIMEImage
from email.mime.audio import MIMEAudio
from email.mime.message import MIMEMessage
This resolved problems with 'image', 'audio' and 'message'.

Resolved this by installing Python Imaging Library: http://www.pythonware.com/products/pil/
1) python setup.py build
2) sudo python setup.py install

Related

Python 3.6.5 and cx_freeze :

I got this message when trying to execute python executable program, build with cxfreeze, but when I execute the python script .py, there is no problems
D:\TEST2000>Get-List-FoldersID-and-Titles.exe Traceback (most recent call last): File "C:\Python-365\lib\site-packages\cx_Freeze\initscripts__startup__.py", line 14, in run module.run() File "C:\Python-365\lib\site-packages\cx_Freeze\initscripts\Console.py", line 26, in run exec(code, m.dict) File "D:\TEST2000\Get-List-FoldersID-and-Titles.py", line 5, in import requests File "C:\Python-365\lib\site-packages\requests__init__.py", line 98, in from . import packages File "C:\Python-365\lib\site-packages\requests\packages.py", line 7, in locals()[package] = import(package) File "C:\Python-365\lib\site-packages\idna__init__.py", line 2, in from .core import * File "C:\Python-365\lib\site-packages\idna\core.py", line 1, in from . import idnadata ImportError: cannot import name 'idnadata'
How do I resolve the ImportError that I am getting?
idnadata is a module from the idna package. When you build the executable with cx_Freeze, use the packages option to include the idna package.
In your setup.py
setup(
options={
"build_exe": {
"packages": ["idna"],
},
},
)

LazyITKModule' object has no attribute 'AnalyzeImageIO'

from medpy.io import load
import SimpleITK
import vtk
image_data, image_header = load('/Users/N01-T2.mha')
print image_data.shape
And the error is:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/wuzhenglin/anaconda/lib/python2.7/site-packages/spyder/utils/site/sitecustomize.py", line 880, in runfile
execfile(filename, namespace)
File "/Users/wuzhenglin/anaconda/lib/python2.7/site-packages/spyder/utils/site/sitecustomize.py", line 94, in execfile
builtins.execfile(filename, *where)
File "/Users/wuzhenglin/Python_nice/SAL_LUNG/test.py", line 140, in <module>
changeage()
File "/Users/wuzhenglin/Python_nice/SAL_LUNG/test.py", line 42, in changeage
image_data, image_header = load('/Users/wuzhenglin/Python_nice/SAL_BRAIN/brain_healthy_dataset/Normal001-T2.mha')
File "/Users/wuzhenglin/anaconda/lib/python2.7/site-packages/medpy/io/load.py", line 201, in load
raise err
medpy.core.exceptions.ImageLoadingError: Failes to load image /Users/wuzhenglin/Python_nice/SAL_BRAIN/brain_healthy_dataset/Normal001-T2.mha as
Itk/Vtk MetaImage (.mhd, .mha/.raw). Reason signaled by third-party module:
'LazyITKModule' object has no attribute 'AnalyzeImageIO'
I want to deal with .mha image, but it doesn't work.
I have installed medpy, itk and vtk.
I have searched on Google, but there is not related answer to this problem.
Does the same error occur without the import SimpleITK line? I don't think that is relevant to producing this error.
ITK for Python and SimpleITK are two separate Python packages which provide different interfaces to ITK. The error you are seeing is lated to ITK for Python, or the itk package on PyPi. Where did you itk install come from. Can you run a simple program like this, with your install?
#!/usr/bin/env python
import itk
pixelType = itk.UC
imageType = itk.Image[pixelType, 2]
readerType = itk.ImageFileReader[imageType]

Importing pandas in windows

I tried multiple methods with Anaconda and python both using version 3.6 and when I import pandas I'm getting the following error in my Windows machine
import pandas
File "D:\python3\lib\site-packages\pandas\__init__.py", line 22, in <module>
from pandas.compat.numpy import *
File "D:\python3\lib\site-packages\pandas\compat\__init__.py", line 59, in <module>
import http.client as httplib
File "D:\python3\lib\http\client.py", line 71, in <module>
import email.parser
File "D:\email.py", line 5, in <module>
import pandas.io.sql as psql
File "D:\python3\lib\site-packages\pandas\io\sql.py", line 14, in <module>
import pandas.lib as lib
File "pandas\lib.pyx", line 1, in init pandas.lib (pandas\lib.c:90879)
File "pandas\tslib.pyx", line 59, in init pandas.tslib (pandas\tslib.c:115313)
ImportError: cannot import name is_platform_windows
It seems to be environment related but I can't find anything related to this issue when I google this.
Looks like it was picking anything python script in my folder called email.py and that's causing the issue.

ImportError: No module named 'ruamel' running Anaconda

I am using MacOS X 10.11.2 and I want to install Anaconda 3, so that I downloaded the Anaconda3-4.3.0-MacOSX-x86_64.pkg from here. After I installed, I tried runnging this but I got the error like the following.
S0106602ad06e3352:bin jouk$ conda
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/conda/common/configuration.py", line 38, in <module>
from ruamel_yaml.comments import CommentedSeq, CommentedMap
ImportError: No module named 'ruamel_yaml'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.5/bin/conda", line 7, in <module>
from conda.cli.main import main
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/conda/cli/__init__.py", line 8, in <module>
from .main import main # NOQA
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/conda/cli/main.py", line 46, in <module>
from ..base.context import context
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/conda/base/context.py", line 18, in <module>
from ..common.configuration import (Configuration, MapParameter, PrimitiveParameter,
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/conda/common/configuration.py", line 40, in <module>
from ruamel.yaml.comments import CommentedSeq, CommentedMap # pragma: no cover
ImportError: No module named 'ruamel'
S0106602ad06e3352:bin jouk$
I tried solving this error with this workaround (here). But in this case is for the case in which I installed Anaconda twice to two places in local. But, I didn't do that. What is my problem?

OPENSSL_1.0.1 Error When Executing Job Inside Jenkins

I've written a python script using scrapy to crawl a site, and I'm trying to set up a job through jenkins to call the script nightly (this way it's very easy to see the output).
The machine I'm running jenkins on is a bitnami VM inside google compute.
I set up the command to run through the shell command in jenkins, and it's failing with the following error:
Building on master in workspace /opt/bitnami/apps/jenkins/jenkins_home/jobs/Scrape and Import myco/workspace [workspace] $ /bin/sh -xe /opt/bitnami/apache-tomcat/temp/hudson4165433582945317339.sh
+ /usr/local/myco/myscript.py -l /usr/local/myco/results/7.log -o /usr/local/myco/results/7.json -s /usr/local/myco/results/7.stats myspider
Traceback (most recent call last): File "/usr/local/myco/myscript.py", line 5, in <module>
from twisted.internet import reactor File "/usr/local/lib/python2.7/dist-packages/twisted/internet/reactor.py", line 38, in <module>
from twisted.internet import default File "/usr/local/lib/python2.7/dist-packages/twisted/internet/default.py", line 56, in <module>
install = _getInstallFunction(platform) File "/usr/local/lib/python2.7/dist-packages/twisted/internet/default.py", line 44, in _getInstallFunction
from twisted.internet.epollreactor import install File "/usr/local/lib/python2.7/dist-packages/twisted/internet/epollreactor.py", line 24, in <module>
from twisted.internet import posixbase File "/usr/local/lib/python2.7/dist-packages/twisted/internet/posixbase.py", line 23, in <module>
from twisted.internet import error, udp, tcp File "/usr/local/lib/python2.7/dist-packages/twisted/internet/tcp.py", line 29, in <module>
from twisted.internet._newtls import ( File "/usr/local/lib/python2.7/dist-packages/twisted/internet/_newtls.py", line 21, in <module>
from twisted.protocols.tls import TLSMemoryBIOFactory, TLSMemoryBIOProtocol File "/usr/local/lib/python2.7/dist-packages/twisted/protocols/tls.py", line 41, in <module>
from OpenSSL.SSL import Error, ZeroReturnError, WantReadError File "/usr/local/lib/python2.7/dist-packages/OpenSSL/__init__.py", line 8, in <module>
from OpenSSL import rand, crypto, SSL File "/usr/local/lib/python2.7/dist-packages/OpenSSL/rand.py", line 11, in <module>
from OpenSSL._util import ( File "/usr/local/lib/python2.7/dist-packages/OpenSSL/_util.py", line 7, in <module>
binding = Binding() File "/usr/local/lib/python2.7/dist-packages/cryptography/hazmat/bindings/openssl/binding.py", line 114, in __init__
self._ensure_ffi_initialized() File "/usr/local/lib/python2.7/dist-packages/cryptography/hazmat/bindings/openssl/binding.py", line 126, in _ensure_ffi_initialized
cls._modules, File "/usr/local/lib/python2.7/dist-packages/cryptography/hazmat/bindings/utils.py", line 31, in load_library_for_binding
lib = ffi.verifier.load_library() File "/usr/local/lib/python2.7/dist-packages/cffi/verifier.py", line 97, in load_library
return self._load_library() File "/usr/local/lib/python2.7/dist-packages/cffi/verifier.py", line 207, in _load_library
return self._vengine.load_library() File "/usr/local/lib/python2.7/dist-packages/cffi/vengine_cpy.py", line 155, in load_library
raise ffiplatform.VerificationError(error) cffi.ffiplatform.VerificationError: importing '/usr/local/lib/python2.7/dist-packages/cryptography/_Cryptography_cffi_e7d09016xc302a38b.so': /usr/local/lib/python2.7/dist-packages/cryptography/_Cryptography_cffi_e7d09016xc302a38b.so: symbol EC_GFp_nistp521_method, version OPENSSL_1.0.1 not defined in file libcrypto.so.1.0.0 with link time reference Build step 'Execute shell' marked build as failure Finished: FAILURE
I'm perplexed because when I run the same command (as my user and the user jenkins is running under, tomcat) I don't get this error, the script works fine.
I suspect this may have to do with the script being executed inside apache, but I'm at my wits end and googling hasn't turned up any obvious solutions.
Any idea as to how to solve this?
symbol EC_GFp_nistp521_method, version OPENSSL_1.0.1 not defined in file libcrypto.so.1.0.0
It looks like you are running a python compiled with OpenSSL 1.0.1 with a libcrypto from OpenSSL 1.0.0. It might be because you are running with a different python (at least compiled against a different OpenSSL version) but include files from your local python installation which expects the newer OpenSSL.

Resources