Pyinstaller with PIL. ImportError: cannot import name _imaging - build

I am having trouble running a compiled executable that includes pillow. I have used pyinstaller which seems to compile well enough, however after running the exe, an error is thrown. Seems there is a conflict with '_imaging' being referenced instead of 'Image'.
First off, I find it strange how pillow installs to a PIL directory rather than a pillow and the modules are also referenced as PIL. I doubt that has anything to do with the problem though.
There isn't actually a _imaging.py file in Python27\Lib\site-packages\PIL however and I suspect this might be a problem as somehow pyinstaller has made the executable require it. Not sure if there is some way to exclude it from the build. This may be a next step.
Issues like this and thishave been raised but not solved. Some also refer to PIL not being uninstalled before installing pillow, but PIL is definitely uninstalled and I have tried both binaries and pip installs of pillow.
Any suggestions?
Error from runtime:
Traceback (most recent call last):
File "<string>", line 26, in <module>
File "C:\Python27\Lib\site-packages\PyInstaller\loader\pyi_importers.py", line 270, in load_module
exec(bytecode, module.__dict__)
File "C:\Users\Hp\PycharmProjects\GISdev\build\gis_helper2\out00-PYZ.pyz\PIL.PngImagePlugin", line 40, in <module>
File "C:\Python27\Lib\site-packages\PyInstaller\loader\pyi_importers.py", line 270, in load_module
exec(bytecode, module.__dict__)
File "C:\Users\Hp\PycharmProjects\GISdev\build\gis_helper2\out00-PYZ.pyz\PIL.Image", line 63, in <module>
ImportError: cannot import name _imaging
Extract from the PIL.Image file is below and the offending line is
from PIL import _imaging as core
try:
# If the _imaging C module is not present, Pillow will not load.
# Note that other modules should not refer to _imaging directly;
# import Image and use the Image.core variable instead.
# Also note that Image.core is not a publicly documented interface,
# and should be considered private and subject to change.
from PIL import _imaging as core
if PILLOW_VERSION != getattr(core, 'PILLOW_VERSION', None):
raise ImportError("The _imaging extension was built for another "
" version of Pillow or PIL")
from PIL import Image
And this is how I am calling pillow from my script:
from PIL import Image

Related

numpy and pandas breaking after installing biopython on spyder anaconda

I'm using spyder 2 anaconda 2.3.0 on windows as a python IDE for python 2.7. I've been using this for a long time to code in python but suddenly I don't know what happened and it said I did not have biopython package installed, when I installed biopython using
conda -c install anaconda biopython
command, biopython started running however it broke pandas and numpy.
now when I import pandas I get this:
>>> import pandas as pd
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Anaconda\lib\site-packages\pandas\__init__.py", line 13, in
<module>
"extensions first.".format(module))
ImportError: C extension: hashtable not built. If you want to import pandas
from the source directory, you may need to run 'python setup.py build_ext --
inplace' to build the C extensions first.
and then when I import numpy I get this:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Anaconda\lib\site-packages\numpy\__init__.py", line 142, in <module>
from . import add_newdocs
File "C:\Anaconda\lib\site-packages\numpy\add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "C:\Anaconda\lib\site-packages\numpy\lib\__init__.py", line 8, in <module>
from .type_check import *
File "C:\Anaconda\lib\site-packages\numpy\lib\type_check.py", line 11, in <module>
import numpy.core.numeric as _nx
File "C:\Anaconda\lib\site-packages\numpy\core\__init__.py", line 26, in <module>
raise ImportError(msg)
ImportError:
Importing the multiarray numpy extension module failed. Most
likely you are trying to import a failed build of numpy.
If you're working with a numpy git repo, try `git clean -xdf` (removes all
files not under version control). Otherwise reinstall numpy.
Original error was: DLL load failed: The specified module could not be found.
I uninstalled numpy and pandas and then installed them back using pip ... still the same. I entirely unistalled anaconda and installed it back still the same errors. I really do not know what's causing this. Any help will be truly appreciated. I've been trying to fix this for the past three days and its not working out. Thanks for your time.

Pyinstaller choking on underscore module names. ImportError: cannot import name _proj

I am having trouble running a compiled build containing pyproj. I have used pyinstaller to compile and keep running into the 'cannot import name error' at runtime.
This is a similar type of error to what I've reported here regarding PIL. Specifically with regards to naming conventions and the type of error.
A similar qustion has been asked here although I didn't find their suggestion fixed the error in my case.
I've added in the _proj.pyd as a binary to the build folder and referenced in the spec file but to no avail.
Incidentally, can anyone explain what is the deal with certain modules being called by the underscore naming convention rather than the capital?
In this instance, _proj rather than Proj. These types of modules also usually only contain a .pyd and not a .py in their module folder, resulting in the compiler getting confused when compiling to executables. Noticing a similar pattern with problem modules and don't really understand it.
import _socket # dynamically loaded from C:\Users\Hp\AppData\Local\Temp\_MEI53882\_socket.pyd
import parser # builtin
import win32api # dynamically loaded from C:\Users\Hp\AppData\Local\Temp\_MEI53882\win32api.pyd
import pywintypes # dynamically loaded from C:\Users\Hp\AppData\Local\Temp\_MEI53882\pywintypes27.dll
import pythoncom # dynamically loaded from C:\Users\Hp\AppData\Local\Temp\_MEI53882\pythoncom27.dll
Traceback (most recent call last):
File "<string>", line 50, in <module>
File "C:\Python27\Lib\site-packages\PyInstaller\loader\pyi_importers.py", line 270, in load_module
exec(bytecode, module.__dict__)
File "C:\Users\Hp\PycharmProjects\GISdev\build\gis_helper2\out00-PYZ.pyz\pyproj", line 50, in <module>
ImportError: cannot import name _proj
This was fixed by uninstalling pyproj and installing basemap which contains pyproj as a submodule. For some reason, pyinstaller picks this up.

How to properly install sklearn on Eclipse

I recently came across a blog(http://stronginference.com/ScipySuperpack/) on how to install sklearn . I successfully installed it and it was stored on the path:
/usr/local/lib/python2.7/site-packages/sklearn
I then went to the properties of my eclipse; under the Interpreter-Python and added the path to the PYTHONPATH. I could import sklearn but when I ran this simple code to test everything:
from sklearn import datasets
iris = datasets.load_iris()
digits = datasets.load_digits()
print digits.data
It threw the following errors:
Traceback (most recent call last):
File "/Users/licheng/Documents/workspaceII/SkLearnTutorial/Src/my_first_scilearn.py", line 6, in <module>
from sklearn import datasets
File "/usr/local/lib/python2.7/site-packages/sklearn/datasets/__init__.py", line 7, in <module>
from .base import load_diabetes
File "/usr/local/lib/python2.7/site-packages/sklearn/datasets/base.py", line 24, in <module>
from ..utils import check_random_state
File "/usr/local/lib/python2.7/site-packages/sklearn/utils/__init__.py", line 10, in <module>
from .murmurhash import murmurhash3_32
File "numpy.pxd", line 155, in init sklearn.utils.murmurhash (/private/var/folders/fv/vhs3w0zn2q961_gyp8f2z_rw0000gn/T/pip-EVsI8B-build/sklearn/utils/murmurhash.c:5029)
ValueError: numpy.dtype has the wrong size, try recompiling
any help on what could be wrong? I have been on these for hours now.
Thanks
Try uninstalling NumPy, SciPy and scikit-learn.
Then reinstall those packages.
If you are using Windows, binaries for those packages have been provided by Christoph Gohlke, which can be quite convenient. Just download them and then use pip to install.
Unofficial Windows Binaries for Python Extension Packages

Python 2.7.9 PyBrain issue with SciPy

I just tried installing SciPy using scipy‑0.15.1‑cp27‑none‑win_amd64.whl
I have Python 2.7.9 x64 installed
I have wheel installed
I have numpy installed
I am working under Windows7
The log said that scipy has been successfully installed after running:
pip install scipy-0.15.1-cp27-none-win_amd64.whl
The log said that pybrain has been installed succeffully as well:
pip install pybrain
When I create a python file I can import scipy, but when I try to import pybrain I get:
Traceback (most recent call last): File
"C:\Users\me\Desktop\PROJECT\nn.py", line 1, in
import pybrain File "C:\Python27\lib\site-packages\pybrain__init__.py", line 1, in
from structure.init import * File "C:\Python27\lib\site-packages\pybrain\structure__init__.py", line 2,
in
from modules.init import * File "C:\Python27\lib\site-packages\pybrain\structure\modules__init__.py",
line 2, in
from gate import GateLayer, DoubleGateLayer, MultiplicationLayer, SwitchLayer File
"C:\Python27\lib\site-packages\pybrain\structure\modules\gate.py",
line 11, in
from pybrain.tools.functions import sigmoid, sigmoidPrime File "C:\Python27\lib\site-packages\pybrain\tools\functions.py", line 4, in
from scipy.linalg import inv, det, svd File "C:\Python27\lib\site-packages\scipy\linalg__init__.py", line 161, in
from .misc import * File "C:\Python27\lib\site-packages\scipy\linalg\misc.py", line 5, in
from . import blas File "C:\Python27\lib\site-packages\scipy\linalg\blas.py", line 155, in
from scipy.linalg import _fblas ImportError: DLL load failed: The specified module could not be found.
trying to
import from scipy.linalg import _fblas
only gives the same error:
Traceback (most recent call last): File
"C:\Users\me\Desktop\PROJECT\nn.py", line 1, in
from scipy.linalg import _fblas File "C:\Python27\lib\site-packages\scipy\linalg__init__.py", line 161, in
from .misc import * File "C:\Python27\lib\site-packages\scipy\linalg\misc.py", line 5, in
from . import blas File "C:\Python27\lib\site-packages\scipy\linalg\blas.py", line 155, in
from scipy.linalg import _fblas ImportError: DLL load failed: The specified module could not be found.
I reached a conclusion I am missing LAPACK so i build it using this link The build finished and all tests passed, but the issue is still there... maybe i did not copy the LIB and BIN to the right destination...
Uninstall and reinstall.
If you didn't install with sudo the first time, that may be the problem if you're installing for your global Python modules.
You can also try using installs from here:
http://www.lfd.uci.edu/~gohlke/pythonlibs/#scipy-stack

What should I modify to solve the "No module named _sqlite3" error message?

I installed ATpy-0.9.7 on my pc successfully and I also have the Python version of "2.7.5".
But when I import atpy I get the following error message:
>>> import atpy
ERROR: ImportError: No module named _sqlite3 [unknown]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "atpy/__init__.py", line 1, in <module>
from .basetable import Table, TableSet, VectorException
File "atpy/basetable.py", line 15, in <module>
from . import registry
File "atpy/registry.py", line 186, in <module>
from . import sqltable
File "atpy/sqltable.py", line 10, in <module>
from . import sqlhelper as sql
File "atpy/sqlhelper.py", line 11, in <module>
import sqlite3
File "/export/aibn84_2/zahra/lib/Python-2.7.5/lib/python2.7/sqlite3/__init__.py", line 24, in <module>
from dbapi2 import *
File "/export/aibn84_2/zahra/lib/Python-2.7.5/lib/python2.7/sqlite3/dbapi2.py", line 27, in <module>
from _sqlite3 import *
ImportError: No module named _sqlite3
I also installed db_sqlite3.egg-info. I don't know why this error message occurs!
I installed again th python2.7.5 with the following command :
./configure --prefix=$PYTHONPATH
but I also get this error after executing make:
Python build finished, but the necessary bits to build these modules were not found:
_bsddb _sqlite3 bsddb185
dbm dl gdbm
imageop sunaudiodev
To find the necessary bits, look in setup.py in detect_modules() for the module's name.
How could I run configure in order to install required C libraries?
If you are using a self built version of Python you need to ensure that both the base and the development sqllite3 packages are installed on your system before building Python.
If they are not and, as you said, you do not have superuser privileges, you can download and build sqlite locally, and get your Python build to use that version. This blog post describes how.
According to this question
How can I install sqlite3 to Python?
...you shouldn't have to install anything to get sqlite3 for python. Before I could import atpy I did have to install astropy (which was quite involved). After I did that, everything worked.