pyinstaller importing scipy module - python-2.7

A little python script that uses the scipy module executes perfectly, but when a stand-alone executable is compiled with pyinstaller the executable fails. Details:
Windows 10 python 2.7.10 pyinstaller 3.3.1
The error message is:
C:\Users\barry\Desktop\Testing>TestScipy
Traceback (most recent call last):
File "TestScipy.py", line 15, in <module>
from scipy import stats
File "c:\python27\Lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 396, in load_module
exec(bytecode, module.__dict__)
File "site-packages\scipy\stats\__init__.py", line 343, in <module>
File "c:\python27\Lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 396, in load_module
exec(bytecode, module.__dict__)
File "site-packages\scipy\stats\stats.py", line 169, in <module>
File "c:\python27\Lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 396, in load_module
exec(bytecode, module.__dict__)
File "site-packages\scipy\special\__init__.py", line 640, in <module>
File "c:\python27\Lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 687, in load_module
module = imp.load_module(fullname, fp, filename, ext_tuple)
ImportError: DLL load failed: The specified module could not be found.
[9476] Failed to execute script TestScipy
How can I ensure that pyinstaller loads scipy correctly?

You can add scipy.stats to the hiddenimports list in the .spec file and run PyInstaller again (pyinstaller myfile.spec). Or you could add the following option to your PyInstaller command:
pyinstaller [options] --hiddenimport=scipy.stats myfile.py

The problem with pyinstaller finding scipy.stats turns out to depend on the Python installation used:
Mac OSX: the native python in 10.13 does not exhibit the problem.
Windows 10: Using Anaconda python eliminates the problem.
Ubuntu Linux 16.10: Using Anaconda python eliminates the problem.

Related

gcloud version 306.0.0 causing "No module named 'urllib2'" errors

After updating gcloud from version 290.0.1 to version 306.0.0, I'm getting an error when I run a gsutil cp command:
Traceback (most recent call last):
File "/usr/lib/google-cloud-sdk/platform/gsutil/gsutil", line 21, in <module>
gsutil.RunMain()
File "/usr/lib/google-cloud-sdk/platform/gsutil/gsutil.py", line 122, in RunMain
import gslib.__main__
File "/usr/lib/google-cloud-sdk/platform/gsutil/gslib/__main__.py", line 53, in <module>
import boto
File "/usr/lib/google-cloud-sdk/platform/gsutil/gslib/vendored/boto/boto/__init__.py", line 1216, in <module>
boto.plugin.load_plugins(config)
File "/usr/lib/google-cloud-sdk/platform/gsutil/gslib/vendored/boto/boto/plugin.py", line 93, in load_plugins
_import_module(file)
File "/usr/lib/google-cloud-sdk/platform/gsutil/gslib/vendored/boto/boto/plugin.py", line 75, in _import_module
return imp.load_module(name, file, filename, data)
File "/usr/lib/python3.6/imp.py", line 235, in load_module
return load_source(name, filename, file)
File "/usr/lib/python3.6/imp.py", line 172, in load_source
module = _load(spec)
File "/usr/share/google/boto/boto_plugins/compute_auth.py", line 18, in <module>
import urllib2
ModuleNotFoundError: No module named 'urllib2'
Following the downgrade instructions at https://cloud.google.com/sdk/docs/downloads-apt-get#downgrading_cloud_sdk_versions temporarily fixes the issue:
sudo apt-get update && sudo apt-get install google-cloud-sdk=290.0.1-0
But I'd like to know how to get this working with the latest version.
I have installed the version 306.0.0 and I ran a gcloud cp command, but I didn't face the issue. For this reason, checking for causes for the error ModuleNotFoundError: No module named 'urllib2', it seems that they are always related to a Python library that isn't working correctly - as you can check in this two examples here and here.
However, in further searches, this plugin usually is used within Compute Engine and startup scripts to VMs with Python, more specific relating to the file compute_auth.py - which in the message seems to be related to the error - and as you can check for more information here about this file.
Considering that, the new version of Cloud SDK bring some updates to Compute Engine that could be causing the error. In case you are indeed, using Python within your applications, I would give it a try the solution from this case here, that would be to update the file compute_auth.py, changing the line import urllib2 toimport urllib.request as urllib2.
In case this doesn't fix, raising a bug within Google's Issue Tracker will be the best option, for a further investigation.
I had a similar case. In my case, Travis CI/CD was giving the below error. What I did is add the below script to my .travis.yml file before_script section.
Error:
Traceback (most recent call last):
635 File "/usr/lib/google-cloud-sdk/platform/gsutil/gsutil", line 21, in <module>
636 gsutil.RunMain()
637 File "/usr/lib/google-cloud-sdk/platform/gsutil/gsutil.py", line 121, in RunMain
638 import gslib.__main__
639 File "/usr/lib/google-cloud-sdk/platform/gsutil/gslib/__main__.py", line 83, in <module>
640 import httplib2
641ModuleNotFoundError: No module named 'httplib2'
642error Command failed with exit code 1
Fix:
before_script:
- pip install httplib2 crcmod

ImportError: cannot import name _remove_dead_weakref python 2.7

I use windows 7 and python 2.7
When I used py2exe to make an .exe file I get the error;
Traceback (most recent call last):
File "mainpy", line 17, in
File "main.py", line 17, in
File "zipextimporter.pyc", line 82, in load_module
File "zipextimporter.pyc", line 82, in load_module
File "logging_init_.pyc", line 26, in
File "zipextimporter.pyc", line 82, in load_module
File "weakref.pyc", line 14, in
ImportError: cannot import name _remove_dead_weakref
The same code could be used to make an .exe file in another computer so there is nothing wrong with the code in main.py. The minor environmental difference may cause this problem. I used pycharm, python 2.7.10 and py2exe 0.6.9. On another computer all other config are the same except using sublimetext instead of pycharm.
Could anyone please tell me how to fix that?
Another tricky thing is that
It is possible that the library does not exists for the other computer.Please check whether the library exists or not.

Cannot run TensorFlow compiled with MKL

I've compiled the latest TensorFlow on Ubuntu 16.04 with CUDA and MKL like so
bazel build --config=opt --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=0" --config=mkl --config=cuda //tensorflow/tools/pip_package:build_pip_package
And now when I'm trying to run it I'm getting an error saying that one of intel's libraries can't be found. I've also found other people who're installing a different DNN framework struggling with this https://github.com/PaddlePaddle/Paddle/issues/3213 and found an Intel doc https://software.intel.com/en-us/articles/intel-mkl-dnn-part-1-library-overview-and-installation that basically says that these files should become avilable when you follow the directions in that doc as far as I understood this. I've followed those directions and everything seems to have worked, but in reality those libmklml_intel.so and libiomp5.so files weren't added to /usr/local/lib.
>>> import tensorflow
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/tensorflow/__init__.py", line 24, in <module>
from tensorflow.python import *
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/__init__.py", line 49, in <module>
from tensorflow.python import pywrap_tensorflow
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/pywrap_tensorflow.py", line 52, in <module>
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/pywrap_tensorflow.py", line 41, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 24, in swig_import_helper
_mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
ImportError: libmklml_intel.so: cannot open shared object file: No such file or directory
Edit:
actually, they were located in /mkl-dnn/external/mklml_lnx_2018.0.20170720/lib after I've cloned mkl-dnn git and followed directions in https://software.intel.com/en-us/articles/intel-mkl-dnn-part-1-library-overview-and-installation
Actually, the libs were located in /mkl-dnn/external/mklml_lnx_2018.0.20170720/lib after I've cloned mkl-dnn git and followed directions in https://software.intel.com/en-us/articles/intel-mkl-dnn-part-1-library-overview-and-installation
So I copied them into /usr/local/lib and included those folders in .bashrc as
export LIBRARY_PATH=/usr/local/lib:$LIBRARY_PATH
export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
and reloaded .bashrc
source ~/.bashrc
And now TensorFlow works.

ImportError: No module named six - Already Installed six

I've installed six with the command
pip install six
and if I print the version with:
python -c "import six; print (six.__version__)"
the version of six is listed as:
1.10.0
I'm trying to convert my Python program into stand-alone executable.
I've tried py2exe and PyInstaller. Both create the package fine but when I run the main.exe I get a brief flash with the following error:
Traceback (most recent call last):
File "main.py", line 9, in <module>
File "requests\__init__.pyc", line 58, in <module>
File "requests\utils.pyc", line 26, in <module>
File "requests\compat.pyc", line 7, in <module>
File "requests\packages\__init__.pyc", line 7, in <module>
File "urllib3\__init__.pyc", line 10, in <module>
File "urllib3\connectionpool.pyc", line 30, in <module>
File "urllib3\packages\six.pyc", line 5, in <module>
ImportError: No module named six
Can someone help me understand how to use this traceback to fix my issue?
I have tried to include six in my setup.py for p2exe:
from distutils.core import setup
import py2exe
setup(windows=[{"script":"main.py"}], options={"py2exe":{"includes":["six"]}})
But alas it did not work.
pip install urllib3 --upgrade
solved the issue.
Found this here: https://stackoverflow.com/a/44071536/3804349

Can't install pip because I get "the system cannot find the file specified" whenever I run get-pip.py (python 2.7)

So I'm running Python 2.7.11 and am trying to install pip. I thought pip was already installed on Python 2 >= 2.7.9, but I guess I was wrong. Whenever I try to run get-pip.py, I get:
`Traceback (most recent call last):
File "get-pip.py", line 19177, in <module>
main()
File "get-pip.py", line 194, in main
bootstrap(tmpdir=tmpdir)
File "get-pip.py", line 82, in bootstrap
import pip
File "c:\users\user\appdata\local\temp\tmp41xybl\pip.zip\pip\__init__.py", line 14, in <module>
File "c:\users\user\appdata\local\temp\tmp41xybl\pip.zip\pip\utils\__init__.py", line 23, in <module>
File "c:\users\user\appdata\local\temp\tmp41xybl\pip.zip\pip\locations.py", line 120, in <module>
File "c:\users\user\appdata\local\temp\tmp41xybl\pip.zip\pip\utils\appdirs.py", line 150, in site_config_dirs
File "c:\users\user\appdata\local\temp\tmp41xybl\pip.zip\pip\utils\appdirs.py", line 191, in _get_win_folder_from_registry
WindowsError: [Error 2] The system cannot find the file specified`
I really don't know what I'm doing wrong, and there aren't any helpful answers online. Can someone help me understand what I need to do to fix this and get pip installed? Thanks.