简体   繁体   中英

Easy install python modules for Jupyter notebooks?

Lately I've been learning a bit about Python. Jupyter notebooks seem like a good idea in theory, in practice I'm having some difficulty setting up the python modules within a Jupyter environment.

For example, I found this neat geographical data article and I want to follow along. There is a very nice github project that I downloaded to follow along.

Start up Jupyter and everything looks in order until I run the first code block:

import pandas as pd
import re
from datetime import datetime
from dateutil.parser import parse
import missingno as msno
import numpy as np
import seaborn as sb
import matplotlib.pyplot as plt
import json

This immediately generates an error:

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-1-422e89229f53> in <module>
----> 1 import pandas as pd
      2 import re
      3 from datetime import datetime
      4 from dateutil.parser import parse
      5 import missingno as msno

ModuleNotFoundError: No module named 'pandas'

There are quite a few modules and I guess I can go into the command line to add them each individually. That doesn't seem efficient. Is there some other 'Jupyter' or 'Conda' way to do this?

Within Jupyter notebooks you can execute command line methods using ! at the start of the line eg

! conda install pandas --yes

More detail on the inner working is discussed in this question: Running interactive command line code from Jupyter notebook

Thanks to @PaulH for pointing out the need to add the --yes flag.

just run this in Jupyter:

!pip install <the name of the module>, <the name of the module>, <the name of the module>...

this will install the module you choose. For example :

!pip install pandas, re, ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM