I'm using pyinstaller on one of my scripts but I'm getting an error on the line of code I wrote:
from statsmodels.stats.diagnostic import kstest_normal
The command I used was
pyinstaller fitness_of_statistical_tests.py --hidden-import=scipy.linalg.cython_blas --hidden-import=scipy.linalg.cython_lapack
The full error I get is:
Traceback (most recent call last):
File "C:\Python34\lib\site-packages\pandas\__init__.py", line 7, in <module>
from pandas import hashtable, tslib, lib
ImportError: cannot import name 'lib'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<string>", line 9, in <module>
File "C:\Python34\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 311, in load_module
exec(bytecode, module.__dict__)
File "D:\SEDS\gahndiwashingtonmethod\fitness_of_statistical_tests_view.py", line 11, in <module>
from statsmodels.stats.diagnostic import kstest_normal
File "C:\Python34\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 311, in load_module
exec(bytecode, module.__dict__)
File "C:\Python34\lib\site-packages\statsmodels\__init__.py", line 8, in <module>
from .tools.sm_exceptions import (ConvergenceWarning, CacheWriteWarning,
File "C:\Python34\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 311, in load_module
exec(bytecode, module.__dict__)
File "C:\Python34\lib\site-packages\statsmodels\tools\__init__.py", line 1, in <module>
from .tools import add_constant, categorical
File "C:\Python34\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 311, in load_module
exec(bytecode, module.__dict__)
File "C:\Python34\lib\site-packages\statsmodels\tools\tools.py", line 11, in <module>
from statsmodels.datasets import webuse
File "C:\Python34\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 311, in load_module
exec(bytecode, module.__dict__)
File "C:\Python34\lib\site-packages\statsmodels\datasets\__init__.py", line 5, in <module>
from . import (anes96, cancer, committee, ccard, copper, cpunish, elnino,
File "C:\Python34\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 311, in load_module
exec(bytecode, module.__dict__)
File "C:\Python34\lib\site-packages\statsmodels\datasets\anes96\__init__.py", line 1, in <module>
from .data import *
File "C:\Python34\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 311, in load_module
exec(bytecode, module.__dict__)
File "C:\Python34\lib\site-packages\statsmodels\datasets\anes96\data.py", line 90, in <module>
from statsmodels.datasets import utils as du
File "C:\Python34\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 311, in load_module
exec(bytecode, module.__dict__)
File "C:\Python34\lib\site-packages\statsmodels\datasets\utils.py", line 13, in <module>
from pandas import read_csv, DataFrame, Index
File "C:\Python34\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 311, in load_module
exec(bytecode, module.__dict__)
File "C:\Python34\lib\site-packages\pandas\__init__.py", line 13, in <module>
"extensions first.".format(module))
ImportError: C extension: 'lib' 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.
fitness_of_statistical_tests returned -1
All of these imports work in the python interpreter, but it's just when I run the exe from PyInstaller that all this stuff breaks.
Related
I am new at linux(ubuntu 20.04), facing problem to installation of pip apt-pkg as following,
curl -sS https://bootstrap.pypa.io/get-pip.py | python3.10
Traceback (most recent call last):
File "/usr/lib/command-not-found", line 28, in
from CommandNotFound import CommandNotFound
File "/usr/lib/python3/dist-packages/CommandNotFound/CommandNotFound.py", line 19, in
from CommandNotFound.db.db import SqliteDatabase
File "/usr/lib/python3/dist-packages/CommandNotFound/db/db.py", line 5, in
import apt_pkg
ModuleNotFoundError: No module named 'apt_pkg'
pradeep#pradeep-Vostro-15-3568:~$ pip install pip
Traceback (most recent call last):
File "/usr/bin/pip", line 11, in
load_entry_point('pip==20.0.2', 'console_scripts', 'pip')()
File "/usr/lib/python3/dist-packages/pip/_internal/cli/main.py", line 73, in main
command = create_command(cmd_name, isolated=("--isolated" in cmd_args))
File "/usr/lib/python3/dist-packages/pip/_internal/commands/init.py", line 96, in create_command
module = importlib.import_module(module_path)
File "/usr/lib/python3.10/importlib/init.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 1050, in _gcd_import
File "", line 1027, in _find_and_load
File "", line 1006, in _find_and_load_unlocked
File "", line 688, in _load_unlocked
File "", line 883, in exec_module
File "", line 241, in _call_with_frames_removed
File "/usr/lib/python3/dist-packages/pip/_internal/commands/install.py", line 24, in
from pip._internal.cli.req_command import RequirementCommand
File "/usr/lib/python3/dist-packages/pip/_internal/cli/req_command.py", line 15, in
from pip._internal.index.package_finder import PackageFinder
File "/usr/lib/python3/dist-packages/pip/_internal/index/package_finder.py", line 21, in
from pip._internal.index.collector import parse_links
File "/usr/lib/python3/dist-packages/pip/_internal/index/collector.py", line 12, in
from pip._vendor import html5lib, requests
ImportError: cannot import name 'html5lib' from 'pip._vendor' (/usr/lib/python3/dist-packages/pip/_vendor/init.py)
I'm trying to convert a .py script to an .exe.
I'm using pyinstaller to make it, but I can only open a easy file which contains, for example: print("Hello world"). When I use more lines in the script I can't open it.
I think that the problem is that I'm importing some libraries and I don't know if I have to add them to the .exe when I'm building it.
Here I have the Traceback
File "GraficoTorta.py", line 1, in <module>
File "d:\programs\python\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
exec(bytecode, module.__dict__)
File "site-packages\matplotlib\__init__.py", line 138, in <module>
File "d:\programs\python\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
exec(bytecode, module.__dict__)
File "site-packages\matplotlib\cbook\__init__.py", line 31, in <module>
File "d:\programs\python\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
exec(bytecode, module.__dict__)
File "site-packages\numpy\__init__.py", line 150, in <module>
File "d:\programs\python\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
exec(bytecode, module.__dict__)
File "site-packages\numpy\random\__init__.py", line 180, in <module>
File "mtrand.pyx", line 1, in init numpy.random.mtrand
ModuleNotFoundError: No module named 'numpy.random.common'
[13372] Failed to execute script GraficoTorta
import matplotlib.pyplot as plt; plt.rcdefaults()
import numpy as np
import matplotlib.pyplot as plt
objects = ('Python', 'C++', 'Java', 'Perl', 'Scala', 'Lisp')
y_pos = np.arange(len(objects))
performance = [10,8,6,4,2,1]
plt.bar(y_pos, performance, align='center', alpha=0.5)
plt.xticks(y_pos, objects)
plt.ylabel('Usage')
plt.title('Programming language usage')
plt.show()
i have made a exe file from a python file which have multiple import from our own files and have package sklearn, xgboost, pandas and other sklaern packages. during exe preparation thier is no error while running it it throw error
Traceback (most recent call last):
File "probability_score_engine.py", line 16, in <module>
import sklearn.ensemble
File "C:\Users\ShubhamSingh\PycharmProjects\cfna_scoring\venv\lib\site-
packages\PyInstaller\loader\pyimod03_importers.py", line 627, in
exec_module
exec(bytecode, module.__dict__)
File "lib\site-packages\sklearn\__init__.py", line 76, in <module>
File "C:\Users\ShubhamSingh\PycharmProjects\cfna_scoring\venv\lib\site-
packages\PyInstaller\loader\pyimod03_importers.py", line 627, in
exec_module
exec(bytecode, module.__dict__)
File "lib\site-packages\sklearn\base.py", line 16, in <module>
File "C:\Users\ShubhamSingh\PycharmProjects\cfna_scoring\venv\lib\site-
packages\PyInstaller\loader\pyimod03_importers.py", line 627, in
exec_module
exec(bytecode, module.__dict__)
File "lib\site-packages\sklearn\utils\__init__.py", line 20, in <module>
File "C:\Users\ShubhamSingh\PycharmProjects\cfna_scoring\venv\lib\site-
packages\PyInstaller\loader\pyimod03_importers.py", line 627, in
exec_module
exec(bytecode, module.__dict__)
File "lib\site-packages\sklearn\utils\validation.py", line 21, in
<module>
File "C:\Users\ShubhamSingh\PycharmProjects\cfna_scoring\venv\lib\site-
packages\PyInstaller\loader\pyimod03_importers.py", line 627, in
exec_module
exec(bytecode, module.__dict__)
File "lib\site-packages\sklearn\utils\fixes.py", line 18, in <module>
File "C:\Users\ShubhamSingh\PycharmProjects\cfna_scoring\venv\lib\site-
packages\PyInstaller\loader\pyimod03_importers.py", line 627, in
exec_module
exec(bytecode, module.__dict__)
File "lib\site-packages\scipy\sparse\linalg\__init__.py", line 113, in
<module>
File "C:\Users\ShubhamSingh\PycharmProjects\cfna_scoring\venv\lib\site-
packages\PyInstaller\loader\pyimod03_importers.py", line 627, in
exec_module
exec(bytecode, module.__dict__)
File "lib\site-packages\scipy\sparse\linalg\isolve\__init__.py", line 6,
in <module>
File "C:\Users\ShubhamSingh\PycharmProjects\cfna_scoring\venv\lib\site-
packages\PyInstaller\loader\pyimod03_importers.py", line 627, in
exec_module
exec(bytecode, module.__dict__)
File "lib\site-packages\scipy\sparse\linalg\isolve\iterative.py", line 10,
in <module>
ImportError: DLL load failed: The specified module could not be found.
[10668] Failed to execute script probability_score_engine
i have use add data for xgboost when it throw error in not finding dll files for xgboost but it throw error for sklearn. i have made a exe of one file but that file call other other python files function by using import.
Both sklearn and xgboost needs special care when using with Pyinstaller. I'm skipping importing xgboost but here is a useful answer about using it with Pyinstaller.
It seems that when you add xgboostPyinstaller can't handle some modules like scipy. A simple approach is to add the whole scipy in Python's sit-package to your executable as data. So edit your spec file and add this after Analysis:
# -*- mode: python -*-
block_cipher = None
a = Analysis(
datas=[('./env/xgboost/*', 'xgboost/'), ('./env/Lib/site-packages/xgboost/VERSION', 'xgboost/')],
...
)
# add here
a.datas += Tree('<path_to_scipy_in_python_dir>', prefix='scipy')
...
pyz = PYZ(a.pure, a.zipped_data,
cipher=block_cipher)
And finally, generate your executable with pyinstaller script.spec.
With both pyinstaller and cxfreeze I get this error:
C:\Users\asdasda\Desktop\dist>test.exe
Traceback (most recent call last):
File "site-packages\requests\packages\__init__.py", line 27, in <module>
File "c:\python34\lib\site-packages\PyInstaller\loader\pyimod03_importers.py",
line 389, in load_module
exec(bytecode, module.__dict__)
File "site-packages\requests\packages\urllib3\__init__.py", line 8, in <module
>
File "c:\python34\lib\site-packages\PyInstaller\loader\pyimod03_importers.py",
line 389, in load_module
exec(bytecode, module.__dict__)
File "site-packages\requests\packages\urllib3\connectionpool.py", line 28, in
<module>
File "site-packages\requests\packages\urllib3\packages\six.py", line 203, in l
oad_module
File "site-packages\requests\packages\urllib3\packages\six.py", line 115, in _
resolve
File "site-packages\requests\packages\urllib3\packages\six.py", line 82, in _i
mport_module
ImportError: No module named 'queue'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "test.py", line 1, in <module>
File "c:\python34\lib\site-packages\PyInstaller\loader\pyimod03_importers.py",
line 389, in load_module
exec(bytecode, module.__dict__)
File "site-packages\requests\__init__.py", line 63, in <module>
File "c:\python34\lib\site-packages\PyInstaller\loader\pyimod03_importers.py",
line 389, in load_module
exec(bytecode, module.__dict__)
File "site-packages\requests\utils.py", line 24, in <module>
File "c:\python34\lib\site-packages\PyInstaller\loader\pyimod03_importers.py",
line 389, in load_module
exec(bytecode, module.__dict__)
File "site-packages\requests\_internal_utils.py", line 11, in <module>
File "c:\python34\lib\site-packages\PyInstaller\loader\pyimod03_importers.py",
line 389, in load_module
exec(bytecode, module.__dict__)
File "site-packages\requests\compat.py", line 11, in <module>
File "c:\python34\lib\site-packages\PyInstaller\loader\pyimod03_importers.py",
line 389, in load_module
exec(bytecode, module.__dict__)
File "site-packages\requests\packages\__init__.py", line 29, in <module>
File "c:\python34\lib\site-packages\PyInstaller\loader\pyimod03_importers.py",
line 389, in load_module
exec(bytecode, module.__dict__)
File "site-packages\urllib3\__init__.py", line 8, in <module>
File "c:\python34\lib\site-packages\PyInstaller\loader\pyimod03_importers.py",
line 389, in load_module
exec(bytecode, module.__dict__)
File "site-packages\urllib3\connectionpool.py", line 28, in <module>
File "site-packages\urllib3\packages\six.py", line 203, in load_module
File "site-packages\urllib3\packages\six.py", line 115, in _resolve
File "site-packages\urllib3\packages\six.py", line 82, in _import_module
ImportError: No module named 'queue'
Failed to execute script test
I tried compiling the exact same script that I compiled a few months ago (It worked that time) but now I get the error which made me think that it was a python version error, so I switched from 3.4.4 to 3.5.2 but that didn't help.
I also tried different versions of pyinstaller and cxfreeze but all gave me the same error.
Please help me regarding this issue. Thanks in Advance.
cxfreeze seems to not support the most recent version requests. This error was fixed for me by downgrading to v2.11.1
pip install requests==2.11.1
Sometimes imports are not detected. I had the same problem with the queue module.
Adding the queue module to the hidden imports in the .spec file solved the problem for me (PyInstaller):
a = Analysis(...,
hiddenimports=['queue'],
...)
source
I have a simple python script that imports couchbase module on Ubuntu 14.04:
$ cat test.py
from couchbase import Couchbase
print 'module _libcouchbase found'
Running from interpreter works fine:
$ python test.py
module _libcouchbase found
Created an executable:
$ pyinstaller test.py
Running the executable throws an error of unable to import _libcouchbase module:
$ ./dist/test/test
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/PyInstaller/loader/pyi_importers.py", line 270, in load_module
exec(bytecode, module.__dict__)
File "/home/subba/cb/build/cb/out00-PYZ.pyz/mycouch", line 28, in <module>
File "/usr/local/lib/python2.7/dist-packages/PyInstaller/loader/pyi_importers.py", line 270, in load_module
exec(bytecode, module.__dict__)
File "/home/subba/cb/build/cb/out00-PYZ.pyz/couchbase", line 28, in <module>
File "/usr/local/lib/python2.7/dist-packages/PyInstaller/loader/pyi_importers.py", line 270, in load_module
exec(bytecode, module.__dict__)
File "/home/subba/cb/build/cb/out00-PYZ.pyz/couchbase.user_constants", line 21, in <module>
File "/usr/local/lib/python2.7/dist-packages/PyInstaller/loader/pyi_importers.py", line 270, in load_module
exec(bytecode, module.__dict__)
File "/home/subba/cb/build/cb/out00-PYZ.pyz/couchbase._bootstrap", line 34, in <module>
File "/usr/local/lib/python2.7/dist-packages/PyInstaller/loader/pyi_importers.py", line 270, in load_module
exec(bytecode, module.__dict__)
File "/home/subba/cb/build/cb/out00-PYZ.pyz/couchbase.exceptions", line 18, in <module>
ImportError: No module named _libcouchbase
It seems very mysterious. Thanks for any thoughts on why this happens!
Try creating a file called hook-couchbase.py with the following content:
import os
import glob
import itertools
try:
# PY_EXTENSION_SUFFIXES is unavailable in older versions
from PyInstaller.hooks.hookutils import PY_EXTENSION_SUFFIXES
except ImportError:
try:
from importlib.machinery import EXTENSION_SUFFIXES as PY_EXTENSION_SUFFIXES
except ImportError:
import imp
PY_EXTENSION_SUFFIXES = set([f[0] for f in imp.get_suffixes()
if f[2] == imp.C_EXTENSION])
def hook(mod):
module_directory = os.path.dirname(mod.__file__)
bundled = []
for libname, ext in itertools.product(('libcouchbase', '_libcouchbase'),
PY_EXTENSION_SUFFIXES):
bundled.extend(glob.glob(os.path.join(module_directory, libname + ext)))
for f in bundled:
name = os.path.join('couchbase', os.path.basename(f))
if hasattr(mod, 'pyinstaller_binaries'):
mod.pyinstaller_binaries.append((name, f, 'BINARY'))
else: # mod.pyinstaller_binaries is unavailable in older versions
mod.binaries.append((name, f, 'BINARY'))
return mod
When building, supply the path to the directory in which you placed the file as a value to the --additional-hooks-dir argument, as follows:
--additional-hooks-dir=<path_to_directory_of_hook_file>