Gdal will not import after several installs (Mac OSX) - python

Using Macports,
I've tried to install: gdal, py27gdal, and gdal-grass. All so I can import gdal into python 2.7.2.
Neither have been successful.
When I type:
port list installed
I see the installed modules:
gdal-grass #1.4.3 gis/gdal-grass
gdbm #1.8.3 databases/gdbm
py27-gdal #1.7.1 python/py27-gdal
And when I run python to import the module:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named gdal
What am I doing wrong?

Are you using the MacPorts python2.7? Try launching Python this way:
/opt/local/bin/python2.7

I'm not 100% sure if this solves your problem, but gdal is in the osgeo namespace. So you should try importing gdal like this:
from osgeo import gdal
The gdal namespace itself is deprecated.

Related

How to install missing wx module on Python 2.5?

I have developped a tool under python 2.5 and can't upgrade to a newer python version as I need to use an API developped under python 2.5 as well.
I recently tried my tool under another machine and it seems it hasn't wx module installed as you can see below:
>>> import wx
Traceback (most recent call last):
File "<interactive input>", line 1, in <module>
ImportError: No module named wx
So I searched for the wxpython source. However once I tried to install the source with:
D:\tmp\wxPython-4.0.0b2>c:\Python25\python.exe setup.py install
I got following error:
Traceback (most recent call last): File "setup.py", line 15, in
from setuptools import setup, find_packages ImportError: No module named setuptools
I can't either install whl files as I don't have pip.
So, how can I install wxpython for python 2.5 under Windows?
Is there any executable there in the web that I couldn't find? May there be a workaround by copying the wx module from a python directory from another computer?
As I had to install wxpython 2.7.2.0 I finally got it from wxPython2.7-win32-ansi-2.7.2.0-py25.exe.
As stated in Patrick's comment all wxpython executables for any version are under https://sourceforge.net/projects/wxpython/files/wxPython/

Mac reinstall Python

I tried to use the Coursera course downloader from here and it worked for few courses but not all. They have recommended to use Python3.X. So I uninstalled Anaconda (version 2) from my Mac and installed Python3.5.1 from Python's website but still the course downloaders did not work as it was using default Python 2.7.
So I deleted Python from /usr/local/lib and now nothing is working. When I do which python it shows ``usr/local/bin/pythonand bothpythonandpython3` runs.
But when I do pip install coursera it throws error as follows:
Traceback (most recent call last):
File "/usr/local/bin/pip", line 5, in <module>
from pkg_resources import load_entry_point
ImportError: No module named pkg_resources
And when I do sudo easy_install pip, I get the following error.
Traceback (most recent call last):
File "/usr/local/bin/easy_install", line 5, in <module>
from pkg_resources import load_entry_point
ImportError: No module named pkg_resources
try Homebrew http://brew.sh/
brew install python3
curl bootstrap.pypa.io/get-pip.py | python3
Your Mac should have Python 2 and Python 3 installed by default. in the terminal "python" will launch Python2, "python3" will launch Python3. With Anaconda you could have just kept the Python 2 version and created an environment for Python 3, http://conda.pydata.org/docs/using/envs.html#managing-environments.
This is the solution you will most likely need, No module named pkg_resources. Setuptools is causing the issue and you will need to wget ez_setup.py. Reinstalling Anaconda will save you a lot of time and pain.

Python Basemap/Matplotlib Install

I am trying to install the base map for use with matplotlib python v2.7 running on Mac OSX Mavericks. I have all the latest versions of all modules (matplotlib, etc) running using anaconda, but keep getting the following error:
Traceback (most recent call last):
File "simpletest.py", line 1, in <module>
from mpl_toolkits.basemap import Basemap
File "/Users/felishalawrence/anaconda/lib/python2.7/site-packages/mpl_toolkits/basemap/__init__.py", line 37, in <module>
import _geoslib.so
ImportError: dlopen(/Users/felishalawrence/anaconda/lib/python2.7/site-packages/_geoslib.so, 2): Library not loaded: libgeos_c.1.dylib
Referenced from: /Users/felishalawrence/anaconda/lib/python2.7/site-packages/_geoslib.so
Reason: no suitable image found. Did find:
/usr/local/bin/gcc-4.9/libgeos_c.1.dylib: stat() failed with errno=20
Can someone please give me an idea of what is wrong? Thanks!
Try installing the following packages with Homebrew:
brew install numpy
brew install proj
brew install geos
export GEOS_DIR="/usr/local/Cellar/geos/3.10.3/"

How to use gexiv2 in python?

I just compiled exiv2 and gexiv2 for my debian machiene and now I want to start working with gexiv2 to edit IPTC data using python. The gexiv2 website presents the following line of code:
from gi.repository import GExiv2
But that already results in:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named gi.repository
I can't even import gi so I think I'm missing another package!? What do I have to do to make this work as expected?
UPDATE: I upgraded my OS to the newest debian version. I can import gi now, but I'm still having trouble with GExiv2.
The following error occurs when importing GExiv2:
>>>from gi.repository import GExiv2
ERROR:root:Could not find any typelib for GExiv2
Hi i had the same problem i fixed it by installing gir1.2-gexiv2-0.4
I believe the package you need is python3-gi or, if you're using Python 2, python-gi.
Same problem here, I solved it by installing gir1.2-gexiv2-0.4 AND python-gobject

Numpy and OpenCV

I'm tired to import cv and numpy and get errors. I started importing cv and I got this error:
ImportError: numpy.core.multiarray failed to import
Traceback (most recent call last):
File "", line 1, in <module>
File "/usr/lib/pymodules/python2.7/cv.py", line 1, in <module>
from cv2.cv import *
ImportError: numpy.core.multiarray failed to import
So I installed numpy on Ubuntu using:
apt-get install python-numpy
So when I import numpy I get:
Traceback (most recent call last):
File "", line 1, in <module>
File "numpy/init.py", line 127, in <module>
raise ImportError(msg)
ImportError: Error importing numpy: you should not try to import numpy from
its source directory; please exit the numpy source tree, and relaunch
your python intepreter from there.
I really need help. I'm using Python 2.7.3 on Ubuntu.
There is nothing wrong with installing common dependencies using your operating system's package manager, remember using pip means your synaptic updates won't update your Python libraries and pip won't leverage the dependencies already taken care of by aptitude. For python packages with C extensions like numpy and opencv its probably better to use apt-get.
In Ubuntu you can install both dependencies with
sudo apt-get install python-numpy python-opencv
The actual Python error you are getting indicates what is wrong, namely that you are executing from within the numpy source directory, or have a file named numpy.py in your current directory which is confusing things at import time. Try change into an empty directory, start Python import your libraries:
import numpy
import cv
Hope that helps.
It's better that use some package management tool such like pip to install numpy.
For example,
pip install numpy

Categories