How do I install extra python packages on Datalab if they are not supported by pip?

坚强是说给别人听的谎言 提交于 2019-12-24 02:00:55

问题


I tried to install basemap within Datalab using pip:

%bash
pip install basemap

and got the error:

Downloading/unpacking basemap
Could not find any downloads that satisfy the requirement basemap
Cleaning up... No distributions at all found for basemap
Storing debug log for failure in /root/.pip/pip.log

How do I install extra packages on Datalab if they are not supported by pip?


回答1:


Use apt-get install. In a cell of your notebook:

%bash
apt-get -y update
apt-get -y install python-mpltoolkits.basemap

Then, remember to restart your kernel (by Reset Session)




回答2:


Use the following code for this:

%%bash
pip install package_name



回答3:


You might need to first do

apt-get update

So it gets the updated list of packages.




回答4:


The command suggested by Lak might have worked in the past but it's no longer the case: as of today (Aug 2017) Google Datalab instances reject the command listed here

%bash

echo 'Y' | apt-get install python-mpltoolkits.basemap

outputs the error message:

E: Unable to locate package python-mpltoolkits.basemap E: Couldn't find any package by regex 'python-mpltoolkits.basemap'

Execution from the shell (vs. notebook) outputs the same error.

After searching various sources I found a fix that worked for me: from the notebook in Datalab I added an update cmd before the actual install, like this:

%bash 

echo 'Y' | apt-get update

echo 'Y' | apt-get install python-mpltoolkits.basemap



回答5:


Basemap doesn't come with the google datalab out of the box.

Note: I use shorthand '!' to indicate a bash command, rather than '%bash' as the google documents usually do.

As of Feb 2019, this works on a fresh google datalab:

Step 1: Install Pre-requisites

  • !apt-get update && apt-get install -y --allow-unauthenticated build-essential libgeos-3.5.0 libgeos-c1v5 libgeos++-dev

  • !pip install pyproj pyshp

Step 2: Install the whole package

  • !pip install https://downloads.sourceforge.net/project/matplotlib/matplotlib-toolkits/basemap-1.0.7/basemap-1.0.7.tar.gz

Step 3: Check the package has been installed correctly

  • !pip freeze

Step 4: Import the module

  • from mpl_toolkits.basemap import Basemap

@Lak: You will need to update page 155 of your book - Data Science on the Google Cloud platform as the instructions there won't work; basemap is one of the more difficult packages to get working.



来源:https://stackoverflow.com/questions/36047155/how-do-i-install-extra-python-packages-on-datalab-if-they-are-not-supported-by-p

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!