After run conda activate d2l

# sanity check that the path to the python
# binary matches that of the anaconda env
# after you activate it
which python

To deactivate the environment, either run conda deactivate d2l or exit the terminal. Note that every time you want to work on the assignment, you should rerun conda activate d2l . manage-environments

only cpu version: in my pull

import torch

Recommend my repo that records all my study process about pytorch version of d2l-en :
Recommend my post: Do these before you ask
More classes:

I still suggest to use conda install to install pytorch

For Chinese users:
conda config --add channels
Then look to install.
For me,

For Chinese users:
It is necessary to use pypi mirror and conda mirror to get pip install and conda install quicker.
pypi mirror:
conda mirror:
For example:
conda config --add channels
You can add any other channels

unset pip mirror: pip config unset global.index-url
unset conda mirror:conda config --remove channels

Check your mirror by printing all configuration:
pip config list
conda config --show

conda config --show-sources

For more
conda config --add channels
conda config --set show_channel_urls yes
conda config --remove channels defaults

from d2l import torch as d2l

--------------------------------------------------------------------------- ModuleNotFoundError
Traceback (most recent call last) in
1 get_ipython ( ) . run_line_magic ( ‘matplotlib’ , ‘inline’ ) ---->
2 from
d2l import torch as d2l
3 import torch
4 import random ~\anaconda3\envs\pytorch\lib\site-packages\d2l\ in
17 import tarfile
18 import time
—>19 import requests
20 import zipfile
21 import hashlib
ModuleNotFoundError : No module named ‘requests’

Is there a way to install all packages advancely we need to import in or or

I guess the reason of No module named ‘requests’ is that mxnet has ‘requests’ defaulty while pytorch not.

d2l requirements
install_requires vs requirements files

hey @StevenJokes, just do a pip install requests.

I have done this long long ago. Just curious about how to do all this type stuff advancely.

Have found the solution :conda env create -f environment.yml from handson-ml

Or can we add library “requests” to d2l package?

I have been trying to run these ipynb files of PyTorch but I am getting an error every time I try to run them.

Error is:
Unable to read notebook …ipynb notJSONERROR (notebook does not appear to be json) in Ubuntu.

Could someone help to solve me this error?

Hi @Shashwat, could specify the Ubuntu version you are using? Is it a local installation without GPU?


My first search from google:
It may helps you. Can you tell me where do you download there ipynb files?
And more details?

Do you install jupyter?
Maybe you don’t install jupyter book.

Read And then you can find these to install jupyter notebook

conda install notebook


pip install notebook

Any other problem? Look Do these before you ask!. Figure it out by yourself first.

I think we don’t tell them to install jupyter at all.
new commit:
Help me review!

I am using Ubuntu 18.04 with GTX 1050ti graphics card.

Thanks Steven,
I already tried the approaches suggested in But they were of no help. I even tried renaming them with a .html extension but it didn’t help either.

I downloaded the ipynb files from from the All notebooks section.

And yeah I am using Jupyter to run these files.

I still can’t find your real problem. Have you run other .ipynb that is not in this book files before?

But there is what you can try:

  1. update your jupyter
  2. read again:

    Have you run jupyter notebook first, then read files in your browser?
  3. install VScode to open it directly: Using Jupyter
  4. read
    I guess you choose ipynb files from local disk.

Once all packages are installed, you can open the Jupyter notebook by

jupyter notebook

At this point open http://localhost:8888 (which usually opens automatically) in the browser, then you can view and run the code in each section of the book.


You’re trying to run the pytorch code that we don’t have now…
Please look this for more details.

Hello May be it is very easy problem … I have struggled to solve it but I can’t

I installed torch & torch vision CPU only version as book guided

after installation, I activate virtual env & activate Jupyter notebook and run the code of notebook . I also install requests as your guidance

I met error message like this
OSError: [WinError 126] 지정된 모듈을 찾을 수 없습니다.
Error loading “C:~~\torch\lib\asmjit.dll” or one of its dependencies.

Plz give me a guide to fix it.


google first… And convert your language to English next time

@Shashwat Did you have a solution? I have the same problem like you.
In pytorch folder:

  • I can’t open index.ipynb
  • I can’t open /chapter_introduction/index.ipynb
  • But, I can open /chapter_optimization/adadelta.ipynb

Could someone help me, please?

Because there isn’t any code in index…

in my linux, mxnet is cuda-100, why?


from mxnet import npx plz
click mxnet tab to discuss mxnet next time

why I cannot import ? thanks reply.

**image **

Hi @HeartSea15, please post MXNet installation issue under MXNet tag. You may need to upgrade to MXNet 1.7.