rasterio and gdal DLL load fail in PyCharm - python

I have a conda environment with rasterio installed and a whole load of other libraries, including gdal.
When I do:
import rasterio
on jupyter notebook, it loads fine and I can utilise it's methods etc..
When I do exactly the same thing on PyCharm, with the same environment and interpreter, I can the following error:
from rasterio._base import gdal_version
ImportError: DLL load failed: The specified module could not be found.
I'm struggling to understand why this is the case, as it loads fine in jupter notebook.

I encountered the same problem as you and has finished solving it.
First, You need to ensure that gdal version is still 2.x. If no, just remove it.
conda remove rasterio gdal -y
then reinstall gdal with specifying the installation version:
conda install rasterio gdal=2 -y
Then, you need add GDAL_DATA which containing a gcs.csv file to environment,
for me in Windows:
setx /m GDAL_DATA C:\Users\Admin\AppData\Local\ESRI\conda\envs\python3\Library\share\gdal
reboot your computer, and import gdal before importing rasterio:
In [1]: import rasterio
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-1-350e27267e59> in <module>
----> 1 import rasterio
~\AppData\Local\ESRI\conda\envs\python3\lib\site-packages\rasterio\__init__.py in <module>
20 pass
21
---> 22 from rasterio._base import gdal_version
23 from rasterio.drivers import is_blacklisted
24 from rasterio.dtypes import (
ImportError: DLL load failed: 找不到指定的模块。
In [2]: from osgeo import gdal
In [3]: import rasterio

Related

Fixing "DLL load failed: The specified module could not be found." error in python for importing rasterio

I am trying to download the package rasterio for analyzing raster datasets in python within the geospatial analysis disciplines.
I have downloaded the package dependencies for rasterio, including gdal, pyproj, and fiona via the wheel files from this geospatial analysis binaries resource: https://www.lfd.uci.edu/~gohlke/pythonlibs/
I installed these packages through pip.
I then downloaded from this resource the wheel file rasterio through pip.
I received the following message from Window Command Prompt after installing rasterio: Successfully installed affine-2.3.0 numpy-1.21.4 pyparsing-3.0.6 rasterio-1.2.10 snuggs-1.4.7.
I want to use this package in Jupyter Notebook, and so I open a Jupyter Notebook file and run import rasterio, and receive this error message:
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-17-350e27267e59> in <module>
----> 1 import rasterio
~\Anaconda3\lib\site-packages\rasterio\__init__.py in <module>
15 from pathlib import Path
16
---> 17 from rasterio._base import gdal_version
18 from rasterio.drivers import driver_from_extension, is_blacklisted
19 from rasterio.dtypes import (
ImportError: DLL load failed: The specified module could not be found.
How can I address this "DLL load failed" issue and address this error so that I can use rasterio? I was told this could be an issue of not having Visual C++ installed on my computer, and so I installed Visual Studio 2022 on my computer, but this did not help.
I solved this problem with the following steps:
I created a fresh environment
I installed the gdal library (since rasterio is built on top of it), with the command:
conda install -c conda-forge gdal
I installed rasterio with the command:
conda install -c conda-forge rasterio

Getting an Import Error when importing rasterio

I have been having trouble installing Rasterio, finally got that installed, but now I am getting an error on the import in Spyder. Below is the console output for the error.
runfile('C:/Users/eolson/untitled0.py', wdir='C:/Users/eolson')
Traceback (most recent call last):
File "C:\Users\eolson\untitled0.py", line 9, in
import rasterio
File
"C:\Users\eolson\Anaconda3\lib\site-packages\rasterio__init__.py",
line 22, in
from rasterio._base import gdal_version
ImportError: DLL load failed: The specified procedure could not be
found.
Create a new environment in anaconda, then follow the instructions here:
In the anaconda command prompt:
conda config --add channels conda-forge
conda install rasterio

Used "pip3 install" to successfully installed "pytesseract", but when I try to import it at Jupyter Notebook, it failed on me

Once again, the "pip3 install" was successful
This is what the error message looks like:
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-1-fb370059137a> in <module>
1 from PIL import Image
----> 2 import pytesseract
3 import sys
4 from pdf2image import convert_from_path
5 import os
ModuleNotFoundError: No module named 'pytesseract'
check which pip you are using for installation and also see where your Jupyter Notebook is reading from.
1- In the terminal (outside Jupyter), make sure that you can import the package. Note the path of your Python.
2- When in Jupyter Notebook, find your Python path with the following command and make sure they match:
import sys
print(sys.executable)
If the problem was not a PATH issue (which it seems it is!), you should figure out why it's not installed correctly.
Try installing Pillow package along with the pytesseract package
pip install pytesseract Pillow

Spyder not finding modules installed with anaconda

I have a newly installed Anaconda and tried to run an old code that uses scipy, numpy and os using Spyder 3.2.6. and get an error. When trying to import numpy from the IPythoin console I get
import numpy as np
Traceback (most recent call last):
File "<ipython-input-4-0aa0b027fcb6>", line 1, in <module>
import numpy as np
ModuleNotFoundError: No module named 'numpy'
The os module however does get imported and works. I tried running python importing both scipy and numpy and I don't have any issue. I'm running just one Anaconda environment, so there's no mistake there.
Assuming you're using Anaconda Prompt:
Try installing Spyder into that environment via "conda install spyder", and then run spyder from that environment via "spyder".
I had the same issue. I just wrote this line in Anaconda Prompt instead of OS command prompt:
pip install <module>
It's obvious that <module> will be replaced by the desired module name.

PIL installation on anaconda for windows 10, 64 bit

when I ran conda-forge to get xgboost running, it seems to have affected few running packages, one of them being PIL. It was running properly until I ran conda-forge, but now I am getting the following error.
ImportError Traceback (most recent call last)
<ipython-input-3-588a23339ee5> in <module>()
5 import matplotlib.pyplot as plt
6 import scipy
----> 7 from PIL import Image
8 #from pillow import Image
9 from scipy import ndimage
C:\Anaconda3\lib\site-packages\PIL\Image.py in <module>()
54 # Also note that Image.core is not a publicly documented interface,
55 # and should be considered private and subject to change.
---> 56 from . import _imaging as core
57 if PILLOW_VERSION != getattr(core, 'PILLOW_VERSION', None):
58 raise ImportError("The _imaging extension was built for another "
ImportError: DLL load failed: The specified module could not be found.
when I try to install PIL again using conda install pil, I get the following error message
(C:\Anaconda3) C:\Users\P Srinivasa Rao>conda install pil
Fetching package metadata ...............
Solving package specifications: .
UnsatisfiableError: The following specifications were found to be in conflict:
- pil -> python 2.6*
- python 3.6*
Use "conda info <package>" to see the dependencies for each package.
I then installed pillow, which seems to have gone well. But when I run from PIL import image, I still get the same error as above. I tried from pillow import image, it says no module found named pillow
Any advice on how to resolve this issue and get PIL working again?
I am using anaconda3 on windows 10, 64bit.
The problem looks like you have both pythons 2.x versions and a 3.x version. try the following
create a conda environment with python 3.6
conda create -n pil-env python=3.6
load PIL
conda install Pillow==4.0.0
I found Pillow 4.0.0 to be the most stable while using it on 3.6

Categories

Resources