I get error "No module named 'pyproj._datadir'" after I made .py to .exe with pyinstaller [duplicate] - python-3.6

This question already has answers here:
Issues with pyinstaller and pyproj
(3 answers)
Closed 2 years ago.
My code works well when it's .py
but when I make .exe file with pyinstaller, it shows ModuleNotFoundError.
I write this when I made .exe
pyinstaller -F MyCode.py
How can I solve this problem?
I've read
Issues with pyinstaller and pyproj
and I was going to try to make and located hook-pyproj.py at "hooks" folder in Pyinstaller. but hook-pyproj.py was already there with the same code.
After that, I installed "basemap" and tried to use pyproj from it. However it shows me the same error.
This is the error it showed me when I execute the .exe file.
(I covered some information with *****)
Traceback (most recent call last):
File "collect\MyCode.py", line 8, in <module>
File "c:\users\*****\appdata\local\programs\python\python36-32\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
exec(bytecode, module.__dict__)
File "site-packages\mpl_toolkits\basemap\__init__.py", line 41, in <module>
File "c:\users\*****\appdata\local\programs\python\python36-32\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
exec(bytecode, module.__dict__)
File "site-packages\pyproj\__init__.py", line 62, in <module>
File "c:\users\*****\appdata\local\programs\python\python36-32\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
exec(bytecode, module.__dict__)
File "site-packages\pyproj\crs.py", line 26, in <module>
File "pyproj\_crs.pyx", line 1, in init pyproj._crs
ModuleNotFoundError: No module named 'pyproj._datadir'
[25936] Failed to execute script MyCode
This is my code.
from mpl_toolkits.basemap import pyproj as pyproj
I tried this at first.
import pyproj
but I get same " ModuleNotFoundError: No module named 'pyproj._datadir' " error.

It's a bit odd and I don't exactly understand why but I found a quick dirty fix.
You can add this import
from pyproj import _datadir, datadir
to your existing one.

I noticed this pyproj import dll error error occurred on some Windows machines and not others.
Turned out to be a dependency on Visual C Runtime 2015+
https://support.microsoft.com/en-au/help/2977003/the-latest-supported-visual-c-downloads

Related

Script compiled with pyinstaller is missing a .dll file, when the file is manually copied in the program's folder it just dies

I have a python script which is basically a graphic interface (pysimpleguy) to a mysql database.
I am working in python 3.8; my dependencies are:
PySimpleGUI 4.55.1
sqlalchemy 1.3.20
pymysql 1.0.2
pandas 1.1.3
regex 2020.10.15
pillow 8.0.1
The code works and I'd like to compile it to .exe to distribute it to users in my organization.
I tried to compile it with:
pyinstaller -D .\db_interface_v3.6.1_release.py --debug=imports
However, pyinstaller throws some errors when compiling:
201667 INFO: Building COLLECT COLLECT-00.toc
Traceback (most recent call last):
File "c:\users\spit\anaconda3\lib\runpy.py", line 194, in _run_module_as_main
return _run_code(code, main_globals, None,
File "c:\users\spit\anaconda3\lib\runpy.py", line 87, in _run_code
exec(code, run_globals)
File "C:\Users\Spit\anaconda3\Scripts\pyinstaller.exe\__main__.py", line 7, in <module>
File "c:\users\spit\anaconda3\lib\site-packages\PyInstaller\__main__.py", line 124, in run
run_build(pyi_config, spec_file, **vars(args))
File "c:\users\spit\anaconda3\lib\site-packages\PyInstaller\__main__.py", line 58, in run_build
PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
File "c:\users\spit\anaconda3\lib\site-packages\PyInstaller\building\build_main.py", line 782, in main
build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))
File "c:\users\spit\anaconda3\lib\site-packages\PyInstaller\building\build_main.py", line 714, in build
exec(code, spec_namespace)
File "C:\Users\Spit\Desktop\DIPEx db parser\db_interface_v3.6.1_release.spec", line 37, in <module>
coll = COLLECT(exe,
File "c:\users\spit\anaconda3\lib\site-packages\PyInstaller\building\api.py", line 818, in __init__
self.__postinit__()
File "c:\users\spit\anaconda3\lib\site-packages\PyInstaller\building\datastruct.py", line 155, in __postinit__
self.assemble()
File "c:\users\spit\anaconda3\lib\site-packages\PyInstaller\building\api.py", line 866, in assemble
shutil.copy(fnm, tofnm)
File "c:\users\spit\anaconda3\lib\shutil.py", line 415, in copy
copyfile(src, dst, follow_symlinks=follow_symlinks)
File "c:\users\spit\anaconda3\lib\shutil.py", line 261, in copyfile
with open(src, 'rb') as fsrc, open(dst, 'wb') as fdst:
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\Spit\\Desktop\\DIPEx db parser\\dist\\db_interface_v3.6.1_release\\share\\jupyter\\lab\\staging\\node_modules\\.cache\\terser-webpack-p
lugin\\content-v2\\sha512\\2e\\ba\\cfce62ec1f408830c0335f2b46219d58ee5b068473e7328690e542d2f92f2058865c600d845a2e404e282645529eb0322aa4429a84e189eb6b58c1b97c1a'
If I try to run the compiled exe, I get an error regarding a specific .dll:
INTEL MKL ERROR: Impossibile trovare il modulo specificato. mkl_intel_thread.dll.
Intel MKL FATAL ERROR: Cannot load mkl_intel_thread.dll.
If I take this missing .dll from my Anaconda environment and copy it into the program's folder, when I try to run the .exe again it just dies without further messages:
import 'numpy.ma' # <pyimod03_importers.FrozenImporter object at 0x000001F6A455BEE0>
PS C:\Users\Spit\Desktop\DIPEx db parser\dist\db_interface_v3.6.1_release>
Any idea on how to sort it out?
Thanks!
Sorted out. As a future reference if someone stumbles upon this question, the error is caused by Windows' PATH_MAX limitation, preventing pyinstaller to find all the necessary files.
In order to disable said limitation: https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation?tabs=cmd
Kudos to https://github.com/bwoodsend

Streamlit deploy error with cv2 and with streamlit lib

ModuleNotFoundError: No module named 'cv2'
Traceback:
File "/usr/local/lib/python3.7/site-packages/streamlit/script_runner.py", line 332, in _run_script
exec(code, module.dict)
File "/app/pencilsketch_webapp/webapp.py", line 4, in
import cv2
Although I need to see your scripts and Procfile/Dockerfile for solving this properly but analyzing your error code I can see there is an issue with opencv.
A possible fix if it is purely related to deployment:
In the requirements.txt file put opencv-python instead of cv2

Dependencies tracking on python application

I am trying to make a portable application from a python app I developped on Windows 7 - 32 bits using python3.4. My first idea was to use py2exe combined with a ThinApp equivalent, but as I use rasterio which is not a pure python library, py2exe does not manage to find some DLLs.
If I try to run the generated executable I get this error :
File Traceback (most recent call last):
File "viewer.py", line 3, in <module>
import MainWindow as GUI
File "C:\Users\IEUser\Documents\viewer-dev\viewer\MainWindow.py", line 2, in <module>
import ImageWindow
File "C:\Users\IEUser\Documents\viewer-dev\viewer\ImageWindow.py", line 1, in <module>
import Resampler
File "C:\Users\IEUser\Documents\viewer-dev\viewer\Resampler.py", line 1, in <module>
import rasterio
File "C:\Python34\lib\site-packages\rasterio\__init__.py", line 31, in <module>
from rasterio._base import gdal_version
File "<loader>", line 10, in <module>
File "<loader>", line 8, in __load
ImportError: (DLL load failed: The specified module could not be found.) 'C:\\Users\\IEUser\\Documents\\viewer-dev\\dist\\rasterio._base.pyd'
I read that I had to add these DLLs manually in the dist directory, but I wonder how could I get a list of the required DLLs ?
You can use the Dependency Walker on your py2exe to see all the missing dependencies.
Check the executable and all the linked libraries(PYD & DLL files)

import rpy2.rinterface throwing errors in Python3.5

I've just reinstalled rpy2 with Python3.5 and I am having difficulty figuring out why the module cannot find the "R-Home". I have installed R on my computer already. Should I try reinstalling R or another method? Some help would be much appreciated here!
import rpy2.rinterface
Traceback (most recent call last):
File "<ipython-input-7-676c977874d9>", line 1, in <module>
import rpy2.rinterface
File "/Users/JasonDucker/anaconda/lib/python3.5/site-packages/rpy2/rinterface/__init__.py", line 16, in <module>
tmp = subprocess.check_output(("R", "RHOME"), universal_newlines=True)
File "/Users/JasonDucker/anaconda/lib/python3.5/subprocess.py", line 629, in check_output
**kwargs).stdout
File "/Users/JasonDucker/anaconda/lib/python3.5/subprocess.py", line 696, in run
with Popen(*popenargs, **kwargs) as process:
File "/Users/JasonDucker/anaconda/lib/python3.5/subprocess.py", line 950, in __init__
restore_signals, start_new_session)
File "/Users/JasonDucker/anaconda/lib/python3.5/subprocess.py", line 1544, in _execute_child
raise child_exception_type(errno_num, err_msg)
FileNotFoundError: [Errno 2] No such file or directory: 'R'
This means that there is no executable in the PATH when python is calling "R RHOME" in a subprocess.
To overcome this add the path to R to your PATH. For example:
export PATH=/usr/local/some/place/bin:${PATH}

pkg_resources.DistributionNotFound: distribute error on new Plone 4.3 instance

I've just installed a new plone 4.3 instance in a folder which already contained 2 Plone 4.3 instance, which both work fine. When I try to run buildout I get this error:
Traceback (most recent call last):
File "bin/buildout", line 17, in <module>
import zc.buildout.buildout
File "/usr/local/Plone4.3/buildout-cache/eggs/zc.buildout-1.7.1-py2.7.egg/zc/buildout/buildout.py", line 40, in <module>
import zc.buildout.download
File "/usr/local/Plone4.3/buildout-cache/eggs/zc.buildout-1.7.1-py2.7.egg/zc/buildout/download.py", line 20, in <module>
from zc.buildout.easy_install import realpath
File "/usr/local/Plone4.3/buildout-cache/eggs/zc.buildout-1.7.1-py2.7.egg/zc/buildout/easy_install.py", line 31, in <module>
import setuptools.package_index
File "/usr/local/Plone4.3/Python-2.7/lib/python2.7/site-packages/distribute-0.6.35-py2.7.egg/setuptools/package_index.py", line 158, in <module>
sys.version[:3], require('distribute')[0].version
File "/usr/local/Plone4.3/buildout-cache/eggs/setuptools-0.6c11-py2.7.egg/pkg_resources.py", line 666, in require
continue # try the next older version of project
File "/usr/local/Plone4.3/buildout-cache/eggs/setuptools-0.6c11-py2.7.egg/pkg_resources.py", line 565, in resolve
pkg_resources.DistributionNotFound: distribute
Google has failed me. Can anyone tell me how to resolve this error?

Resources