Pyinstaller fails to import site module in python3 on MacOSX - python-3.x

I am trying to package (freeze) a python3 application using pyinstaller (ver. 3.3.1)
After running pyinstaller my_script.py it fails with a list of import errors, the first of which is the following:
292 INFO: checking Analysis
292 INFO: Building Analysis because out00-Analysis.toc is non existent
292 INFO: Initializing module dependency graph...
298 INFO: Initializing module graph hooks...
299 INFO: Analyzing base_library.zip ...
Failed to import the site module
Traceback (most recent call last):
File "/usr/local/Cellar/python3/3.6.4_2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site.py", line 544, in <module>
main()
...
...and continues with a longer list of import errors
It could be it is a problem with my python3 configuration, or pyinstaller spec file.
I am using at present the default pyinstaller spec file.
Following is the system I am testing:
MacOSX 10.13.3 (High Sierra)
Python 3.6.4 (installed using brew)
pyinstaller 3.3.1 (installed using pip)
Thanks a lot for all your kind help.

Mac 10.13.3
Python 3.6.4
Pyinstaller 3.3.1
I had this problem and my resolution was to:
pip3 uninstall enum34
as per Why Python 3.6.1 throws AttributeError: module 'enum' has no attribute 'IntFlag'?

Related

No module named 'torch' or 'torch.C'

Would appreciate an explanation like I'm 5 simply because I have checked all relevant answers and none have helped.
I have installed Python.
I have installed Pycharm.
I have installed Anaconda.
I have installed Microsoft Visual Studio.
I have not installed the CUDA toolkit.
In Anaconda, I used the commands mentioned on Pytorch.org (06/05/18)
conda install pytorch -c pytorch
pip3 install torchvision
Both have downloaded and installed properly, and I can find them in my Users/Anaconda3/pkgs folder, which I have added to the Python path.
Trying to enter
import torch
in the Python console proved unfruitful - always giving me the same error,
No module named 'torch'
I have also tried using the Project Interpreter to download the Pytorch package. It worked for numpy (sanity check, I suppose) but told me to go to Pytorch.org when I tried to install the "pytorch" or "torch" packages.
When trying to use the console in PyCharm, pip3 install codes (thinking maybe I need to save the packages into my current project, rather than in the Anaconda folder) return me an error message saying
torch-0.4.0-cp35-cp35m-win_amd64.whl is not a supported wheel on this
platform.
The same message shows no matter if I try downloading the CUDA version or not, or if I choose to use the 3.5 or 3.6 Python link (I have Python 3.7)
Currently the closest I have gotten to a solution, is manually copying the "torch" and "torch-0.4.0-py3.6.egg-info" folders into my current Project's lib folder.
However, when I do that and then run "import torch" I received the following error:
Traceback (most recent call last):
File "", line 1, in
File "C:\Program Files\JetBrains\PyCharm Community Edition 2018.1.2\helpers\pydev_pydev_bundle\pydev_import_hook.py", line 19, in do_import
module = self._system_import(name, *args, **kwargs) File "C:\Users\Michael\PycharmProjects\Pytorch_2\venv\lib\site-packages\torch__init__.py",
line 78, in
from torch._C import *
File "C:\Program Files\JetBrains\PyCharm Community Edition 2018.1.2\helpers\pydev_pydev_bundle\pydev_import_hook.py", line 19, in do_import
module = self._system_import(name, *args, **kwargs) ModuleNotFoundError: No module named 'torch._C'
pip uninstall torch
then
pip install torch worked for me.
I encountered the same problem because I updated my python from 3.5 to 3.6 yesterday. I think the connection between Pytorch and Python is not correctly changed. Thus, I installed Pytorch for 3.6 again and the problem is solved.
Check the install command line here[1].

PyInstaller: .exe runs, throws an exception trying to dynamically load a module

I've written a Python program using phonenumbers. On my Windows system with Python 3.6.4 installed, it works as intended, but I'd like to redistribute it as a standalone Windows executable, so I've run PyInstaller on it to get a Windows executable.
However, I'm hitting two barriers: first, I'm a rank beginner with Python, and the details of the Python environment are still a slog for me.
Second, the .EXE program throws an exception trying to dynamically load a module (country data to parse a number, FWIW), and I haven't managed to figure out how to incorporate dynamically loaded modules into a standalone executable. (The failure was in a "try" clause, so it took me a while to locate it.) My own system has all the memory I'd need to pre-load all the needed dynamically loaded modules up front, so I'd prefer to do things that way.
Solutions, suggestions, hints, thoughts? A fully-worked example somewhere? Perhaps I'm failing to understand an answer already in the forum, but that would be because I'm a beginner, so I'd appreciate some clarity.
____
Thanks for your notes. To answer #adnan-y and #apogalacticon: I've made a simple test case. Here are the program source, output from running the script, the pyinstaller run on the program (with no prior build directories or files), its warning file, the result of running the executable, and the location of the file that the Python script correctly loads and correctly uses on the sample input.
The source program Parse-failure.py
import phonenumbers
Number = "+17034820623"
print("The unprocessed number is <%s>" % (Number))
Parsed_Number = phonenumbers.parse(Number)
print("The parsed number is <%s>" % (Parsed_Number))
Output from running Parse-failure.py
$ Parse-failure.py
The unprocessed number is <+17034820623>
The parsed number is <Country Code: 1 National Number: 7034820623>
Pyinstaller run
$ PyInstaller --onefile Parse-failure.py
94 INFO: PyInstaller: 3.4.dev0
94 INFO: Python: 3.6.4
94 INFO: Platform: Windows-7-6.1.7601-SP1
95 INFO: wrote N:\PPR\Parse-failure.spec
96 INFO: UPX is not available.
97 INFO: Extending PYTHONPATH with paths
['f:\\Dems\\PhoneCheck', 'f:\\Dems\\PhoneCheck']
98 INFO: checking Analysis
98 INFO: Building Analysis because out00-Analysis.toc is non existent
98 INFO: Initializing module dependency graph...
99 INFO: Initializing module graph hooks...
101 INFO: Analyzing base_library.zip ...
5155 INFO: running Analysis out00-Analysis.toc
5157 INFO: Adding Microsoft.Windows.Common-Controls to dependent assemblies of final executable
required by d:\python36\python.exe
6356 INFO: Caching module hooks...
6363 INFO: Analyzing N:\PPR\Parse-failure.py
6738 INFO: Loading module hooks...
6739 INFO: Loading module hook "hook-encodings.py"...
6843 INFO: Loading module hook "hook-pydoc.py"...
6845 INFO: Loading module hook "hook-xml.py"...
7238 INFO: Looking for ctypes DLLs
7238 INFO: Analyzing run-time hooks ...
7247 INFO: Looking for dynamic libraries
7372 INFO: Looking for eggs
7372 INFO: Using Python library d:\python36\python36.dll
7372 INFO: Found binding redirects:
[]
7375 INFO: Warnings written to N:\PPR\build\Parse-failure\warnParse-failure.txt
7461 INFO: Graph cross-reference written to N:\PPR\build\Parse-failure\xref-Parse-failure.html
7471 INFO: checking PYZ
7471 INFO: Building PYZ because out00-PYZ.toc is non existent
7471 INFO: Building PYZ (ZlibArchive) N:\PPR\build\Parse-failure\out00-PYZ.pyz
8292 INFO: Building PYZ (ZlibArchive) N:\PPR\build\Parse-failure\out00-PYZ.pyz completed successfully.
8302 INFO: checking PKG
8302 INFO: Building PKG because out00-PKG.toc is non existent
8302 INFO: Building PKG (CArchive) out00-PKG.pkg
10218 INFO: Building PKG (CArchive) out00-PKG.pkg completed successfully.
10222 INFO: Bootloader d:\python36\lib\site-packages\PyInstaller\bootloader\Windows-64bit\run.exe
10222 INFO: checking EXE
10222 INFO: Building EXE because out00-EXE.toc is non existent
10222 INFO: Building EXE from out00-EXE.toc
10222 INFO: Appending archive to EXE N:\PPR\dist\Parse-failure.exe
10228 INFO: Building EXE from out00-EXE.toc completed successfully.
Warnings file build\PCS\warnParse-failure.txt
missing module named resource - imported by posix, n:\PPR\Parse-failure.py
missing module named posix - imported by os, n:\PPR\Parse-failure.py
missing module named _posixsubprocess - imported by subprocess, n:\PPR\Parse-failure.py
missing module named org - imported by pickle, n:\PPR\Parse-failure.py
missing module named readline - imported by cmd, code, pdb, n:\PPR\Parse-failure.py
excluded module named _frozen_importlib - imported by importlib, importlib.abc, n:\PPR\Parse-failure.py
missing module named _frozen_importlib_external - imported by importlib._bootstrap, importlib, importlib.abc, n:\PPR\Parse-failure.py
missing module named _winreg - imported by platform, n:\PPR\Parse-failure.py
missing module named _scproxy - imported by urllib.request
missing module named java - imported by platform, n:\PPR\Parse-failure.py
missing module named 'java.lang' - imported by platform, n:\PPR\Parse-failure.py, xml.sax._exceptions
missing module named vms_lib - imported by platform, n:\PPR\Parse-failure.py
missing module named termios - imported by tty, n:\PPR\Parse-failure.py, getpass
missing module named grp - imported by shutil, tarfile, n:\PPR\Parse-failure.py
missing module named pwd - imported by posixpath, shutil, tarfile, http.server, webbrowser, n:\PPR\Parse-failure.py, netrc, getpass
missing module named _dummy_threading - imported by dummy_threading, n:\PPR\Parse-failure.py
missing module named 'org.python' - imported by copy, n:\PPR\Parse-failure.py, xml.sax
Run the executable
$ dist\Parse-failure.exe
[1364] Failed to execute script Parse-failure
The unprocessed number is <+17034820623>
Traceback (most recent call last):
File "Parse-failure.py", line 7, in <module>
Parsed_Number = phonenumbers.parse(Number)
File "site-packages\phonenumbers\phonenumberutil.py", line 2835, in parse
File "site-packages\phonenumbers\phonemetadata.py", line 294, in metadata_for_region_or_calling_code
File "site-packages\phonenumbers\phonemetadata.py", line 267, in metadata_for_region
File "site-packages\phonenumbers\data\__init__.py", line 23, in _load_region
ModuleNotFoundError: No module named 'phonenumbers.data.region_US'
The location of ...region_US
D:\Python36\Lib\site-packages\phonenumbers\data\region_US.py

python 3.5.3 kivy error

I am developing a small app in python using Kivy for the GUI. So far I have been working with Pycharm and 3.4.3 which works just fine. I have had to upgrade to 3.5.3 and now when I run the script it fails with the following error:
File "/usr/lib/python3/dist-packages/kivy/event.py", line 8, in <module>
import kivy._event
ImportError: No module named 'kivy._event'
Is this a python 3.5.3 kivy 1.9.1 compatibility problem?

Pyinstaller --onefile ImportError: No module named 'win32api'

Problem statement:
I can't seem to run
'PyInstaller --onefile myfile.py'
on a file containing
import wmi
It cannot find win32api. I get a popup warning saying python has stopped etc. My console says "ImportError: No module named 'win32api'". I can run 'import win32api', 'import win32com', and 'import WMI' in python directly in the same environment without issue. I fundamentally don't understand what is wrong here.
Error message:
3469 INFO: Loading module hook "hook-pywintypes.py"...
Fatal Python error: Py_Initialize: can't initialize sys standard streams
ImportError: No module named 'win32api'
I have tried:
PyInstaller - ImportError: No module named win32api - 'import os' works fine for PyInstaller and runs fine in python.
No module named 'win32api' - Not very helpful
How to install pywin32 module in windows 7 - This is where I got the SF link (python3.5 amd64 pywin32 version)
ImportError: no module named win32api -
I thought it might be a path thing, but my installation appears to be in the correct place: "C:\Users\myuser\AppData\Local\Continuum\Anaconda3\pkgs\pywin32-220-py35_2\Lib\site-packages\win32"
I can run 'PyInstaller --onefile myscript.py' on other files, and have without issue as long as they don't use the wmi module.
I looked at the win32com _init__.py line 5 where it's messing up and it's just an import statement for win32api.
System:
Windows 7 x64, Python 3.5.3 64bit, Anaconda 4.3.14 64bit, using pyinstaller 3.2.3 (recommended by this thread), with pywin32 220 (with sourceforge download [I know, I tried pip, conda, and easy_install]) and I'm running it in cmder as an admin.
In my case, I couldn't use the module in the python shell, even if original one could. When I execute python shell as an administrator option, it was solved. Try it with administrator execution. I used python version 3.5.2 with windows x64bits.
I face this problem but I install ---> pip install pypiwin32 to solve my problems

Import error with tweepy

I am new to python and anaconda.
I am using Python 3.5.1 |Anaconda 4.1.0 (64-bit)| (default, Jun 15 2016, 15:29:36) [MSC v.1900 64 bit (AMD64)]. The version of the notebook server is 4.2.1.
When I issue the following command
import tweepy
it runs successfully.
But when I try to run the following command
%%file test.py
import tweepy
Its getting save as test.py
When I issue the following command
!python test.py
I am getting the following error.
Traceback (most recent call last):
File "test.py", line 2, in <module>
import tweepy
ImportError: No module named tweepy
I am able to see tweepy folders in my anaconda installation directory
D:\Anaconda3\Lib\site-packages
tweepy-3.5.0.dist-info
tweepy
Where am I going wrong. Kindly guide me.
Thanks.
Since I have multiple versions of python installed on my machine this issue exists. So when I point to the correct directory of my python installation, its working fine.

Resources