from IPython.display import GeoJSON not working on google colab - python

On Google Colab I'm getting an error when trying to import GeoJSON from IPython.display:
Any help on how to properly import it would be appreciated.

I found the issue to be caused by your Collab runtime having an older version of IPython installed.
pip freeze
Output
ipython==5.5.0
ipython-genutils==0.2.0
ipython-sql==0.3.9
ipywidgets==7.5.1
Since the collab was created sometime ago
Updating the module fixed the issue for me
pip install -U IPython
After which you can restart your runtime and the changes should be reflected
pip freeze
Output
ipython==7.16.1
ipython-genutils==0.2.0
ipython-sql==0.3.9

Exactly how to execute in Google Colab:
import IPython
Update IPython
Now able to from IPython.display import GeoJson

Google Colaboratory has an older version of IPython installed (v5.5.0 as of the time I'm writing this). The best way to fix this is to include the following line in the Colab notebook before your import statements:
!pip3 install --upgrade IPython
This should fix it for you!

Related

sklearn.feature_selection.mutual_info_regression not found

I have been trying to utilise mutual_info_regression method from sklearn, I have updated sklearn to latest build which is 0.24.1 and when I checked the source code inside my conda env path there is folder and files for feature_selection.mutual_info_regression, but when I try to import it in my Jupiter notebook it throws this error ImportError: cannot import name 'mutual_info_regression' from 'sklearn.model_selection' (/opt/anaconda3/envs/<my_env>/lib/python3.8/site-packages/sklearn/model_selection/__init__.py)
I tried restarting kernel as well, but it is still not working, has anyone else faced this issue? Im using macOS 11.2.1 and conda 4.8.3 with Python3
Thanks
I found the solution,
I just had to restart my terminal and then it started working for some reason.
I hope this helps anyone facing such problem in future
Thanks SO!
import sklearn
print(sklearn.__version__)
Check your sklearn version sklearn.model_selection is only available for version 0.18.1
Then try this in Jupyter Notebook cell
from sklearn.feature_selection import mutual_info_regression
If any of the above doesn't work try these three steps
1- pip uninstall sklearn
2- pip uninstall scikit-learn
3- pip install sklearn

Jupyter Notebook ModuleError after Homebrew Upgrade

I have been using Jupyter for some time now and it has worked just fine. I have Jupyter and Python installed via Homebrew. I am running on MacOS.
Yesterday, I ran the command brew upgrade and now my Jupyter notebook is unable to find any of the installed python packages. I will use Numpy as the example.
When inside of a Jupyter notebook, I try to do
import numpy
I get the message:
ModuleNotFoundError: No module named 'numpy'
If, however, I launch python in a terminal window, then I can import Numpy without issue.
I first checked that the package was installed correctly by re-issuing the install command
brew install numpy
which outputs:
Warning: numpy 1.18.4 is already installed and up-to-date
To reinstall 1.18.4, run `brew reinstall numpy`
I also ran
pip install numpy
and got:
Requirement already satisfied: numpy in /usr/local/lib/python3.7/site-packages (1.18.4)
Now, this is where I got confused because I expected the path to point to something like /usr/local/Cellar/, so I checked the path inside of the Jupyter notebook:
import sys
sys.path
which outputs:
['/Users/kseuro/Dropbox/Dev/',
'/usr/local/Cellar/jupyterlab/2.1.2/libexec/lib/python38.zip',
'/usr/local/Cellar/jupyterlab/2.1.2/libexec/lib/python3.8',
'/usr/local/Cellar/jupyterlab/2.1.2/libexec/lib/python3.8/lib-dynload',
'/usr/local/opt/python#3.8/Frameworks/Python.framework/Versions/3.8/lib/python3.8',
'',
'/usr/local/Cellar/jupyterlab/2.1.2/libexec/lib/python3.8/site-packages',
'/usr/local/Cellar/jupyterlab/2.1.2/libexec/lib/python3.8/site-packages/IPython/extensions',
'/Users/kseuro/.ipython']
Ok, so Homebrew wants Jupyter to use Python3.8? So I tried brew switch python 3.8 and got:
Error: python does not have a version "3.8" in the Cellar.
python's installed versions: 3.7.7
I feel like I'm out of my depth now and need help figuring out what to do next. I don't want to start by just changing paths around.
Suggestions? Thanks so much.
I figured out what to do — posting the solution for my future self and others who may stumble upon this.
Since Jupyerlab is in its own Cellar, the Python packages need to end up in the
/usr/local/Cellar/jupyterlab/x.y.z/libexec/lib/python3.x/site-packages
directory, where x, y, z are integers, so that the Jupyter kernel can find them.
You can do this by calling:
import sys
!{sys.executable} -m pip install 'package-name'
inside of the Jupyer notebook.
All is well, again.

Jupyter notebook does not reflect library version change in virtualenvironment

I am new to jupyter notebooks and virtualenvironment. I think that I am incurring in a really trivial problem.
I am trying to import matplotlib in a Jupyter notebook and the import works fine. However, it uses the wrong version of the library (installed also systemwide) and I don't know how to force it to use the one in the virtualenvironment.
In my virtualenvironment I want to use a most recent version of matplotlib and therefore I did
pip install --upgrade matplotlib in my virtualenvironment. The upgrade worked fine.
Now if I do pip show matplotlib in my virtualenvironment I get:
Name: matplotlib
Version: 2.2.5
...
Instead, if I do the same command in my home, I get:
Name: matplotlib
Version: 1.5.1
However, if in my jupyter notebook I do
import matplotlib
print ("matplotlib version:",matplotlib.__version__)
I get:
('matplotlib version:', '1.5.1')
Could you please help me understanding what I do wrong?
I found a solution to my problem. First of all, I read this long post that I suggest to everyone using conda or pip.
Then I understood that the shell environment is determined when the Jupyter notebook is launched, while the Python executable is determined by the kernel, and the two do not necessarily match.
I understood this by putting at the beginning of my jupyter notebook the following:
paths = !type -a python
for path in set(paths):
path = path.split()[-1]
print(path)
!{path} -c "import sys; print(sys.path)"
print()
!type python
import sys
sys.executable
!pip show matplotlib
It showed me that I was still using an older version of the matplotlib library.
Therefore I added
!{sys.executable} -m pip install --upgrade matplotlib
Restarted my jupyter kernel and this solved my problem.
I hope this solution will help someone else in the same situation.

How to determine Azure python sdk version?

I'm using notebooks.azure.com to learn python. I'm trying to manage Blobs with python sdk.
MUCH of the documentation I come across mentions pip install azure-storage-blob then using the BlobServiceClient (class?) to interact with Azure Storage.
UNFORTUNATELY, I get the error: ImportError: cannot import name 'BlobServiceClient' when trying to call from azure.storage import BlobServiceClient. This occurs after installing and upgrading azure-storage (v0.36.0) and azure-blob-storage (v12.3.0).
Here is a public Notebook showing the issue
Does this mean notebooks.azure.com is using the python v2.1 SDK (which appears to use BlockBlobService instead of BlobServiceClient)
How do I check which version of the python SDK my Azure Notebook is running?
EDIT 1:
No change after running !pip install azureml-sdk\[notebooks,automl\] --upgrade
Did you try
pip install --upgrade azureml-sdk\[notebooks,automl\]
azure-storage is deprecated, don't use that.

ModuleNotFoundError: No module named 'seaborn' in Python IDE

It checks the lib folder where my seaborn stuff is, but still error._.
Hi,
I have looked at other posts, but most seemed to be dealing with Jupyter notebooks, which I'm not. I was wondering how to get to use Seaborn in the basic Python IDE or in PyCharm. I read about filepath collisions stuff, but not too clear on that front.
I'm using Python 3.6 right now.
Thanks for any help!
When dealing with version ambiguity, remember that pip is a python module. Once you're confident that python is the python installation that your IDE is running, run
python --version
python -m pip install seaborn
>pip3 may be pointing to an old or different python installation.
import pip
pip.main(['install','seaborn'])
From: https://stackoverflow.com/a/49391839
If you're doing in jupyter notebook Try doing this:
!conda install -c anaconda seaborn -y
Try running it in the terminal, it will work. But while running the command your pwd should be in the virtual environment in activated form
$ sudo apt-get install -y python3-seaborn
Try running this in a command line 'pip install seaborn'
https://seaborn.pydata.org/installing.html#installing
In PyCharm IDE, we can import the downloaded libraries, and that's what I did. Still, I have no clue on how to resolve this issue on Python IDE, but as of now, it's working on PyCharm for me.
Conda install seaborn
worked in my case.
If you are using jupyter notebook following command will solve the issue
!pip install seaborn
Jupyter Code-Cell:
%%bash
pip install seaborn
Since you are using python 3, try to open with idle3 from terminal
Tried importing seaborn in Pycharm with the proper configuration thing, and it works. I still don't know why the regular Python IDE doesn't work even though one of the sys.path folder it checks contains the seaborn folder, but oh well.
Thanks for all the replies!
Maybe you should try “python —version “to check if you’re using the right version of python in cmd. Sometimes it happens that there are multiple versions installed and it sometimes picks the wrong one.
Also it can happens that python hasn’t the rights to use the module. Then you should create your file and run it with “python [path of file]”
Just found a new method to install all important libraries.
Open command prompt:
Pip install pyforest
All the most important libraries got installed.
My fix (Same import error but on Jupyter Notebook). The import sequence:
import numpy as np
import seaborn as sns
%matplotlib inline
import matplotlib.pyplot as plt
Importing Matplotlib before seaborn can lead to an import error (I have no idea why).
The Seaborn official document also shows this:
https://seaborn.pydata.org/installing.html
If you're using Jupyter notebook try to run this_ _
** pip install seaborn --user**

Categories