Why can't I import folium python package? - python

I've pip installed folium and get this error when I try to import it in when Im working in my home directory:
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-1-af6e4f19ef00> in <module>()
----> 1 import folium
//anaconda/lib/python2.7/site-packages/folium-0.3.0.dev0- py2.7.egg/folium/__init__.py in <module>()
3 from __future__ import absolute_import
4
----> 5 from folium.folium import Map, initialize_notebook, CircleMarker
6
7 from folium.map import (FeatureGroup, FitBounds, Icon, LayerControl, Marker,
//anaconda/lib/python2.7/site-packages/folium-0.3.0.dev0- py2.7.egg/folium/folium.py in <module>()
13 import json
14
---> 15 from branca.colormap import StepColormap
16 from branca.utilities import color_brewer
17 from branca.six import text_type, binary_type
ImportError: No module named branca.colormap
However, i can import it when I cd to /Library/Python/2.7/site-packages.... What gives?

Did you install the package with Anaconda? It looks like it's reading the package from Anaconda python's package install locations. A few things to try:
conda install branca
pip install branca

Related

torchtext ImportError in colab

I am trying to run this tutorial in colab.
However, when I try to import a bunch of modules:
import io
import torch
from torchtext.utils import download_from_url
from torchtext.data.utils import get_tokenizer
from torchtext.vocab import build_vocab_from_iterator
It gives me the errors for extract_archive and build_vocab_from_iterator:
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-5-a24e72502dbc> in <module>()
1 import io
2 import torch
----> 3 from torchtext.utils import download_from_url, extract_archive
4 from torchtext.data.utils import get_tokenizer
5 from torchtext.vocab import build_vocab_from_iterator
ImportError: cannot import name 'extract_archive'
ImportError Traceback (most recent call last)
<ipython-input-4-02a401fd241b> in <module>()
3 from torchtext.utils import download_from_url
4 from torchtext.data.utils import get_tokenizer
----> 5 from torchtext.vocab import build_vocab_from_iterator
6
7 url = 'https://s3.amazonaws.com/research.metamind.io/wikitext/wikitext-2-v1.zip'
ImportError: cannot import name 'build_vocab_from_iterator'
Please help me with this one.
You need to upgrade torchtext first
!pip install -U torchtext==0.8.0
Currently, version 0.8.0 works with torch 1.7.0 (no need to upgrade torch, torchvision)
Update (sep 2021)
Currently, torchtext is already 0.10.0 and you don't need to upgrade anything.
Update December 2021
!pip install -U torchtext==0.10.0
torchtext.data becomes torchtext.legacy.data
use:
from torchtext.legacy.data import Field, TabularDataset, BucketIterator, Iterator
credit
You can use:
pip install -U torchtext==0.6.0
if 0.8 version is not available
This might help solve your problem:
conda install -c pytorch torchtext==0.8

How to install python package 'rpy2' in Databricks?

I am trying to install and utilize pymer4 package functionalities in Databricks which requires rpy2 to be installed as well. Under Library in the Cluster I am able to install them, it even says "Installed", but when I try to import them then it gives error, as if it was not installed properly. In local system it works perfectly.
from pymer4.test_install import test_install
Error is:
ImportError: No module named 'pandas.core.dtypes'
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<command-2946392196605768> in <module>()
----> 1 from pymer4.test_install import test_install
/databricks/python/lib/python3.5/site-packages/pymer4/__init__.py in <module>()
6 "__version__"]
7
----> 8 from .models import Lmer, Lm
9 from .simulate import (easy_multivariate_normal,
10 simulate_lm,
/databricks/python/lib/python3.5/site-packages/pymer4/models.py in <module>()
2 import rpy2.robjects as robjects
3 from rpy2.robjects.packages import importr
----> 4 from rpy2.robjects import pandas2ri
5 import rpy2
6 from copy import copy
/databricks/python/lib/python3.5/site-packages/rpy2/robjects/pandas2ri.py in <module>()
14 from pandas.core.series import Series as PandasSeries
15 from pandas.core.index import Index as PandasIndex
---> 16 from pandas.core.dtypes.api import is_datetime64_any_dtype
17 import pandas
18 import numpy
ImportError: No module named 'pandas.core.dtypes'
Was able to solve my own problem. It was nothing but version issues of dependent packages of pymer4 package.
Changed the version of following packages with the latest one prior to release date of pymer4 and it worked:
matplotlib==3.0.2
pandas==0.23.4
rpy2==2.9.4
tzlocal

Installing Geopandas undoes Jupyter installation

I installed qtconsole using conda and the command conda install qtconsole. Then I was able to open up the console by typing the following command
jupyter qtconsole
Later on I found that I needed the geopandas package and I installed it by doing:
conda install geopandas
This however broke the qtconsole installation such that when I type in jupyter qtconsole in cmd no console appears. Then I thought I would update qtconsole to bring it back by doing conda update qtconsole. This worked (ie I got the console to work again). However when I try to import the geopandas package in it I get the error
ImportError
Traceback (most recent call last)
<ipython-input-1-fc7d1d298f0c in <module ()
----> 1 import geopandas
~\AppData\Local\Continuum\miniconda3\envs\mynewenv\lib\site-packages\geopandas\__init__.py
in <module ()
2 from geopandas.geodataframe import GeoDataFrame
3
----> 4 from geopandas.io.file import read_file
5 from geopandas.io.sql import read_postgis
6 from geopandas.tools import sjoin
~\AppData\Local\Continuum\miniconda3\envs\mynewenv\lib\site-packages\geopandas\io\file.py
in <module ()
1 import os
2
----> 3 import fiona
4 import numpy as np
5 import six
~\AppData\Local\Continuum\miniconda3\envs\mynewenv\lib\site-packages\fiona\__init__.py
in <module ()
67 from six import string_types
68
---> 69 from fiona.collection import Collection, BytesCollection, vsi_path
70 from fiona._drivers import driver_count, GDALEnv
71 from fiona.drvsupport import supported_drivers
~\AppData\Local\Continuum\miniconda3\envs\mynewenv\lib\site-packages\fiona\collection.py
in <module ()
7
8 from fiona import compat
----> 9 from fiona.ogrext import Iterator, ItemsIterator, KeysIterator
10 from fiona.ogrext import Session, WritingSession
11 from fiona.ogrext import (
ImportError: DLL load failed: The specified module could not be found.
It seems like qtconsole cannot coexist with geopandas. This seems strange. How do I fix this?

ImportError: libgeos-3.6.2.so: cannot open shared object file: No such file or directory

I installed mpl_toolkits.basemap yet it is still not working. In ipython I am trying:
In [1]: from mpl_toolkits.basemap import Basemap
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-1-d9467465a3b6> in <module>()
----> 1 from mpl_toolkits.basemap import Basemap
/usr/local/lib/python2.7/dist-packages/mpl_toolkits/basemap/__init__.py in <module>()
37 import numpy as np
38 import numpy.ma as ma
---> 39 import _geoslib
40 import functools
41
ImportError: libgeos-3.6.2.so: cannot open shared object file: No such file or directory
Still not working. Help.
I got the same error when trying to install PostGIS. Installing the following fixed the error for me
sudo apt-get install binutils libproj-dev gdal-bin
Once I had a similar error. I fixed it finding the location of the library. In my case the location was different that where all my libs where, so I moved it to the correct folder and it worked.

Error in importing geopandas

I am getting the following error when importing
import geopandas as gpd
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-3-f8b81fe8ca07> in <module>()
----> 1 import geopandas as gpd
//anaconda/lib/python2.7/site-packages/geopandas/__init__.py in <module>()
2 from geopandas.geodataframe import GeoDataFrame
3
----> 4 from geopandas.io.file import read_file
5 from geopandas.io.sql import read_postgis
6 from geopandas.tools import sjoin
//anaconda/lib/python2.7/site-packages/geopandas/io/file.py in <module>()
1 import os
2
----> 3 import fiona
4 import numpy as np
5 from shapely.geometry import mapping
//anaconda/lib/python2.7/site-packages/fiona/__init__.py in <module>()
67 from six import string_types
68
---> 69 from fiona.collection import Collection, BytesCollection, vsi_path
70 from fiona._drivers import driver_count, GDALEnv
71 from fiona.drvsupport import supported_drivers
//anaconda/lib/python2.7/site-packages/fiona/collection.py in <module>()
6 import warnings
7
----> 8 from fiona import compat
9 from fiona.ogrext import Iterator, ItemsIterator, KeysIterator
10 from fiona.ogrext import Session, WritingSession
ImportError: cannot import name compat
I have installed geoPandas using anaconda however when I am trying to run it is displaying me the above error. When running
conda list
I am getting
After the runnning of the following:
conda install -c conda-forge fiona shapely pyproj rtree
conda install pandas
conda install -c conda-forge geopandas
I am getting
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-2-f8b81fe8ca07> in <module>()
----> 1 import geopandas as gpd
//anaconda/lib/python2.7/site-packages/geopandas/__init__.pyc in <module>()
2 from geopandas.geodataframe import GeoDataFrame
3
----> 4 from geopandas.io.file import read_file
5 from geopandas.io.sql import read_postgis
6 from geopandas.tools import sjoin
//anaconda/lib/python2.7/site-packages/geopandas/io/file.py in <module>()
1 import os
2
----> 3 import fiona
4 import numpy as np
5 from shapely.geometry import mapping
//anaconda/lib/python2.7/site-packages/fiona/__init__.py in <module>()
67 from six import string_types
68
---> 69 from fiona.collection import Collection, BytesCollection, vsi_path
70 from fiona._drivers import driver_count, GDALEnv
71 from fiona.drvsupport import supported_drivers
//anaconda/lib/python2.7/site-packages/fiona/collection.py in <module>()
7
8 from fiona import compat
----> 9 from fiona.ogrext import Iterator, ItemsIterator, KeysIterator
10 from fiona.ogrext import Session, WritingSession
11 from fiona.ogrext import (
ImportError: dlopen(//anaconda/lib/python2.7/site-packages/fiona/ogrext.so,
2): Library not loaded: #rpath/libnetcdf.11.dylib
Referenced from: //anaconda/lib/libgdal.20.dylib
Reason: Incompatible library version: libgdal.20.dylib requires version
12.0.0 or later, but libnetcdf.11.dylib provides version 11.0.0
The problem is caused by incompatibility of the fiona's and gdal's dependencies. Uninstall geopandas via conda. It will uninstall fiona as well.
Do conda uninstall geopandas;
Do conda install fiona=1.6
Do conda search fiona before hand and see if it is available for your version of python. If not, create new environment for that version of python.(Ex. create -n py35 python=3.5 anaconda)
Then pip install geopandas
Finally, try to import geopandas and see if you still get the error.
I had the same issue in MacOs Mojave 10.14. I found out that the solution is to install geopandas via pip instead of using conda
pip install geopandas

Categories