Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Issues with pyinstaller and pyproj

I'm trying to do an standalone application with pyinstaller. The executable has just build fine, but when I´m trying to do some operations with functions integrated on library pyproj, the executable crashes.

The script runs fine on Pycharm, so I think that the problem is that pyinstaller is not linking with some kind of library of pyproj.

May I have to do something special with spec file or another thing to specify pyproj on the standalone application built with pyinstaller?

This is the error that Ihave obtained:

Traceback (most recent call last):   File "<string>", line 6, in
<module>   File "C:\pyproj\build\main\out00-PYZ.pyz\pyproj", line 343,
in __new__   File "_proj.pyx", line 85, in _proj.Proj.__cinit__
(_proj.c:1190) 
RuntimeError: no system list, errno: 2

This is my "main.py"

 #!/usr/bin/env python
 # -*- coding: utf-8 -*-

 import pyproj 
 print pyproj.__version__ 
 p=pyproj.Proj(init='EPSG:4326')

Thanks in advance

like image 914
edsonlp1 Avatar asked Nov 25 '13 19:11

edsonlp1


People also ask

Why my PyInstaller is not working?

The most common reason a PyInstaller package fails is that PyInstaller failed to bundle a required file. Such missing files fall into a few categories: Hidden or missing imports: Sometimes PyInstaller can't detect the import of a package or library, typically because it is imported dynamically.

Does PyInstaller need UPX?

PyInstaller looks for UPX on the execution path or the path specified with the --upx-dir option. If UPX exists, PyInstaller applies it to the final executable, unless the --noupx option was given. UPX has been used with PyInstaller output often, usually with no problems.

Does PyInstaller include imports?

Analysis: Finding the Files Your Program Needs To find out, PyInstaller finds all the import statements in your script. It finds the imported modules and looks in them for import statements, and so on recursively, until it has a complete list of modules your script may use.

What is hidden import in PyInstaller?

--hidden-import. List multiple top-level imports that PyInstaller was unable to detect automatically. This is one way to work around your code using import inside functions and __import__() . You can also use --hidden-import multiple times in the same command.


2 Answers

The problem is that when using pyproj with PyInstaller, pyproj can not find the data files that are in the library folder.

The solution is to create a hook file, which will specify where the data files, so you can link them with our executable.

 hook-pyproj.py

 from PyInstaller.hooks.hookutils import collect_data_files
 datas = collect_data_files('pyproj')

The hook file can be located on "hooks" folder on Pyinstaller installation or using the order --additional-hooks-dir, specifying a folder in which will be located "hook-pyproj.py"

like image 166
edsonlp1 Avatar answered Oct 28 '22 13:10

edsonlp1


Just threading on the previous answer, since 2014 there has been some refactoring on PyInstaller and here is the correct import line for the hook file above :

from PyInstaller.utils.hooks import collect_data_files
datas = collect_data_files('pyproj')
like image 32
oliche Avatar answered Oct 28 '22 13:10

oliche