Error using PyInstaller - python

I'm trying to use PyInstaller to create a standalone OSX app that runs a GUI I've made. When I enter the following in my terminal:
pyinstaller gui.py
Everything seems to work until I get the following error:
File "/Users/username/anaconda/bin/PyInstaller", line 11, in <module>
sys.exit(run())
File "/Users/username/anaconda/lib/python2.7/site-
packages/PyInstaller/__main__.py", line 90, in run
run_build(pyi_config, spec_file, **vars(args))
File "/Users/username/anaconda/lib/python2.7/site-
packages/PyInstaller/__main__.py", line 46, in run_build
PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
File "/Users/username/anaconda/lib/python2.7/site-
packages/PyInstaller/building/build_main.py", line 788, in main
build(specfile, kw.get('distpath'), kw.get('workpath'),
kw.get('clean_build'))
File "/Users/username/anaconda/lib/python2.7/site-
packages/PyInstaller/building/build_main.py", line 734, in build
exec(text, spec_namespace)
File "<string>", line 16, in <module>
File "/Users/username/anaconda/lib/python2.7/site-
packages/PyInstaller/building/build_main.py", line 212, in __init__
self.__postinit__()
File "/Users/username/anaconda/lib/python2.7/site-
packages/PyInstaller/building/datastruct.py", line 178, in __postinit__
self.assemble()
File "/Users/username/anaconda/lib/python2.7/site-
packages/PyInstaller/building/build_main.py", line 470, in assemble
module_hook.post_graph()
File "/Users/username/anaconda/lib/python2.7/site-
packages/PyInstaller/building/imphook.py", line 409, in post_graph
self._load_hook_module()
File "/Users/username/anaconda/lib/python2.7/site-
packages/PyInstaller/building/imphook.py", line 376, in
_load_hook_module
self.hook_module_name, self.hook_filename)
File "/Users/username/anaconda/lib/python2.7/site-
packages/PyInstaller/hooks/hook-PyQt4.py", line 33, in <module>
(qt_menu_nib_dir('PyQt4'), ''),
File "/Users/username/anaconda/lib/python2.7/site-
packages/PyInstaller/utils/hooks/qt.py", line 125, in qt_menu_nib_dir
""".format(namespace, path))
Exception:
Cannot find qt_menu.nib for PyQt4
Path checked:
/Users/felipe/miniconda/envs/_build/lib/QtGui.framework/Resources/qt_menu.nib
Which seems strange, since my name is not felipe!
I have a couple of questions:
1) How is it possible that there is a directory under the name felipe on my computer? (I used anaconda to install qt, I don't know whether that has something to do with it?)
2) Up until I get the error message, PyInstaller is looking in the correct folder. Why does it start looking in this vague (vague to me that is) directory I don't know of?
3) I'm quite a novice regarding directories and I can't find mister felipe anywhere on my computer. When I look in the Users folder I just see my own user and an empty "Shared" folder. (I don't know what the shared folder is used for and why it's there.)
4) Based on what I read on the internet, I copied qt_menu-nib to the folder where the script that's supposed to be turned into a standalone is located. What should I do in order to successfully create a standalone from here?

First of all, you face a known issue between PyInstaller and Anaconda: PyInstaller issue #2135. The conversation contains answers to your questions.
1) The path is hardcoded in the wrongly built Qt binary that is provided by Anaconda, see comment from mrady3.
2) PyInstaller loads Qt4-specific hook in order to find resources (qt_menu.nib) that are necessary for running target app. The hook code tries to obtain location of resource directory from the Qt binary itself. Qt binary returns wrong /hardcoded/ path, and after that process fails.
3) See point 1), it was a folder on maintainer's machine. Qt assumes that its installation path is pre-set before building; Anaconda repository hosts a binary that was compiled with another installation path in mind.
4) There could be several possible approaches:
Try installing developer version of PyInstaller from sources, it has some fixes for the above-mentioned issue. Then try building the app again:
git clone https://github.com/pyinstaller/pyinstaller.git
cd pyinstaller
/Users/username/anaconda/bin/python setup.py sdist
conda install dist/PyInstaller-3.3.dev0.tar.bz2
Install Qt4 using homebrew. Local compilation will take a long time:
brew install cartr/qt4/qt
find /usr/local/Cellar/qt -name qt_menu.nib
Edit Qt4 hook at /Users/username/anaconda/lib/python2.7/site-
packages/PyInstaller/hooks/hook-PyQt4.py and replace call to qt_menu_nib_dir('PyQt4') with the path from homebrew installation ('/usr/local/Cellar/qt/4.8.7_3/lib/QtGui.framework/Versions/4/Resources/qt_menu.nib').
Or alternatively, just put qt_menu.nib into expected location:
sudo mkdir -p /Users/felipe/miniconda/envs/_build/lib/QtGui.framework/Resources/
sudo ln -s /usr/local/Cellar/qt/4.8.7_3/lib/QtGui.framework/Versions/4/Resources/qt_menu.nib /Users/felipe/miniconda/envs/_build/lib/QtGui.framework/Resources/

Related

importlib.metadata.PackageNotFoundError: No package metadata was found for djoser pyinstaller

Context
I made a Django react app. Now I want to make it a desktop application so that the user does not have type python manage.py runserver and also activate the environment every time. I used pyinstaller. I did all the steps mentioned for django.
Problem
when I run my executable file made from pyinstaller, I got this error
File "manage.py", line 5, in <module>
File "PyInstaller\loader\pyimod02_importers.py", line 499, in exec_module
File "djoser\__init__.py", line 6, in <module>
File "importlib\metadata\__init__.py", line 955, in version
File "importlib\metadata\__init__.py", line 928, in distribution
File "importlib\metadata\__init__.py", line 518, in from_name
importlib.metadata.PackageNotFoundError: No package metadata was found for djoser
[2200] Failed to execute script 'manage' due to unhandled exception!
What I have done
I have already installed Djoser in the environment and the environment is also activated. I have also tried to add in manage.py file and also in hidden_import lists but nothing changed. I have also tried adding --copy-meta=djoser in the build command but it got even worse error.
How do I fix this error and If there are any better alternative solutions out there? Thanks
Well I have found for myself another solution . To run this django file by creating a batch file
#echo off
set "VENV_NAME=myenv"
set "PROJECT_DIR=C:\path\to\project"
cd /d %~dp0
cd /d %PROJECT_DIR%
call "%VENV_NAME%\Scripts\activate.bat"
python manage.py runserver
manage.exe runserver --norelaod

Installing Google Cloud SDK throwing error in install.py when using install.bat

I am trying to install google cloud SDK using install.bat. I have tried downloading the bundled pythons versions 275 and current version 276, they both fail at the same spot. It is able to find python in the platform/bundledpython folder so that is not the issue. I have also tried the suggestions online including making sure that the "Find" command works on a command prompt. Any help appreciated.
The latest available version is: 276.0.0
���───────────────────────────────────────────────────────────────────────────────────────────────────────────────┐Trac
back (most recent call last):
File "C:\google-cloud-sdk\google-cloud-sdk\\bin\bootstrapping\install.py", line 225, in <module>
main()
File "C:\google-cloud-sdk\google-cloud-sdk\\bin\bootstrapping\install.py", line 203, in main
Install(pargs.override_components, pargs.additional_components)
File "C:\google-cloud-sdk\google-cloud-sdk\\bin\bootstrapping\install.py", line 148, in Install
_CLI.Execute(['--quiet', 'components', 'list'])
File "C:\google-cloud-sdk\google-cloud-sdk\lib\googlecloudsdk\calliope\cli.py", line 1007, in Execute
self._HandleAllErrors(exc, command_path_string, specified_arg_names)
File "C:\google-cloud-sdk\google-cloud-sdk\lib\googlecloudsdk\calliope\cli.py", line 1040, in _HandleAllErrors
exceptions.HandleError(exc, command_path_string, self.__known_error_handler)
File "C:\google-cloud-sdk\google-cloud-sdk\lib\googlecloudsdk\calliope\exceptions.py", line 527, in HandleError
core_exceptions.reraise(exc)
File "C:\google-cloud-sdk\google-cloud-sdk\lib\googlecloudsdk\core\exceptions.py", line 146, in reraise
six.reraise(type(exc_value), exc_value, tb)
File "C:\google-cloud-sdk\google-cloud-sdk\lib\googlecloudsdk\calliope\cli.py", line 981, in Execute
resources = calliope_command.Run(cli=self, args=args)
File "C:\google-cloud-sdk\google-cloud-sdk\lib\googlecloudsdk\calliope\backend.py", line 809, in Run
display_info=self.ai.display_info).Display()
File "C:\google-cloud-sdk\google-cloud-sdk\lib\googlecloudsdk\calliope\display.py", line 483, in Display
self._printer.Print(self._resources)
File "C:\google-cloud-sdk\google-cloud-sdk\lib\googlecloudsdk\core\resource\resource_printer_base.py", line 279, in P
int
self.Finish()
File "C:\google-cloud-sdk\google-cloud-sdk\lib\googlecloudsdk\core\resource\table_printer.py", line 467, in Finish
self._out.write(line)
File "C:\google-cloud-sdk\google-cloud-sdk\lib\googlecloudsdk\core\log.py", line 239, in write
self._Write(plain_text, styled_text)
File "C:\google-cloud-sdk\google-cloud-sdk\lib\googlecloudsdk\core\log.py", line 232, in _Write
self.__stream_wrapper.stream.write(stream_msg)
I just had the same problem trying to install the latest Google Cloud SDK (276.0.0). The Windows setup was stuck on "Installing components".
Looking at the process list with Process Explorer I could see it was running this command that was stuck, as you probably did to get your stack trace. I took the command line and ran it in a separate Administror cmd.exe (paths might differ per system, the idea is the same).
cd "C:\Program Files (x86)\Google\Cloud SDK"
SET "CLOUDSDK_CORE_DISABLE_PROMPTS=1"
SET "CLOUDSDK_CONFIG=%APPDATA%\gcloud"
"C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\install.bat" --quiet --disable-installation-options --path-update "FALSE" --usage-reporting "true" --additional-components beta powershell"
Running them would produce the same error / stack trace.
Editing log.py and commenting out (prefix with #) line 232 would make it get further, but it runs into a separate problem:
ERROR: Cannot use bundled Python installation to update Cloud SDK in non-interactive mode.
Please run again in interactive mode.
Enable prompts with CLOUDSDK_CORE_DISABLE_PROMPTS envvar and remove --quiet and --disable-installation-options from the install.bat command line and run it again.
SET "CLOUDSDK_CORE_DISABLE_PROMPTS=0"
"C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\install.bat" --path-update "FALSE" --usage-reporting "true" --additional-components beta powershell"
This time it should continue, start a new console where it actually installs the components and eventually finish succesfully.

Py2app with native Python 2.6

I have a python application primarily dependent on matplotlib, tkinter, numpy and scipy I have been distributing for multiple operating systems. I build these on top of the python.org version of python 2.6. For mac, I have had good success in the past with py2app and pyinstaller to build standalone versions of my application. Recently, however, I have included functions that require patsy, pandas and igraph and have had to move to the mac distributed version of python 2.6 in order to get igraph to work. All works fine in building a py2app version of my software on the Mac for my OS (10.6) but when I run on 10.8 I encountered the following error:
Traceback (most recent call last):
File "UI.pyc", line 603 createHeatMap
File "clustering.pyc", line 31, in <module>
File "mpl_toolkits/__init__.pyc", line 2, in <module>
File "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/pkg_resources.py", line 698, in <module>
File "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/pkg_resources.py", line 701, in Environment
File "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/pkg_resources.py", line 96, in get_supported_platform
File "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/pkg_resources.py", line 222, in get_build_platform
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/distutils/util.py", line 98, in get_platform
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/distutils/sysconfig.py", line 537, in get_config_vars
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/distutils/sysconfig.py", line 405, in _init_posix
DistutilsPlatformError: invalid Python installation: unable to open /user/include/python2.6/pyconfig.h (No such file or directory)
This is fixed by saving the file pyconfig.h to the designated location on the destination machine (not present in 10.8 but present in 10.6), which allows my application to work fine. In my py2app pacakge directory, under "Contents/Resources" there is a sym-link to the directory "include" which points to: /System/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6/pyconfig.h. If I include the pyconfig.h file as an addition resource in my py2app setup file, it also includes it in the package, but it still is not recognized.
Can anyone suggest a good work around for this that doesn't require me to use the python.org version of python (I've had horrible luck getting igraph to work with this).
Thanks...
This is a known issue in py2app, see https://bitbucket.org/ronaldoussoren/py2app/issue/36/py2app-fails-to-build-a-working-executable. The pyconfig.h file is only present on machines where the developer tools are installed, which is why I haven't noticed the problem myself.
The easiest workaround is probably to replace the pyconfig.h symlink by a copy of the file after creating the app bundle.

Using virtualenv in VMWare with shared Windows folder

I currently use a linux VM in VMWare running on a Windows machine. I have a shared Windows folder for my projects that I access in linux via /mnt/hgfs/
When I try to use virtualenv for my python projects I get an 'Operation not supported' error:
joe#myserver:/mnt/hgfs/winwww/envtest# virtualenv env
Traceback (most recent call last):
File "/usr/local/bin/virtualenv", line 9, in <module>
load_entry_point('virtualenv==1.7', 'console_scripts', 'virtualenv')()
File "/usr/local/lib/python2.6/dist-packages/virtualenv.py", line 928, in main
never_download=options.never_download)
File "/usr/local/lib/python2.6/dist-packages/virtualenv.py", line 1029, in create_environment
site_packages=site_packages, clear=clear))
File "/usr/local/lib/python2.6/dist-packages/virtualenv.py", line 1164, in install_python
copyfile(join(stdlib_dir, fn), join(lib_dir, fn))
File "/usr/local/lib/python2.6/dist-packages/virtualenv.py", line 430, in copyfile
copyfileordir(src, dest)
File "/usr/local/lib/python2.6/dist-packages/virtualenv.py", line 405, in copyfileordir
shutil.copytree(src, dest, True)
File "/usr/lib/python2.6/shutil.py", line 173, in copytree
raise Error, errors
shutil.Error: [('/usr/lib/python2.6/config/libpython2.6.so', 'env/lib/python2.6/config/libpython2.6.so', '[Errno 95] Operation not supported')]
I'm assuming this is due to Windows not being able to handle symbolic links because I can create my virtualenvs in other directories.
Has anyone worked out a way to make virtualenv work in shared Windows folders? I edit my code on my Windows machine which is why I use shared folders.
Thanks.
The virtualenv does not need to be located next to your code, so even if you can't create it within your shared folder this shouldn't affect your ability to edit the code on windows and run it on your host platform. It sounds to me like a bad idea anyway to attempt to share platform-specific files with multiple platforms.
This is the usefulness of the .pth files and if you're using setuptools with a setup.py within your project you can just $VENV/python setup.py develop which will link your project into the virtualenv, wherever it may be located. You can then run $VENV/python and your package will be in the sys.path and available for import.

Python py2exe - memory load error

I am creating a medium level application in Python.
Everything works well now, and I am trying to make this a windows executable with py2exe.
The executable is created fine, but when I try to run it, it fails with the following error.
File "zipextimporter.pyo", line 82, in load_module
File "ffhandler.pyo", line 33, in ?
File "zipextimporter.pyo", line 82, in load_module
File "pyAA\__init__.pyo", line 1, in ?
File "zipextimporter.pyo", line 82, in load_module
File "pyAA\AA.pyo", line 8, in ?
File "zipextimporter.pyo", line 82, in load_module
File "pyAA\pyAAc.pyo", line 5, in ?
File "zipextimporter.pyo", line 98, in load_module
ImportError: MemoryLoadLibrary failed loading pyAA\_pyAAc.pyd
I am using pyAA in this application. I searched internet, but was unable to get any solution.
I copied msvcp71.dll to windows/system32, but still issue is there.
I had solved it earlier (around 7 months back), but my hard drive crashed and when I try to recreate it, I cannot seem to solve it now. :-(
I would be much obliged if someone could help me out here.
EDIT:
When I use py2exe without bundle files option, it is working perfectly. But when I use bundle file option, it is failing.
I tried without zipfile option, wherein it creates a library.zip alongwith the executable. Again it failed. I did unzip of library.zip using 7-zip, and found that _pyAAc.pyd is there in pyAA folder inside the zip file. So, it looks like some issue with memoryloadlibrary function.
When I tried to unzip using windows unzip function, it failed. I had to use 7-zip to unzip it. Is it a possible clue?
You're missing some DLL's in your build...
First search your hard drive for the file _pyAAC.pyd. Make sure it is included (shipped) in your build.
Then use 'dependency walker' on the .pyd file (in your py2exe compiled version!) to see what it is that is still missing (other DLL's which are causing the MemoryLoadLibrary message for the .pyd file). Make sure these dependencies are also shipped, ...

Categories