PyInstaller on 32-bit Linux - ImportError: The 'six' package is required - linux

I'm making a program using Python2.7 and Kivy1.9.2-dev, and trying to package it with PyInstaller-3.0 for different systems as a single executable.
The systems I'm trying to package it for are these:
64-bit Linux Mint 17.3
32-bit Linux Mint 17 (also tried while upgrading to 17.1 and 17.3)
32-bit Windows XP SP3
Raspbian (Raspberry Pi)
On all these systems the program is working well when just run with Python, uncompiled. (so, all Kivy dependencies are fine, too).
However, out of the executables made with PyInstaller, only the one made on 64-bit Linux works as one file. The Windows and Raspbian executables mostly work (I'll write about it later), but the one made on 32-bit Linux still doesn't run. It gives the following error when run (I tried running it on both 32 and 64-bit Linux):
Traceback (most recent call last):
File "<string>", line 11, in <module>
File "/media/Data/Programming/Python/installers/PyInstaller-3.0/PyInstaller/loader/pyimod03_importers.py", line 363, in load_module
exec(bytecode, module.__dict__)
File "/usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 48, in <module>
File "/usr/local/lib/python2.7/dist-packages/pkg_resources/extern/__init__.py", line 60, in load_module
ImportError: The 'six' package is required; normally this is bundled with this package so if you get this warning, consult the packager of your distribution.
pyi_rth_pkgres returned -1
Here's what I'm confused about:
Inside my "/usr/local/lib/python2.7/dist-packages/" there is no "pkg_resources" folder, but the above indicates that it, apparently, is there... It even reads the files there successfully. Is it something that gets created just when the executable starts?
I don't specifically use "six" for anything, before this error I didn't even know it existed.
"Six" IS installed on my system, as confirmed by the Package Manager and by Pip. It's located in "/usr/local/lib/python2.7/dist-packages/". I guess PyInstaller can't find it for some reason (as, I believe, if everything is packaged correctly it doesn't have to be there on the system where the executable is run.)
So, my question is pretty typical, what may cause this problem for PyInstaller (just in case, I DID run the "setup.py install" for it), and how to get around/fix it?
Thanks!
PS: On a side note, I mentioned the problems with Windows and Raspbian executables. On Windows, the exe only runs when there is "zlib1.dll" present in the same folder (even if specifically packaged into the exe with PyInstaller, it doesn't work), and on Raspbian I only got the program working without using "--onefile" (with "--onefile", it seems PyInstaller doesn't package any Python binaries into the executable, like libpython.2.7.so, and maybe others too)

Well, adding 'six' into hidden packages, as Clement suggested, didn't work, but started a sequence of trial-and-error that finally led to a solution.
After the test with "hiddenimports" didn't work I tried just importing 'six' into my Python code. And the compiled executable no longer showed this error! However, it now said that the package named 'packaging' is required... Which I didn't have installed.
To put it short, starting from the initial problem, I did this:
Installed 'packaging' using 'pip':
sudo pip install packaging
Added these imports into my main Python code:
import six
import packaging
import packaging.version
import packaging.specifiers
(all the imports added were trial-and-error, done until the PyInstaller-made executable finally worked).
Seems a bit hack-y, as making the executable for a 64-bit Linux didn't require any of these imports, but at least it now works, and the executable size is basically unaffected.

For the following setup (anaconda):
PyInstaller: 3.2
Python: 3.5.2
Platform: Windows-10-10.0.10240-SP0
Numpy: 1.11.1
And the following mwe.py:
import numpy
print ("hello world")
I had to do the following to fix:
pip install packaging
Build with the following bat file (^ is the BAT line continuation):
pyinstaller --noconfirm ^
--hidden-import six ^
--hidden-import packaging ^
--hidden-import packaging.version ^
--hidden-import packaging.specifiers ^
--hidden-import packaging.requirements ^
mwe.py

I had a similar problem. Try to add "six" as well as "kivy" to the hidden_packages in your spec file. If it doesn't work, make sure that setuptools is installed in its 19.2 version. It seemed to be the problem for me on Windows. Hope it helps.

Related

Getting error when using pynput with pyinstaller

A friend of mine asked me to write him a program, and I used pynput to handle some of the inputs and other features. When I convert the program an executable with pyinstaller, launcing the executable gives me this error: File "site-packages\pynput\keyboard\__init__.py", line 31, in <module> File "site-packages\pynput\_util\__init__.py", line 82, in backend ImportError [11492] Failed to execute script friend_project
I have tried using the pyinstaller command pyinstaller --onefile friend_project.py, and also using auto-py-to-exe to run it.
Using pyinstaller with other modules like pygame or pyopengl gives me no error, but this one module does.
Running the script by it self with the python inturpeter works fine, but I would perfer to have it be an exe so I can give it to him with out him needing python to run it.
Please fall back to 1.6.8 version of pynput.
pip install pynput==1.6.8
If you are running Windows you need to add these parameters to the command line (for the first time, after that they will be included in the generated spec file).
--hidden-import "pynput.keyboard._win32" --hidden-import "pynput.mouse._win32"
For Linux, use:
--hidden-import "pynput.keyboard._xorg" --hidden-import "pynput.mouse._xorg"
More information can be found in this Github issue.

Dlib ImportError in Windows 10 on line _dlib_pybind11 import *, DLL Load Failed

I am able to successfully install Dlib with CUDA support in Windows 10 but getting an error during "import dlib" in my python code of computer vision project.
Environment: Windows 10, Python 3.7.6 (Anaconda), CUDA 11, CuDNN 10.2
Error Message:
>>> import dlib
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\ProgramData\Anaconda3\lib\site-packages\dlib-19.20.99-py3.7-win-amd64.egg\dlib\__init__.py", line 12, in <module>
from _dlib_pybind11 import *
ImportError: DLL load failed: The specified module could not be found.
This can be solved by copying the cudnn64_7.dll (available here: https://developer.nvidia.com/cudnn)
into the %CUDA_PATH%/bin directory (probably something like this: C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\bin)
I am able to find and fix this issue. CUDA 11 installation wasn't able to add few of the directories into the PATH environment variable (Windows 10). It was truncated due to the max length of 2048 characters. I have removed a few of the unused software paths from PATH value and after reinstallation, dlib 19.20 is working with CUDA 11 now.
I created an issue on DLIB Github under the following link which has more information regarding error logs and snapshots for this issue.
https://github.com/davisking/dlib/issues/2097
In my environment, the problem was due to an error somewhere in the build process that resulted code to load CuDNN dynamic libraries not being included in the generated file dlib/__init__.py despite having no build error. In my case the file always included this strange block of code:
if 'OFF' == 'ON':
add_lib_to_dll_path('cudnn-NOTFOUND')
add_lib_to_dll_path('C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.5/lib/x64/cudart.lib')
The second line's cudnn-NOTFOUND gave a clue of what happened with my build.
As I followed instructions on this page, copying all the binaries and include files to the right places within the CUDA directory, I only needed to modify the code to (similar to what Epic Chen's answer suggests but I got rid of the if clause and the bad code line):
add_lib_to_dll_path('C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.5/lib/x64/cudart.lib')
That workaround fixed the problem for me.
My configuration is CUDA 11.5, CuDNN 8.3.1.22, dlib compiled using Visual Studio 2019. The environment variable CMAKE_PREFIX_PATH to the CuDNN directory to get the compiler to find the include files and libraries.
If you are using Anaconda, uninstall dlib and reinstall dlib.
In anaconda command prompt, type
pip uninstall dlib
After successfully uninstalling, type
pip install dlib
It helped me fix the problem.
Try to check the __init__.py file which the error message indicate as below.
Your path is not the same as me.
In the __init__.py file, the if statement should be 'ON' == 'ON'
Besides, the following library paths must be correct. Your version may not be the same as me.

How to install PyGObject on windows in a anaconda virtual env

I want to use Gtk with python under windows. I already have Anaconda installed on windows. In order not to mess up everything and to have some easiness uninstalling/reinstalling, I would like to have a virtual env created with conda, working with that Gtk installation. But I don't seems to be able to make it work.
Here is my process. I first create a raw Ananconda virtual env with
conda create -n gtk-exporter python
The virtual environment is located at C:\Anaconda3\envs\gtk-exporter.
I then download the latest windows installer for PyGObject at http://sourceforge.net/projects/pygobjectwin32/files/?source=navbar
I extract and execute the installer and tell it to use a portable python install at C:\Anaconda3\envs\gtk-exporter. I only select Base, GTK and Glade for installation. The installation finished in a second and says it's successful.
Then within windows' shell, I activate the new environment with activate gtk-exporter. However when I try to import gtk, it fails, not finding gi.repository.
>>> from gi.repository import Gtk
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named 'gi'
What's wrong here ? C:\Anaconda3\envs\gtk-exporter\Lib\site-package contains a folder gnome with a lot of stuff including *.dlls, *.exe's and unix-looking folders like etc, lib or share, but I don't see a init.py or something pythonic. Am I missing a step.
Thank you for your help !
The problem was that I used python 3.5, whereas it is not supported. The installer should not have allowed me to install with python 3.5. I filed a bug report to signal it.
I solved the problem by uninstalling python 3.5 and installing python 3.4.

importerror-no-module-named-pkg-resources after upgrade of python on cygwin

A while back I upgraded to python 2.7. I haven't used any of the packages I've downloaded recently so I didn't realize the error was connected until just now. I couldn't use any of the packages because I was getting the no_module_named pkg-resources error. I saw this question: What is causing ImportError: No module named pkg_resources after upgrade of Python on os X? and tried to follow the instructions but of course since I'm using cygwin I can't use curl. I used cygwin setup to try and download distribute (which I guess doesn't exist for cygwin either) and found python-setuptools. On the off chance that it would help I downloaded it and it got rid of that error. This was great because now I can use easy_install at least. However, I still get the following error with
dependencies when running many of my packages:
Traceback (most recent call last):
File "/usr/bin/ipython", line 5, in <module>
from pkg_resources import load_entry_point
File "/usr/lib/python2.7/site-packages/pkg_resources.py", line 2803, in <module>
working_set.require(__requires__)
File "/usr/lib/python2.7/site-packages/pkg_resources.py", line 696, in require
needed = self.resolve(parse_requirements(requirements))
File "/usr/lib/python2.7/site-packages/pkg_resources.py", line 594, in resolve
raise DistributionNotFound(req)
pkg_resources.DistributionNotFound:
Any ideas I think it might be a problem with my site-packages not being in the new python folder so I will investigate that. Either way I wanted to share my solution to the problem for cygwin users.
Update: I copied over the site-packages from 2.6 to 2.7 and that didn't help. I eventually realized because the eggs are all for 2.6 not 2.7 so python 2.7 won't accept them. This is quite annoying. I guess I have to reinstall all the packages unless anyone has an easier solution?
To address the root of this problem. I discovered I was operating on a faulty assumption that curl was incompatible with Cygwin. I found out you can setup cygwin to enable curl, problem solved!

Python3.2 PyQt4 installation: UnboundLocalError

Recently I upgraded my Ubuntu to version 11.10 so I had to reinstall python3 modules. I downloaded latest PyQt4 but when I run configure.py I get following error:
Qt Designer plugin disabled because Python library couldn't be found
An internal error occured. Please report all the output from the program,
including the following traceback, to support#riverbankcomputing.com.
Traceback (most recent call last):
File "configure.py", line 2269, in <module>
main()
File "configure.py", line 2254, in main
subdirs=pyqt.qpy_libs() + pyqt_modules + xtra_modules + pyqt.tools(),
File "configure.py", line 957, in tools
link = "%s -lpython%d.%d%s" % (lib_dir_flag, py_major, py_minor, abi)
UnboundLocalError: local variable 'lib_dir_flag' referenced before assignment
I really haven't got a clue what is wrong. btw. Before I upgraded Ubuntu to 11.10 I used python3.1 and everything was fine.
Make sure you have the correct sip packages installed before you try to build PyQt4. For ubuntu, I think you will need the python-sip-dev and python3-sip-dev packages (plus any dependencies). Alternatively, you could download and build the latest version of sip from source.
When you run the configure.py script for either pyqt or sip, it is essential that you use the correct version of python, e.g:
/usr/bin/python3.2 configure.py

Resources