Installing RasterIO with pyenv - python

RasterIO appears to be a very promising library for geospatial IO and much easier for me to navigate than gdal's python bindings. I am having trouble installing it correctly.
Currently, I have am using pyenv and pyenv-virtualenv to manage python distributions and environments, respectively. I installed gdal with brew using the following steps.
I navigated to my project folder, activated the virtual environment and downloaded rasterio from PyPI: pip install rasterio. However, the only way to correctly import the package is to import osgeo first?!? I am concerned that this means I have some broken dependencies or I have installed rasterio incorrectly.
Specifically,
import osgeo
import rasterio
works fine (tested using with about half of their quickstart), but
import rasterio
does not. The latter producing:
Traceback (most recent call last):File "<string>", line 1, in <module>
File "/Users/home/.pyenv/versions/virtual_env_name/lib/python3.6/site-packages/rasterio/__init__.py", line 15, in <module>
from rasterio._base import (
ImportError: dlopen(/Users/home/.pyenv/versions/virtual_env_name/lib/python3.6/site-
packages/rasterio/_base.cpython-36m-darwin.so, 2): Symbol not found: _CPLMalloc
Referenced from: /Users/home/.pyenv/versions/virtual_env_name/lib/python3.6/site-packages/rasterio/_base.cpython-36m-darwin.so
Expected in: flat namespace in /Users/home/.pyenv/versions/virtual_env_name/lib/python3.6/site-packages/rasterio/_base.cpython-36m-darwin.so
Any suggestions on how to debug/interpret this error would be invaluable to me. Thanks!
If possible, I would prefer not build from source per these instructions.

Related

No module named pandas but pandas is already installed in linux

I have two python distributions(python2.7,python3.6) and in both I have installed pandas and numpy as well but cant use
These are the errors caused when i tried to import pandas
in python 2.7
File "/usr/local/lib/python2.7/dist-packages/pandas/init.py", line 19, in
"Missing required dependencies {0}".format(missing_dependencies))
ImportError: Missing required dependencies ['numpy']
then imported numpy
ImportError:
Importing the multiarray numpy extension module failed. Most
likely you are trying to import a failed build of numpy.
If you're working with a numpy git repo, try git clean -xdf (removes all
files not under version control). Otherwise reinstall numpy.
Original error was: cannot import name multiarray
in python 3.6
Traceback (most recent call last):
File "", line 1, in
ModuleNotFoundError: No module named 'pandas'
Most of these cases, the problem is that you are installing pandas in another environment. The easy solution here is using Anaconda.
Anaconda is focused on environments. First, you should choose installation of python2 or python3. Then, you can install this version of Anaconda in Linux: https://www.anaconda.com/download/#linux
For example:
64-Bit (x86) Installer (622 MB) Python3:
$ wget https://repo.anaconda.com/archive/Anaconda3-5.2.0-Linux-x86_64.sh
Then you need, install in your system:
$ bash Anaconda3-5.2.0-Linux-x86_64.sh
Be cautious in the interactive dialog in order to install Anaconda. Remember the route of the installation.
When you have Anaconda in a folder named: anaconda 3 (for example). go to route: .../anaconda3/bin.
Now, you should execute:
$ source activate
Now you are in base environment, you can install the packages that you need (pandas and numpy are install by default). However, I recommend you create a new environment for each new proyect (see https://conda.io/docs/_downloads/conda-cheatsheet.pdf).
Imagine that you have (base) environment. In this environment try:
$ python
The first message gives you the python version. Anyway you can try:
>>> import sys
>>> sys.version
In order to know the version that you are using.

ImportError in Python

I tried to execute a program using geonames_rdf, but I cant execute it by this error:
Traceback (most recent call last):
File "geo1.py", line 13, in <module>
import geonames.config.log
ImportError: No module named config.log
I read several posts abot ImportError and I check the path of the system and it is correct. I'm working in a VirtualBox with a fresh Ubuntu 16.04.
The imports of my program are:
import sys
import os
import os.path
import logging
import geonames.config.log
import geonames.compat
import geonames.adapters.search
I've also tried add this line:
sys.path.append('/usr/local/lib/python2.7/dist-packages/geonames/')
The command that I used to instal this package was
sudo pip install geonames_rdf
Try appending site-packages not dist-packages. A bit of searching it looks like dist-packages is debian specific.
sys.path.append('/usr/local/lib/python2.7/site-packages/geonames/')
Reason:
Since you're installing 3rd party python package via pip it will not go into dist-packages and python rightfully cannot find it on the path.
Reference link:
What's the difference between dist-packages and site-packages?
I just tried to use geonames_rdf, but I didn't know I needed it to do a geonames search so I installed geonames first, then discovered I had to install fiona and gdal (I'm on Windows, had to install these two using prebuilt whl from http://www.lfd.uci.edu/~gohlke/pythonlibs/). Don't know why these dependencies aren't baked into geonames.
Anyway once I then installed geonames_rdf it seemed to install into the geonames folder in c:\Python27\lib\site-packages, added at least the adapters package. In c:\Python27\lib\site-packages\geonames there is a config folder with log.py in it.

Anaconda not able to import the packages like numpy, scipy, theano etc

Without installing Anaconda, everything works fine.
That is, I am able to import the above mentioned packages. But after installing Anaconda, I am not able to import the same packages. Here is the error which I get: -
>>> import numpy
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/numpy/__init__.py", line 199, in <module>
from . import random
File "/usr/local/lib/python2.7/dist-packages/numpy/random/__init__.py", line 99, in <module>
from .mtrand import *
ImportError: /usr/local/lib/python2.7/dist-packages/numpy/random /mtrand.so: undefined symbol: PyFPE_jbuf
Once you install the Anaconda distribution it appends the .bashrc paths with the location of the anaconda/bin.
This means that any python packages installed in the /usr/local/ may not be importable.
I second the suggestion above and recommend using virtual environments to do your work. The Anaconda Python distribution comes with conda package management. This may make your life easier.
You can create a new environments and install packages not provided by the distribution using conda build(http://conda.pydata.org/docs/build_tutorials.html)
Also look at pip and python wheel.

How do I install Matplotlib as a Macintosh Yosemite User

I am a Macintosh Yosemite user. When I try to import matplotlib I get the following error.
import matplotlib
Traceback (most recent call last):
File "<pyshell#11>", line 1, in <module>
import matplotlib
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/matplotlib/__init__.py", line 180, in <module>
from matplotlib.cbook import is_string_like
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/matplotlib/cbook.py", line 33, in <module>
import numpy as np
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/numpy/__init__.py", line 170, in <module>
from . import add_newdocs
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/numpy/add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/numpy/lib/__init__.py", line 8, in <module>
from .type_check import *
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/numpy/lib/type_check.py", line 11, in <module>
import numpy.core.numeric as _nx
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/numpy/core/__init__.py", line 6, in <module>
from . import multiarray
ImportError: cannot import name 'multiarray'
When I use from pylab import axis that would work just fine. I do not know what is going on and I am just so lost. I have tried using homebrew, macports installs, dmg installs. I also have very little experience installing things through terminal so I just followed what other people said. Though, that is still not working.
Mac OS X ships with python by default. And there is one provided by homebrew. I would recommend using homebrew python over the default python.
Here, I suspect your numpy installation has landed up in the site-packages directory managed by the non-homebrew pip package manager whereas matplotlib package is installed in a different site-packages directory. (But I am not sure). Nevertheless it has something to do with multiple python's / package managers being used. This may not be the best answer, but so far the only solution I can think of to fix your problems is to uninstall pip and also remove everything in any python site-packages directory you can find on your filesystem,. And install python via homebrew again, and then install all packages required using the pip (which gets installed automatically when you install python using homebrew)
Warning: Make sure you list out the package names and store the names somewhere before deleting them because you will have to install them again.
brew uninstall python
#(ATTN) Uninstall macports and don't use it with brew
#(ATTN) Delete the contents of all python site-packages directories
rm /usr/local/lib/python2.7/site-packages/*
brew install python
# Homebrew comes with its own pip installed
pip install <package1>, <package2> ...
Here is a related question from someone who faced a similar problem:
Numpy build fails with cannot import multiarray
My advice: Don't use Homebrew and Macports or any other package manager together. They mess up with each other and I have faced the consequences in the past.I just use homebrew python now. For installing scientific python packages either Anaconda or Canopy (choose one) are really helpful, which can be installed on top of the homebrew python.
After having a lot of problems similar to the ones you describe, using sudo pip install -U matplotlib worked fine for me.

scikits.audiolab doen't import into python (numpy.dtype)

I have installed (with lots of troubles) scikits.audiolab for making sounds out of data. Now when I type:
import scikits.audiolab I get the following error
>>> import scikits.audiolab
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Python/2.7/site-packages/scikits.audiolab-0.11.0-py2.7-macosx-10.7-intel.egg/scikits/audiolab/__init__.py", line 25, in <module>
from pysndfile import formatinfo, sndfile
File "/Library/Python/2.7/site-packages/scikits.audiolab-0.11.0-py2.7-macosx-10.7-intel.egg/scikits/audiolab/pysndfile/__init__.py", line 1, in <module>
from _sndfile import Sndfile, Format, available_file_formats, \
File "numpy.pxd", line 30, in scikits.audiolab.pysndfile._sndfile (/private/tmp/easy_install-gKE3i5/scikits.audiolab-0.11.0/scikits/audiolab/pysndfile/_sndfile.c:9632)
ValueError: numpy.dtype does not appear to be the correct type object
How do I fix this?
Any alternative package that can do the job?
I had the same issue and for me it was caused by installing another (more recent) version of NumPy.
Check if you have different versions of NumPy installed and try switching back to an older one. For my part: I had a system-wide installation of Python and common modules like NumPy, which I couldn't touch because I'm not admin on that system. So when I installed some other library locally (in ~/.local/lib/python2.7/) it would also install more recent versions of SciPy and NumPy and put them into that local folder. And when importing the module it would draw from the local directory first before looking at the system-wide libraries which were working fine before with scikits.audiolab. So for me it was solved by
pip uninstall numy && pip uninstall scipy because that only deleted the newer local versions of numpy.
But more specific to your case, here is a tutorial how (on a Mac) to switch to a certain version of NumPy:
multiple numpy version on Mac OS X
The NumPy version I found working for my scikits.audiolab is 1.6.1
>>> import numpy
>>> numpy.version.version
'1.6.1'
Hope that helps. :)
Maybe you installed/upgraded numpy after installing talkbox. Try running this command:
pip install --upgrade --force-reinstall scikits.talkbox
As suggested here:
https://github.com/ppwwyyxx/speaker-recognition/issues/13

Categories

Resources