I started working through the first lab of MIT’s Deep Learning course. Before I even got to the neural networks themselves, I ended up with a small lab of my own: setting up the environment.
The lab itself starts quite simply. You need to import PyTorch and several additional libraries:
import torch
import torch.nn as nn
# Download and import the MIT Introduction to Deep Learning package
!pip install mitdeeplearning --quiet
import mitdeeplearning as mdl
import numpy as np
import matplotlib.pyplot as plt
If you run the lab in a prepared environment such as Jupyter Notebook or Google Colab, you may indeed have almost nothing else to do at this stage.
But I decided to run everything locally on Windows. That was when I discovered that a few lines from the lab require at least a basic understanding of what is actually happening.
First Run: Python Does Not Know What torch Is
I launched the regular Python interpreter and tried:
import torch
The response was:
ModuleNotFoundError: No module named 'torch'
The error is fairly clear: Python is installed, but PyTorch is missing from this environment.
I exited the interpreter:
exit()
and installed PyTorch from PowerShell:
python -m pip install torch
Why use python -m pip instead of simply pip?
Because this form explicitly says: run the pip module with the same Python interpreter invoked by the python command. When a system has multiple Python versions and environments, this helps avoid confusion.
The installation completed successfully:
Successfully installed ... torch-2.13.0 ...
However, warnings appeared saying that some executables were located in a directory that was not in PATH:
WARNING: The scripts torchfrtrace.exe and torchrun.exe are installed in
'C:\Users\dante\AppData\Local\Python\pythoncore-3.14-64\Scripts'
which is not on PATH.
For my current task, this was not a critical error. The package itself had been installed.
PyTorch Worked, but the Next Problem Appeared
I launched Python again:
import torch
This time there was no ModuleNotFoundError, but a warning appeared:
UserWarning: Failed to initialize NumPy: No module named 'numpy'
In other words, PyTorch itself could now be imported, but NumPy was missing.
I checked the version:
print(torch.__version__)
The result was:
2.13.0+cpu
That was already a good sign: PyTorch was installed and working.
The +cpu suffix means that the CPU version of PyTorch was installed. That is enough to begin the lab. GPU support can be addressed separately when it is actually needed.
The Command from the Lab Is Not Regular Python
The next line in the lab looks like this:
!pip install mitdeeplearning --quiet
If you simply copy it into the regular Python interpreter, it will not work.
The reason is the ! character.
It is not standard Python syntax. Jupyter/IPython uses it to run operating-system commands directly from a notebook cell.
Therefore, instead of:
!pip install mitdeeplearning --quiet
I used the following in PowerShell:
python -m pip install mitdeeplearning
It seemed as though everything should now install.
But it did not.
Why I Decided to Switch to a Virtual Environment
The installation of mitdeeplearning ended with an error. At that point, it became clear that continuing to install everything directly into the system Python was not a good idea.
It was better to create a separate virtual environment for the lab.
In the project directory:
C:\Users\dante\OneDrive\Documents\Learning Lab1
I created it with:
python -m venv .venv
This created the following directory:
.venv
It contains a separate Python interpreter and a separate set of libraries for this project.
Normally, you activate the virtual environment after creating it. PowerShell, however, refused to run the activation script because of its script execution policy.
I did not want to change a system-wide Windows policy just for this lab.
That was when I learned something useful: a virtual environment does not have to be activated at all.
You can run the Python interpreter inside it directly:
.\.venv\Scripts\python.exe --version
My result was:
Python 3.14.5
You can also install a package specifically into this environment like this:
.\.venv\Scripts\python.exe -m pip install ...
I actually liked how explicit this approach was: I could see exactly which Python interpreter I was using.
The setuptools Problem
My next attempt was to restrict the setuptools version:
.\.venv\Scripts\python.exe -m pip install "setuptools<82"
The following version was installed:
Successfully installed setuptools-81.0.0
But this did not solve the main problem.
After the next attempt, it became clear that the issue was no longer just setuptools.
The problem was the Python version.
Python 3.14 Was Too New
I had Python 3.14.5 installed.
PyTorch itself was already working on it, but mitdeeplearning brings in a fairly large dependency tree. Compatibility with such a new Python version became a problem somewhere in that tree.
This was an interesting practical lesson.
The newest version of Python is not always the best choice for scientific libraries.
Python evolves faster than the entire ecosystem can adapt. This is especially noticeable in machine learning, where large libraries with native components and many dependencies are common.
So I decided to install another Python version: Python 3.13.15.
There was no need to remove the system-wide Python 3.14. Windows can have several Python versions installed at the same time.
Recreating the Environment with Python 3.13
The old virtual environment had been created with Python 3.14, so merely installing Python 3.13 would not change it.
I removed the old environment:
Remove-Item -Recurse -Force .venv
Then I explicitly created a new one with Python 3.13:
py -3.13 -m venv .venv
I checked it:
.\.venv\Scripts\python.exe --version
The result was:
Python 3.13.15
Now everything was correct.
I installed the appropriate setuptools version again:
.\.venv\Scripts\python.exe -m pip install "setuptools<82"
Then PyTorch:
.\.venv\Scripts\python.exe -m pip install torch
The installation completed successfully.
I checked it:
.\.venv\Scripts\python.exe -c "import torch; print(torch.__version__)"
The result was:
2.13.0+cpu
The NumPy warning appeared again:
UserWarning: Failed to initialize NumPy: No module named 'numpy'
But it no longer looked alarming. PyTorch worked, and NumPy was expected to be installed as one of the mitdeeplearning dependencies anyway.
Installing mitdeeplearning
The next step was:
.\.venv\Scripts\python.exe -m pip install --no-build-isolation mitdeeplearning
This was where a genuinely large installation began.
mitdeeplearning was far from a small package. It started downloading all of the following along with it:
numpy
tensorflow
keras
transformers
datasets
peft
gym
opik
openai
pandas
pyarrow
...
TensorFlow alone was more than 350 MB:
Downloading tensorflow-2.21.0 ... (351.2 MB)
In addition, pip built wheel packages for mitdeeplearning and gym itself:
Building wheel for mitdeeplearning ... done
Building wheel for gym ... done
And finally:
Successfully installed ... mitdeeplearning-0.7.5 ...
The main problem had been solved.
Installing a Package Does Not Yet Mean the Lab Will Run
After that, the AI assistant and I decided not to consider the task finished merely because pip had printed Successfully installed.
It was better to test the exact imports used by the lab.
It turned out that matplotlib was missing.
I installed it:
.\.venv\Scripts\python.exe -m pip install matplotlib
The next check revealed another dependency: ipython.
.\.venv\Scripts\python.exe -m pip install ipython
The following attempt reached:
import cv2
The cv2 module is provided by OpenCV, so I installed it:
.\.venv\Scripts\python.exe -m pip install opencv-python
Then I ran the check again.
Final Environment Check
Now I checked the lab’s main imports all at once:
.\.venv\Scripts\python.exe -c "import torch; import torch.nn as nn; import mitdeeplearning as mdl; import numpy as np; import matplotlib.pyplot as plt; print('torch:', torch.__version__); print('numpy:', np.__version__); print('Все импорты работают')"
This time I got:
torch: 2.13.0+cpu
numpy: 2.5.2
Все импорты работают
Finally.
Before that, TensorFlow printed messages about oneDNN:
oneDNN custom operations are on.
You may see slightly different numerical results due to
floating-point round-off errors...
This is a warning, not an error. The library is reporting that it uses optimized CPU operations and that floating-point results may differ very slightly because operations can be evaluated in a different order.
Gym also displayed a warning:
Gym has been unmaintained since 2022 and does not support NumPy 2.0...
Please upgrade to Gymnasium...
This is more interesting: the mitdeeplearning package uses the old gym package, which is no longer officially maintained and warns about issues with modern NumPy versions.
For now, however, the import succeeds. I am not going to fix something before it has actually broken. If a specific part of the lab fails because of incompatibility between gym and NumPy, I will investigate that issue separately.
The Final Result
The working lab environment now looks approximately like this:
Learning Lab1
│
└── .venv
├── Scripts
├── Lib
└── ...
Most importantly, the complete set of libraries is contained inside .venv instead of being scattered throughout the system Python installation.
I do not even need to activate the environment to run Python:
.\.venv\Scripts\python.exe
To install new packages:
.\.venv\Scripts\python.exe -m pip install имя_пакета
And to run a script:
.\.venv\Scripts\python.exe script.py
If I Were Installing Everything Again
After all these experiments, the sequence now looks much clearer.
Install Python 3.13 and create the environment:
py -3.13 -m venv .venv
Check the version:
.\.venv\Scripts\python.exe --version
Install the appropriate setuptools version:
.\.venv\Scripts\python.exe -m pip install "setuptools<82"
Install PyTorch:
.\.venv\Scripts\python.exe -m pip install torch
Install the MIT package:
.\.venv\Scripts\python.exe -m pip install --no-build-isolation mitdeeplearning
Then install the missing dependencies required by my version of the lab:
.\.venv\Scripts\python.exe -m pip install matplotlib ipython opencv-python
Finally, check the environment:
.\.venv\Scripts\python.exe -c "import torch; import torch.nn as nn; import mitdeeplearning as mdl; import numpy as np; import matplotlib.pyplot as plt; print('torch:', torch.__version__); print('numpy:', np.__version__); print('Все импорты работают')"
What I Learned from This Installation
The funny thing is that I had barely begun the deep learning lab, yet I had already learned several useful practical lessons about Python.
First, code from a Jupyter Notebook cannot always be copied thoughtlessly into regular Python. The construct:
!pip install ...
belongs to the Jupyter/IPython environment, not to the Python language itself.
Second, a virtual environment is not merely an extra complication for professional programmers. It is a convenient way to isolate the dependencies of a specific project.
Third, a virtual environment does not have to be activated. You can explicitly invoke its interpreter:
.\.venv\Scripts\python.exe
Fourth, the newest Python version can be too new. Python 3.14 installed perfectly well and even ran PyTorch, but the large mitdeeplearning dependency tree forced me to move back to Python 3.13.
Finally, a Successfully installed message does not guarantee that the entire project is ready to work. It is far more useful to run the actual imports and see what is missing.
An AI assistant helped me a great deal throughout this process. I probably would have found the answers gradually on my own as well—documentation, search, Stack Overflow, and trial and error are still available. But identifying the cause of each new error would have taken much longer.
Here, AI was not a replacement for learning. It was more like an assistant sitting nearby: I run a command, get an error, try to understand what it means, show the result to the AI, receive an explanation and a possible next step, and then test again.
That, too, is probably part of learning how to work with modern tools.
Most importantly, the environment finally works:
torch: 2.13.0+cpu
numpy: 2.5.2
Все импорты работают
That is enough for today.
I will continue the lab next time.
Leave a Reply