No module named osgeo.ogr - python

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"

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.

Install google-auth in raspberry (Python)

I'm installing google-auth on raspberry pi 3 using pip:
pip install google-auth
pip install --upgrade google-auth
But when I used import google.auth, I get the following error No module named 'google.auth'
(env) pi#raspberrypi:~/Desktop $ python
Python 3.5.3 (default, Sep 27 2018, 17:25:39)
[GCC 6.3.0 20170516] on linu
Type "help", "copyright", "credits" or "license" for more information
>>> import google.auth
Traceback (most recent call last)
File "<stdin>", line 1, in <module
ImportError: No module named 'google.auth
If you have installed pip by sudo,then try installing it using:
sudo pip install google-auth

Installing Rasterio on Ubuntu fails with ImportError

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.

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

can not import MySQLdb after I installed it in a virtualenv

system:ubuntu14.04, mysql:5.5, python:2.7.4
I have installed mysql-connector-python outside of a virtualenv using this command:
pip install mysql-connector-python --allow-external mysql-connector-python
I can use mysql-connector correctly outside of the virtualenv:
think#think-Inspiron-N4050:~$ python
Python 2.7.6 (default, Jun 22 2015, 18:00:18)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import mysql.connector
>>>
>>>
then I activated a virtualenv and installed the mysql-connector. I used this method(I downloaded this install package from the offical website):
think#think-Inspiron-N4050:~/myzone/MindFly$ source venv/bin/activate
(venv)think#think-Inspiron-N4050:~/myzone/MindFly$ cd ~/download/
(venv)think#think-Inspiron-N4050:~/download$ dpkg -i mysql-connector-python_2.0.4-1ubuntu14.04_all.deb
After installed it correctly, I can not import it:
(venv)think#think-Inspiron-N4050:~/download$ python
Python 2.7.6 (default, Jun 22 2015, 18:00:18)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import mysql.connector
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named mysql.connector
I don't know why, then I had to install MySQLdb inside the virtualenv:
(venv)think#think-Inspiron-N4050:~/myzone/MindFly$ sudo apt-get install python-mysqldb
after finished it, I can not import it too
(venv)think#think-Inspiron-N4050:~/myzone/MindFly$ python
Python 2.7.6 (default, Jun 22 2015, 18:00:18)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import MySQLdb
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named MySQLdb
then I installed MySQL-python and libmysqlclient-dev, it alse didn't work.
then I looked over the venv/lib/python2.7/site-packages:
(venv)think#think-Inspiron-N4050:~/myzone/MindFly/venv/lib/python2.7/site-packages$ ls
easy_install.py pip-7.1.2.dist-info wheel
easy_install.pyc pkg_resources wheel-0.24.0.dist-info
_markerlib setuptools
pip setuptools-18.2.dist-info
there are not mysql-connector or mysqldb, I find mysqlconnector in /usr/lib/python2.7/dist-packages when I tried to reinstall mysqlconnector,
(venv)think#think-Inspiron-N4050:~/myzone/MindFly$ sudo pip install mysql-connector-python --allow-external mysql-connector-python
[sudo] password for think:
Requirement already satisfied (use --upgrade to upgrade): mysql-connector-python in /usr/lib/python2.7/dist-packages
Cleaning up...
I really don't know how to do after I install mysql-connector-python,mysqldb,mysql-python and libmysqlclient-dev. I can use them outside of the virtualenv, but I still can not import mysql-connector nor mysqldb in virtualenv.
Please help me: how can I connect mysql in virtualenv? thanks very much. (if the expression is not clear, tell me and I will update it,thanks)
then I activated a virtualenv and installed the mysql-connector (...)
dpkg -i mysql-connector-python_2.0.4-1ubuntu14.04_all.deb
(...)
then I had to install MySQLdb inside the virtualenv:
sudo apt-get install python-mysqldb
Err... apt-get and dpkg are your distrib's package manager, this has nothing to do with pip and virtualenv. Your distrib's package manager installs system packages (.deb in your case) and install them system-wide. The point of virtualenv is to install python packages (with pip) in an isolated "virtual" environnement. What you want is:
# source path/to/your/venv/bin/activate
# pip install your-python-package
Note that all this is documented in virtualenv and pip...

Categories

Resources