Consider this python test file main.py
# main.py
from paraview.simple import *
def paraTest():
Cone()
SetProperties(Resolution=32)
Shrink()
Show()
Render()
if __name__ == '__main__':
paraTest()
that depends on paraview package installed from Anaconda using
conda install -c conda-forge paraview
according to
https://anaconda.org/conda-forge/paraview.
The program works as expected when directly run with python.
The Problem
When I package it using pyinstaller with the Terminal command
pyinstaller main.py, and then run the executable, I get the following error:
Traceback (most recent call last):
File "paraview/__init__.py", line 161, in <module>
ImportError: Failed to load vtkRemotingCore: No module named paraview.modules.vtkPVVTKExtensionsCore
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "main.py", line 1, in <module>
from paraview.simple import *
File "PyInstaller/loader/pyimod03_importers.py", line 546, in exec_module
File "paraview/__init__.py", line 163, in <module>
ModuleNotFoundError: No module named '_paraview_modules_static'
[14370] Failed to execute script 'main' due to unhandled exception!
My Attempts
I understand there may be some modules not recognized and included by pyinstaller, so I copied all module files from {miniconda_root}/miniconda3/lib/python3.9/site-packages/paraview/modules to my package {MyPackage_root}/dist/main/paraview/modules, but the same error persists.
Environment info
MacOS 11.2 (Big Sur)
python==3.9
paraview==5.9.1
pyinstaller==4.4
Thanks in advance!
Related
I am using
pyarmor pack --clean -e "--onefile" main.py
After Running the Compiled .py file I get the following error:
Traceback (most recent call last):
File "<dist \obf\ Builder19948 .py>", line 3, in <module>
File "<frozen Builder19948> ", line 7, in <module
ModuleNotFoundError: No module named 'keyboard"
[12560] Failed to execute script *Builder19948 due to unhandled exception!
I have imported keyboard module in my code, so how can I Fix this?
thanks in advance
I've tried compiling a Python program on my Mac, and all went well. I then moved to ubuntu, and can't even compile a hello world correctly:
I wrote the simplest hello world:
print("hello world")
then tried compiling it using:
pyinstaller --onefile hello.py
everything seemed to be fine, until I tried running it:
dist/hello
and got the following traceback:
[2886] mod is NULL - structTraceback (most recent call last):
File "/usr/lib/python3.6/struct.py", line 13, in <module>
from _struct import *
ModuleNotFoundError: No module named '_struct'
[2886] mod is NULL - pyimod02_archiveTraceback (most recent call last):
File "/usr/local/lib/python3.6/dist-packages/PyInstaller-3.4.dev0+g5f91905-py3.6.egg/PyInstaller/loader/pyimod02_archive.py", line 28, in <module>
import struct
ModuleNotFoundError: No module named 'struct'
[2886] mod is NULL - pyimod03_importersTraceback (most recent call last):
File "/usr/local/lib/python3.6/dist-packages/PyInstaller-3.4.dev0+g5f91905-py3.6.egg/PyInstaller/loader/pyimod03_importers.py", line 24, in <module>
from pyimod02_archive import ArchiveReadError, ZlibArchiveReader
ModuleNotFoundError: No module named 'pyimod02_archive'
Traceback (most recent call last):
File "PyInstaller-3.4.dev0+g5f91905-py3.6.egg/PyInstaller/loader/pyiboot01_bootstrap.py", line 15, in <module>
ModuleNotFoundError: No module named 'pyimod03_importers'
[2886] Failed to execute script pyiboot01_bootstrap
It seems weird as I don't import any modules explicitly, but I followed a suggestion to add the missing modules in hello.spec under hiddenimports. so I added
hiddenimports=['_struct', 'struct', 'pyimod02_archive','pyimod03_importers']
and tried compiling with
pyinstaller --onefile hello.spec
but got the exact same error as before when I tried to run the exe file.
What am I doing wrong?
I'm using pyinstaller 3.4.dev0+g5f91905 with Python 3.6.2 on Ubuntu 16.04.3
I just created an exe from python script and when I tried to run it, it did not show up.
Then, I tried to run it from cmd and I got ImportError below:
Traceback (most recent call last):
File "tkintertest2.py", line 17, in <module>
File "Lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line
389, in load_module
File "MySQL.py", line 1, in <module>
ImportError: No module named mysql.connector
Failed to execute script tkintertest2
How to solve this? I have installed mysql.connector using both pip install and conda install.
According to the pyinstaller docs here, pyinstaller is not finding the python module, so explicitly include it like so:
pyinstaller --hidden-import mysql.connector myscript.py
I am running Mac OS 10.10.5. and Python 3 and XCode 7.2.1. I installed SciKit-Learn and all of its dependencies with pip (PyCharm) and I am getting this error when I try to use the package. I tried it on another computer also running 10.10.5 and didn't get the error. Here is the full error message:
/Library/Frameworks/Python.framework/Versions/3.5/bin/python3.5 /Users/jonathankogan/PycharmProjects/Test/test.py
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/sklearn/__check_build/__init__.py", line 44, in <module>
from ._check_build import check_build
ImportError: dynamic module does not define module export function (PyInit__check_build)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/jonathankogan/PycharmProjects/Test/test.py", line 2, in <module>
from sklearn import datasets
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/sklearn/__init__.py", line 56, in <module>
from . import __check_build
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/sklearn/__check_build/__init__.py", line 46, in <module>
raise_build_error(e)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/sklearn/__check_build/__init__.py", line 41, in raise_build_error
%s""" % (e, local_dir, ''.join(dir_content).strip(), msg))
ImportError: dynamic module does not define module export function (PyInit__check_build)
___________________________________________________________________________
Contents of /Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/sklearn/__check_build:
__init__.py __pycache__ _check_build.cpython-35m-darwin.so
setup.py
___________________________________________________________________________
It seems that scikit-learn has not been built correctly.
If you have installed scikit-learn from source, please do not forget
to build the package before using it: run `python setup.py install` or
`make` in the source directory.
If you have used an installer, please check that it is suited for your
Python version, your operating system and your platform.
tox runs my Python 2.7 tests, but fails for Python 3.4. It gives an "Invocation failed" message. Excerpts:
py34 create: /home/josh/code/ezoutlet/.tox/py34
ERROR: invocation failed (exit code 1), logfile: /home/josh/code/ezoutlet/.tox/py34/log/py34-0.log
ERROR: actionid: py34
msg: getenv
cmdargs: ['/usr/bin/python', '-m', 'virtualenv', '--python', '/usr/bin/python3.4', 'py34']
And later
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/virtualenv.py", line 8, in <module>
import base64
File "/usr/lib/python3.4/base64.py", line 9, in <module>
import re
File "/usr/lib/python3.4/re.py", line 336, in <module>
import copyreg
File "/usr/local/lib/python2.7/dist-packages/copyreg/__init__.py", line 7, in <module>
raise ImportError('This package should not be accessible on Python 3. '
ImportError: This package should not be accessible on Python 3. Either you are trying to run from the python-future src folder or your installation of python-future is corrupted.
Error in sys.excepthook:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 53, in apport_excepthook
if not enabled():
File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 24, in enabled
import re
File "/usr/lib/python3.4/re.py", line 336, in <module>
import copyreg
File "/usr/local/lib/python2.7/dist-packages/copyreg/__init__.py", line 7, in <module>
raise ImportError('This package should not be accessible on Python 3. '
ImportError: This package should not be accessible on Python 3. Either you are trying to run from the python-future src folder or your installation of python-future is corrupted.
Original exception was:
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/virtualenv.py", line 8, in <module>
import base64
File "/usr/lib/python3.4/base64.py", line 9, in <module>
import re
File "/usr/lib/python3.4/re.py", line 336, in <module>
import copyreg
File "/usr/local/lib/python2.7/dist-packages/copyreg/__init__.py", line 7, in <module>
raise ImportError('This package should not be accessible on Python 3. '
ImportError: This package should not be accessible on Python 3. Either you are trying to run from the python-future src folder or your installation of python-future is corrupted.
Running virtualenv with interpreter /usr/bin/python3.4
ERROR: InvocationError: /usr/bin/python -m virtualenv --python /usr/bin/python3.4 py34 (see /home/josh/code/ezoutlet/.tox/py34/log/py34-0.log)
You need to look at the details of the error message. Notice the command that failed (from the first excerpt):
cmdargs: ['/usr/bin/python', '-m', 'virtualenv', '--python', '/usr/bin/python3.4', 'py34']
You can run this manually with:
/usr/bin/python -m virtualenv --python /usr/bin/python3.4 py34
Assuming you see the same error, your issue is with virtualenv rather than tox.
I reviewed the virtualenv help page and it seems like this should work. Faced with a possible bug, a good first step is to upgrade Python, virtualenv, or other libraries.
In my case, upgrading virtualenv was the solution:
pip install --upgrade virtualenv
Interestingly, this solution worked on both Windows and Linux. Most likely, there was a bug fix between when I got virtualenv and the latest release.