Installing Rasterio on Ubuntu fails with ImportError - python

I have an AWS EC2 p2.xlarge instance running on Ubuntu 16.04.4 LTS that was created using the AWS Deep Learning AMI (DLAMI). I am using the keras/Tensor Flow conda environment:
$ source activate tensorflow_p36
I am attempting to install Rasterio and GDAL on top of the Keras - Tensor Flow AMI installations using these commands (source):
$ sudo add-apt-repository ppa:ubuntugis/ppa
$ sudo apt-get update
$ sudo apt-get install python-numpy gdal-bin libgdal-dev
$ pip install rasterio
The GDAL install seems to work:
$ gdalinfo --version
GDAL 2.1.3, released 2017/20/01
However, when I try to import rasterio in Python, it yields the following error:
(tensorflow_p36) ubuntu#ip-171-11-7-03:~$ python
Python 3.6.4 |Anaconda, Inc.| (default, Jan 16 2018, 18:10:19)
[GCC 7.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import rasterio
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/ubuntu/anaconda3/envs/tensorflow_p36_test/lib/python3.6/site-packages/rasterio/__init__.py", line 15, in <module>
from rasterio._base import (
ImportError: /usr/lib/libgdal.so.20: undefined symbol: sqlite3_column_table_name
>>>
How can I clear this error so that I can import and use rasterio in Python?

I had a similar issue trying to import rasterio with GDAL 2.x installed. You should try to install GDAL 1.11 instead.

Related

How to install pyaudio module in the current version of python while having multiple versions of python installed?

I have installed multiple versions of python like 3.8.5 and 3.9.2 in my Linux Ubuntu system. I want to install pyaudio module in 3.9.2 version.
For this, I have used a command: pip3 install PyAudio and I am getting this error - error: Microsoft Visual C++ 14.0 is required.
I have also used python unofficial libraries and tried to install pyaudio but it shows this error -
ERROR: PyAudio-0.2.11-cp39-cp39-win_amd64.whl is not a supported wheel on this platform.
Then I used these commands for the same -
sudo apt-get install libasound-dev portaudio19-dev libportaudio2
libportaudiocpp0
sudo apt-get install ffmpeg libav-tools
sudo pip install pyaudio
After this when I import pyaudio module, it shows module not found error. But when I tried to re-install the module, it shows requirement already satisfied.
Then I executed the command:
sudo -s
python3
import pyaudio
Now it shows no error. It seems that pyaudio module has been installed in python 3.8.5 version and not in python 3.9.2 version. However, I used virtual environment of older python version and installed speech recognition, pyaudio which worked well.
I want to use pyaudio module without using virtual environment without any errors. Please help.
Here is the screenshot of the issueimage_pyaudio_issue
Here is the code -
maaz#maaz-HP-Notebook:~$ python
Python 2.7.18 (default, Mar 8 2021, 13:02:45)
[GCC 9.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
import pyaudio
Traceback (most recent call last):
File "", line 1, in
ImportError: No module named pyaudio
import PyAudio
Traceback (most recent call last):
File "", line 1, in
ImportError: No module named PyAudio
exit()
maaz#maaz-HP-Notebook:~$ sudo pip install pyaudio
[sudo] password for maaz:
Requirement already satisfied: pyaudio in /usr/lib/python3/dist-packages (0.2.11)
maaz#maaz-HP-Notebook:~$ sudo -s
[sudo] password for maaz:
root#maaz-HP-Notebook:/home/maaz# python3
Python 3.8.5 (default, May 27 2021, 13:30:53)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
import pyaudio
exit()
root#maaz-HP-Notebook:/home/maaz# exit
exit
Check in the usr/bin and usr/local/bin for all python instances.
The installation of python3 is probably linked to python 3.8.5. But there might be a python3.9.
You could check for other python instances in the above folders by running the below commands:
ls -ls /usr/bin/python*
ls -ls /usr/local/bin/python*
If so, you can run the commands with python3.9, but i would recommend cleaning up the unused installations.

Pip3 for Python3 in virtual environment not installing package according to path

I am trying to install packages in a Python3 virtual environment using pip3. Pip3 is pointing to the virtual environment when it is active.
Packages will not install, since they are installed outside of the virtual environment, already satisfied outside of the virtual environment.
How do I install packages in the virtual environment?
And how can I be sure that I am actually using the interpreter inside the virtual environment? When pip3 is not acting according to the location returned by 'which', I do can not be sure that the python I am using in fact is the one from the virtual environment.
(venv_name) user_name#user_name-ubuntu:/mnt/ramdisk$ which python3
/mnt/ramdisk/venv_name/bin/python3
(venv_name) user_name#name-ubuntu:/mnt/ramdisk$ which pip3
/mnt/ramdisk/venv_name/bin/pip3
(venv_name) user_name#name-ubuntu:/mnt/ramdisk$ sudo pip3 install pandas
Requirement already satisfied: pandas in /usr/local/lib/python3.6/dist-packages ...
(venv_name) user_name#name-ubuntu:/mnt/ramdisk$ python3
Python 3.7.5 (default, Oct 15 2019, 22:40:07)
[GCC 7.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> import pandas
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'pandas'
OS: UBUNTU 18.04
Solved by not using sudo. Sudo was used for access.

ModuleNotFoundError: No module named 'jpype'

I am using Anaconda Python and used the following to install jpype:
conda install -c conda-forge jpype1
I have GCC installed:
Python 3.6.1 |Anaconda 4.4.0 (x86_64)| (default, May 11 2017, 13:04:09)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
and I did not get any error during installation.
conda install -c conda-forge jpype1
Collecting package metadata: done
Solving environment: done
# All requested packages already installed.
If I run pip search jpype I will get the following:
jtypes.jpype (0.6.3b3) - A Python to Java bridge (ctypes/cffi-based JPype).
JPype1-py3 (0.5.5.2) - Python-Java bridge. Fork of the jPype project by Steve Menard (http://jpype.sourceforge.net/), with the modifications applied by Luis Nell
(https://github.com/originell/jpype)
but still cannot call the library
>>> import jpype
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'jpype'
It might be because it is installed as a Python 2 package and you're running Python 3 or the opposite.
To specifically install the package for Python 3, try entering this command:
pip3 install jpype1
or
python3 -m pip install jpype1
To specifically install the package for Python 2, try entering this command:
pip2 install jpype1
or
python -m pip install jpype1
I found the problem.
By mistake, I had two versions of Anaconda 3.6 and 3.7 which was causing the problem.

No module named 'pafy'

sudo pip3.6 install pafy
Collecting pafy
Downloading pafy-0.5.3.1.tar.gz
Installing collected packages: pafy
Running setup.py install for pafy ... done
Successfully installed pafy-0.5.3.1
It is Successfully installed pafy-0.5.3.1.
~$ python
Python 3.6.1 |Anaconda 4.4.0 (64-bit)| (default, May 11 2017, 13:09:58)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pafy
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'pafy'
Why no module named 'pafy'?
You ran pip as sudo but you're running python as normal user. Programs run as normal user don't have rights to access super-user's content (sudo).
To verify this, you can run python as super-user and try to import pafy.
$ sudo python
>>> import pafy
You should never use sudo pip install; you could overwrite important stuff.
Use pip install --user <packagename> or install and use virtualenv. I prefer virtualenv.
pip install pafy
This would work

No module named osgeo.ogr

I need to import osgeo.ogr module to virtualenv python program.
Global python has this module:
user#ubuntu:~/$ python
Python 2.7.8 (default, Oct 20 2014, 15:05:19)
[GCC 4.9.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import osgeo
>>>
But into virtualenv (without --no-site-packages):
user#ubuntu:~$ temp/bin/python
Python 2.7.8 (default, Oct 20 2014, 15:05:19)
[GCC 4.9.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import osgeo
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named osgeo
What is the reason for this behavior?
Able to solve with this one
pip install --global-option=build_ext --global-option="-I/usr/include/gdal" GDAL==`gdal-config --version`
Problem is solved in this way:
(VIRTUAL_ENV)user#ubuntu:~$ pip install --no-install GDAL==1.11.2
1.11.2 because my version GDAL is 1.11.2:
(VIRTUAL_ENV)user#ubuntu:~$ gdal-config --version
1.11.2
next:
(VIRTUAL_ENV)user#ubuntu:~$ cd ~/.virtualenvs/VIRTUAL_ENV/build/GDAL/
(VIRTUAL_ENV)user#ubuntu:~/.virtualenvs/VIRTUAL_ENV/build/GDAL$ python setup.py build_ext --include-dirs=/usr/include/gdal/
(VIRTUAL_ENV)user#ubuntu:~/.virtualenvs/bamap/build/GDAL$ pip install --no-download GDAL
--include-dirs=/usr/include/gdal/ for me is correct. GDAL was installed with Quantum GIS in my system. If you will build GDAL manually paths may be others. Full version:
python setup.py build_ext --gdal-config=/YOUR_PATH/bin/gdal-config --library-dirs=/YOUR_PATH/gdal/VERSION_GDAL/lib --libraries=gdal --include-dirs=/YOUR_PATH/gdal/VERSION_GDAL/include
Details may find here.
sudo add-apt-repository ppa:ubuntugis/ppa && sudo apt-get update
if you have facing the issue " Cannot import name '_gi' ":
visit this link to fix
sudo apt-get update
sudo apt-get install gdal-bin
sudo apt-get install libgdal-dev
export CPLUS_INCLUDE_PATH=/usr/include/gdal
export C_INCLUDE_PATH=/usr/include/gdal
pip install GDAL==$(gdal-config --version) --global-option=build_ext --global-
option="-I/usr/include/gdal"

Categories

Resources