Google Colab not updating package? - python

I am trying to use seaborn==0.8.1 in an ipynb on Google colab. Here is my code:
"""General import statements and settings config."""
!pip install seaborn==0.8.1
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
%matplotlib inline
pd.set_option('max_columns', 10)
color = sns.color_palette()[0]
print (sns.__version__)
However, this outputs the following:
Requirement already satisfied: seaborn==0.8.1 in /usr/local/lib/python3.6/dist-packages (0.8.1)
0.7.1
If the requirement is satisfied why am I importing the old version of Seaborn?

The issue here is that Colab imports seaborn at startup, before you've pip install'd the new version. If you restart your runtime after the install, you'll pick up the new version.

!pip install seaborn --upgrade packageName and then restart the kernel/runtime.
If you just need to upgrade seaborn in a hosted collab notebook to the latest version then run
!pip install seaborn --upgrade and then restart the kernel/runtime.

Related

can't import seaborn on Jupyter notebook

I have installed numpy, pandas and matplot lib
but installation of seaorn i not possible. I ve tried updating Numpy, installing seaborn through the cmd command but in vain. I restarted the kernel each time.
import seaborn as sns
I keep recieving ;
ImportError: DLL load failed while importing _arpack: The specified procedure could not be found.
I have used:
!pip install seaborn
pip install numpy --upgrade --user
pip import seaborn as sns df = sns.load_dataset(penguins) sns.pairplot(df, hue=species)
It seems like your seaborn and/or numpy installation is broken or at least there is some versions conflict.
Try to run these commande from the command line :
pip unistall seaborn numpy
pip install mkl numpy seaborn
After that, you can run this code in your Jupyter notebook :
import seaborn as sns
df = sns.load_dataset("penguins")
sns.pairplot(df, hue="species")
the problem was fixed by updating matplotlib on the conda shell.
conda update matplotlib

How to Import Pandas Profiling [duplicate]

I am new to pandas_profiling and getting ImportError while importing it. Please help.
import numpy as np
import pandas as pd
import pandas_profiling
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
%matplotlib inline
import seaborn as sns
After executing the above code in jupyter notebook, I am getting the following error.
ImportError: matplotlib is required for plotting when the default backend "matplotlib" is selected.
> python --version
Python 3.7.3
> pip list | grep -E "matplotlib|pandas"
matplotlib 3.2.0
pandas 0.25.3
pandas-profiling 2.5.3
I don't know the actual reason but I restarted the kernel and it is working.
Before restarting the kernel I executed following commands:
conda install -c anaconda pandas-profiling

Get dependency file to host Jupyter notebook on Binder?

I am trying to export my dependencies to a requirements.txt or environment.yml file for pip or conda respectively - in order to host a Binder notebook.
How can I get only the dependencies that my notebook is using?
When I tried pip freeze or conda env export, I get all my installed packages, which leads to errors when building the Docker environment.
You might want to try watermark:
Install:
pip install watermark
Then, in your notebook:
# Load the extension
%load_ext watermark
# import your libraries
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
# Determine the dependency version
%watermark -p numpy,matplotlib,seaborn
The results will look like this:
numpy 1.14.3
matplotlib 2.2.2
seaborn 0.9.0

Python: Imported matplotlib but cannot use imshow

I'm working in Ubuntu as Virtual-Box guest on top of Windows machine (as host), and I am attempting to run my python script from the terminal. I had difficulty installing matplotlib using pip install. I managed to install it using
sudo apt-get install python-matplotlib
However, I am unable to bring up an image I have created in my code:
import numpy as np
import matplotlib.pyplot as plt
import random as random
from random import randrange
image = plt.imshow(mymatrix)
plt.show()
If I import matplotlib as:
import matplotlib as plt
I am recieving the following error on attempting to run the script:
AttributeError: 'module' object has no attribute 'imshow'
If I import matplotlib as:
import matplotlib.pyplot as plt
I recieve the following error:
raise ImportError, str(msg) + ', please install the python-tk package'
ImportError: No module named _tkinter, please install the python-tk
package
On attempting to install python-tk using 'pip install python-tk' this is what I'm getting:
~/ising $ pip install python-tk Collecting python-tk Could not find
a version that satisfies the requirement python-tk (from versions: )
No matching distribution found for python-tk
I'm unsure if I have in fact incorrectly installed matplotlib from the beginning. I am aware pyplot is not automatically imported with matplotlib, could the same be true for installing it from the console? Seems like I have tried everything at this stage.
The problem appears to be that you do not have a graphical backend installed. The error you are getting about Python Tk is happening because normally Tk comes with any Python distribution, so you should have at least that. You can install any Python bindings for Tk, Pyqt4, Pyqt5, Wx, GTK, (possibly others) to get a working interactive graphical backend. Check the package repository for the actual package names to install.
Keep in mind that functions like imshow are part of the (sub)package matplotlib.pyplot, not matplotlib itself. import matplotlib as plt is simply wrong if you intend to do plt.imshow(...). The correct import is either from matplotlib import pyplot as plt or import matplotlib.pyplot as plt.
According to the documentation here try this
python -mpip install -U pip
python -mpip install -U matplotlib

how to import seaborn egg (new 0.6.dev) into python

I got the developmental version using this in cmd prompt (after uninstalling the old package):
pip install git+git://github.com/mwaskom/seaborn.git#egg=seaborn
Now when I try to import in canopy it still says I am using the old version.
import seaborn as sns
help(sns)
And at the end of the output I get:
VERSION
0.5.1
How do I need to set this up?

Categories

Resources