I am trying to wrap a Python script into an exe using PyInstaller (development version) for windows.
The script uses Pandas and I have been running into an error when running the exe.
Traceback (most recent call last): File "site-packages\pandas\__init__.py", line 26, in <module> File "C:\Users\Eddie\Anaconda3\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 631, in exec_module
exec(bytecode, module.__dict__) File "site-packages\pandas\_libs\__init__.py", line 4, in <module> File "C:\Users\Eddie\Anaconda3\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 714, in load_module
module = loader.load_module(fullname) File "pandas/_libs/tslib.pyx", line 1, in init pandas._libs.tslib ModuleNotFoundError: No module named 'pandas._libs.tslibs.timedeltas'
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "G5k Version file Extract (with tkinter).py", line 15, in <module> File "C:\Users\Eddie\Anaconda3\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 631, in exec_module
exec(bytecode, module.__dict__) File "site-packages\pandas\__init__.py", line 35, in <module> ImportError: C extension: No module named 'pandas._libs.tslibs.timedeltas' not built. If you want to import pandas from the source directory, you may need to run 'python setup.py build_ext --inplace --force' to build the C extensions first.
I have tried doing this for programs without pandas and everything was fine.
This is very similar to another question already solved for Python 2, but I am using Python 3 and that solution does not apply the same way due to the changed .spec file format.
Python 3.6
PyInstaller - version 3.3
Pandas - version 0.20.3
PyInstaller 3.3, Pandas 0.21.0, Python 3.6.1.
I was able to solve this thanks to not-yet published/committed fix to PyInstaller, see this and this. AND keeping the ability to pack it into one executable file.
Basically:
Locate PyInstaller folder..\hooks, e.g. C:\Program Files\Python\Lib\site-packages\PyInstaller\hooks.
Create file hook-pandas.py with contents (or anything similar based on your error):
hiddenimports = ['pandas._libs.tslibs.timedeltas']
Save it + I deleted .spec file, build and dist folders just to be sure.
Run pyinstaller -F my_app.py.
This fix should work as long as you don't upgrade or reinstall PyInstaller. So you don't need to edit .spec file.
Maybe they will include the fix sooner for us! :)
I'm not sure it may help you but following the solution on the post you mention work for me with python 3.6 pyinstaller 3.3 and pandas 0.21.0 on windows 7.
So adding this to the spec file just after analysis :
def get_pandas_path():
import pandas
pandas_path = pandas.__path__[0]
return pandas_path
dict_tree = Tree(get_pandas_path(), prefix='pandas', excludes=["*.pyc"])
a.datas += dict_tree
a.binaries = filter(lambda x: 'pandas' not in x[0], a.binaries)
Also my spec file format is the same as the one in the post you mention.
I managed to solve this problem by using the "--hidden-import" flag. Hopefully this can be helpful to someone else that comes across this thread.
pyinstaller --onefile --hidden-import pandas._libs.tslibs.timedeltas myScript.py
If you are using Anaconda, it is highly likely that when you were trying to uninstall some package it has disrupted pandas dependency and unable to get the required script. If you just run conda install pandas you might end up with another error:
module 'pandas' has no attribute 'compat'.
So, try uninstalling and reinstalling pandas conda uninstall pandas, Install it again using conda install pandas this will solve the problem.
On the other hand, if you are not using Anaconda., try doing the same on Command prompt pointing to Python scripts folder pip uninstall pandas & pip install pandas.
Most of the times, this should solve the problem. Just to be cover all the possibilities, don't forget to Launch Spyder from Anaconda after installing pandas.
Related
Though the conversion from *.py- to a standalone *.exe-file via the command "pyinstaller --onefile filename.py" can be completed successfully, the executable itself failes to run
Traceback (most recent call last): File
"venv\Lib\site-packages\PyInstaller\loader\rthooks\pyi_rth_pkgres.py",
line 13, in File
"c:\users\user01\pycharmprojects\api4trd\venv\lib\site-packages\PyInstaller\loader\pyimod03_importers.py",
line 623, in exec_module
exec(bytecode, module.dict) File "lib\site-packages\pkg_resources__init__.py", line 86, in
ModuleNotFoundError: No module named 'pkg_resources.py2_warn' [13560]
Failed to execute script pyi_rth_pkgres
following packages are used
1) math
2) datetime
3) yfinance
Python version: 3.8.1
pyinstaller version: 3.6
OS:W10
Thank you!
You are missing one hidden import in your pyinstaller command. Although earlier version of Python and Pyinstaller never used to give this error, but nevertheless here is the solution
pyinstaller --onefile --hidden-import=pkg_resources.py2_warn filename.py
I have been trying to find a solution to this import error regarding the pandas library when it says no module named "parsing." Every library should be installed correctly from the interpreter and they are all the latest version.
This is what the console returns:
Traceback (most recent call last):
File "C:\Users\shaya\PycharmProjects\NEA\venv\lib\site-packages\pandas\__init__.py", line 26, in <module>
from pandas._libs import (hashtable as _hashtable,
File "C:\Users\shaya\PycharmProjects\NEA\venv\lib\site-packages\pandas\_libs\__init__.py", line 4, in <module>
from .tslib import iNaT, NaT, Timestamp, Timedelta, OutOfBoundsDatetime
File "pandas\_libs\tslibs\conversion.pxd", line 11, in init pandas._libs.tslib
File "pandas\_libs\tslibs\conversion.pyx", line 40, in init pandas._libs.tslibs.conversion
ModuleNotFoundError: No module named 'parsing'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/Users/shaya/PycharmProjects/NEA/Main.py", line 4, in <module>
import pandas_datareader.data as data
File "C:\Users\shaya\PycharmProjects\NEA\venv\lib\site-packages\pandas_datareader\__init__.py", line 2, in <module>
from .data import (DataReader, Options, get_components_yahoo,
File "C:\Users\shaya\PycharmProjects\NEA\venv\lib\site-packages\pandas_datareader\data.py", line 7, in <module>
from pandas_datareader.av.forex import AVForexReader
File "C:\Users\shaya\PycharmProjects\NEA\venv\lib\site-packages\pandas_datareader\av\__init__.py", line 3, in <module>
from pandas_datareader.base import _BaseReader
File "C:\Users\shaya\PycharmProjects\NEA\venv\lib\site-packages\pandas_datareader\base.py", line 7, in <module>
import pandas.compat as compat
File "C:\Users\shaya\PycharmProjects\NEA\venv\lib\site-packages\pandas\__init__.py", line 35, in <module>
"the C extensions first.".format(module))
ImportError: C extension: No module named 'parsing' not built. If you want to import pandas from the source directory, you may need to run 'python setup.py build_ext --inplace --force' to build the C extensions first.
All of the above tracebacks are from PyCharm.
OS: Windows.
I am using pip to install packages
Python version: 3.7.1, panda version: 0.23.4
Do you have python added to path? To test this; open a cmd and type python. If it is on your path, you should see the version of python you are running (Assuming you are using a windows machine). If this is the case, you can simply run the command after you checked this. If not, please navigate to the location where Python is installed, open python.exe and try to run the command python setup.py build_ext --inplace --force
If this doesn't work, you should try to re-install pandas by pip install --upgrade --force-reinstall pandas
If this also fails you could also go rigourous, and simply create a new environment and install pandas there. Sidenote: It is probably better to install pandas by using conda package manager, Pandas has portions of its code written in C to make it run faster. If you tried to install pandas manually you would need to build it.
I had the same problem under the same circumstances. I went through the code of some of the pandas files and saw that there is indeed a module named 'parsing' in the tslib folder of my pandas directory, yet for some reason it's not able to call it. I just reinstalled python and now it's working for me. If you find any other alternative, please let me know.
I want to bundle some python code into a distributable application (.app file) but having trouble with getting opencv and PyQt5 into an application. Either, on the other hand, works fine.
I've stripped all my code and the problem persists. See the following code samples:
# Works absolutely fine
import cv2
print("Hi there opencv v{0} user!".format(cv2.__version__))
# Works absolutely fine
from PyQt5.QtCore import *
print("Qt version {0}".format(QT_VERSION_STR))
# Does not work, see below
import cv2
from PyQt5.QtCore import *
print("Qt version {0}".format(QT_VERSION_STR))
print("opencv version {0}".format(cv2.__version__))
And by "not work", I mean that it bundles without errors (python3.5 -m pyinstaller samplecode.py), but cannot be executed. Instead, the program quits and returns an error:
Traceback (most recent call last):
File "/Users/*****/build/test.py", line 1, in <module>
import cv2
File "/Users/*****/build/PyInstaller/loader/pyimod03_importers.py", line 631, in exec_module
exec(bytecode, module.__dict__)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/cv2/__init__.py", line 9, in <module>
from .cv2 import *
File "/Users/*****/build/PyInstaller/loader/pyimod03_importers.py", line 714, in load_module
module = loader.load_module(fullname)
ImportError: dlopen(/Users/*****/build/test/dist/test/cv2.cv2.so, 2): Symbol not found: __ZN10QByteArray11shared_nullE
Referenced from: /Users/*****/build/test/dist/test/QtTest
Expected in: /Users/*****/build/test/dist/test/QtCore
in /Users/*****/build/test/dist/test/QtTest
[20049] Failed to execute script test
The stars just replace my personal and project folder names.
I tried manually copying the cv2.so file, renaming it to cv2.cv2.so and placing it in the folder. This produces the a slightly different error:
Traceback (most recent call last):
File "/Users/*****/build/test.py", line 1, in <module>
import cv2
File "/Users/*****/build/PyInstaller/loader/pyimod03_importers.py", line 631, in exec_module
exec(bytecode, module.__dict__)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/cv2/__init__.py", line 9, in <module>
from .cv2 import *
File "/Users/*****/build/PyInstaller/loader/pyimod03_importers.py", line 714, in load_module
module = loader.load_module(fullname)
ImportError: dlopen(/Users/*****/build/test/dist/test/cv2.cv2.so, 2): Library not loaded: #loader_path/.dylibs/QtGui
Referenced from: /Users/*****/build/test/dist/test/cv2.cv2.so
Reason: image not found
I've also tried cx_freeze and py2app but couldn't get these to work either. I got the furthest with pyinstaller and its development seems the most active so I prefer using this.
I'm running MacOS 10.12, and have reproduced the error on another clean-install MacBook running the same OS. I'm using Python 3.5.4, PyQt 5.9.1, OpenCV 3.3.0. For PyInstaller I've tried 3.2.1 and the most recent dev.
Can anyone help me understand and solve this error?
Using opencv-python-headless instead solved the problem for me, as mentionned in https://github.com/pyinstaller/pyinstaller/issues/3426.
Uninstall you opencv library, and then
pip install opencv-python-headless
https://pypi.org/project/opencv-python-headless/
I encountered these same errors (using MacOS 10.11.6) when trying to execute my app, which I also built using pyinstaller. I was able to successfully resolve my issue by deprecating opencv and pyinstaller to the following versions:
pip install opencv-python == 3.1.0.4
pip install pyinstaller == 3.3.1
This is not a satisfying solution, but it may be worth trying if you are still struggling with this issue.
I encountered a lot of problems like this, but after some investigating, I solved my problems by creating the virtual environment and install all the libraries I used in the project, then install the OpenCV and pyinstaller on that virtual environment like this:
activate myEnvironment
> pip install opencv-python
> pip install pyinstaller
and then used the pyinstaller in that virtual environment to create the exe file. it bundles all the dlls needed to software.
The situation: I'm trying to install pyside on a project using the PyCharm IDE, however it says that it does not support python 3.5 that is installed by default on ubuntu 16.04. It does support python 2.7, however I'd rather not start a new project using python 2.
What I've done:
So I download python 3.45, extracted it, and I am successful in installing it to a directory using the following command:
`cd /path/to/extracted/python34
./configure --prefix=/path/to/install/dir
make
make install`
The next step is to create a virtualenv out of the newly installed python 3.4, so that it will have its own pip and other tools, so I run the following code:
cd /path/to/virtualenv/script
./virtualenv.py --python=/path/to/python34 /path/to/desired/virtualenv/dir
which fails, unfortunately
What went wrong:
I attempt to use the newly installed Python 3.4 to create a virtualenv, however I am met with errors when I do so. The result is the same whether I create the virtualenv using the builtin PyCharm tool, or even if I use a downloaded source of the virtualenv script. However, I was able to find out that the first error was about zlib, and I attempted to apply the solutions found here: building Python from source with zlib support
The zlib issue was resolved by logging in as administrator, and installing zlib1g-dev through:
sudo apt-get install zlib1g-dev
I also uncommented the following line from the Modules/Setup file of the extracted Python 3.4 source
zlib zlibmodule.c -I$(prefix)/include -L$(exec_prefix)/lib -lz
But even with the zlib issue resolved, I am now met with the following error log when trying to create a virtualenv using the freshly installed python 3.4:
`
Installing setuptools, pip, wheel...
Complete output from command /home/work/Documents...gQtEnv/bin/python3.4 - setuptools pip wheel:
Traceback (most recent call last):
File "<stdin>", line 7, in <module>
File "/home/work/Documents/programming/tools/virtualenv-15.0.3/virtualenv_support/pip-8.1.2-py2.py3-none-any.whl/pip/__init__.py", line 16, in <module>
File "/home/work/Documents/programming/tools/virtualenv-15.0.3/virtualenv_support/pip-8.1.2-py2.py3-none-any.whl/pip/vcs/subversion.py", line 9, in <module>
File "/home/work/Documents/programming/tools/virtualenv-15.0.3/virtualenv_support/pip-8.1.2-py2.py3-none-any.whl/pip/index.py", line 30, in <module>
File "/home/work/Documents/programming/tools/virtualenv-15.0.3/virtualenv_support/pip-8.1.2-py2.py3-none-any.whl/pip/wheel.py", line 39, in <module>
File "/home/work/Documents/programming/tools/virtualenv-15.0.3/virtualenv_support/pip-8.1.2-py2.py3-none-any.whl/pip/_vendor/distlib/scripts.py", line 14, in <module>
File "/home/work/Documents/programming/tools/virtualenv-15.0.3/virtualenv_support/pip-8.1.2-py2.py3-none-any.whl/pip/_vendor/distlib/compat.py", line 66, in <module>
ImportError: cannot import name 'HTTPSHandler'
----------------------------------------
...Installing setuptools, pip, wheel...done.
Traceback (most recent call last):
File "./virtualenv.py", line 2327, in <module>
main()
File "./virtualenv.py", line 711, in main
symlink=options.symlink)
File "./virtualenv.py", line 944, in create_environment
download=download,
File "./virtualenv.py", line 900, in install_wheel
call_subprocess(cmd, show_stdout=False, extra_env=env, stdin=SCRIPT)
File "./virtualenv.py", line 795, in call_subprocess
% (cmd_desc, proc.returncode))
OSError: Command /home/work/Documents...gQtEnv/bin/python3.4 - setuptools pip wheel failed with error code 1`
What I'm trying to figure out:
And this is where I am now. I would like to create a virtualenv from a non-root and non-system installation of python that is built from source. I understand that I can fiddle around and do trial and error installation of what I would guess to be necessary packages until all the errors go away, however I am not keen on willy nilly installation, especially as root. I'm supposing that there must be a way to install python without root access, and create a virtual env using this. Maybe identify what the necessary packages are, download all of them, build them, and add them to my local user's system path? Unfortunately I only have a vague idea on how to do half of these. Any guidance will be appreciated.
Thanks to all those who have taken time to read this and have attempted to provide a solution. Hoping for a resolution to the issue.
I have written a Python app which makes use of:
from PIL import Image
I want to distribute a packed version of this application so that whoever uses it does not need to install all the dependencies.
For that I have used pyinstaller, without much success.
I run:
pyinstaller --onefile image_download.py
and it does not complain. However, when I run the application, I get:
Traceback (most recent call last):
File "", line 26, in
File "/usr/local/lib/python2.7/dist-packages/PyInstaller/loader/pyi_importers.py", line 270, in load_module
exec(bytecode, module.dict)
File "/home/ic/twitter-project/build/image_download/out00-PYZ.pyz/PIL.PngImagePlugin", line 40, in
File "/usr/local/lib/python2.7/dist-packages/PyInstaller/loader/pyi_importers.py", line 270, in load_module
exec(bytecode, module.dict)
File "/home/ic/twitter-project/build/image_download/out00-PYZ.pyz/PIL.Image", line 63, in
ImportError: cannot import name _imaging
I am using:
Ubuntu 14.04
Python 2.7
pyinstaller 2.1
PIL.VERSION 1.1.7 (although I thought I had installed Pillow 2.8.1)
The script works fine running as python image_download.py, but pyinstaller is not being able to import _imaging, for some reason.
Any suggestions?
Finally I could not use pyinstaller for this, since I could not fix the import problem.
I managed to build a standalone executable with Nuitka and bbfreeze, though, so in case anyone runs into the same problem: it is worth trying other tools.