d2l-en icon indicating copy to clipboard operation
d2l-en copied to clipboard

Can't install d2l 1.0.3 on python 3.12.4

Open TheJeffah opened this issue 1 year ago • 8 comments

The D2L Package version 1.0.3 requires numpy 1.23.5. Python 3.12.4/pip 24.1 consider it(numpy 1.23.5) depreciated and does not conclude the installation. It's needed to update the D2L package to depend on numpy 2.0.0. I'm waiting for it.

Regards.

TheJeffah avatar Jun 25 '24 09:06 TheJeffah

The authors mention testing with Python 9. I haven't tried the ML code yet, but installation completes with the latest iteration of Python 11:

mkdir 'D2L Jupyter Notebooks'
cd !$
curl -sSLO https://github.com/d2l-ai/d2l-en/releases/download/v1.0.3/d2l-en-1.0.3.zip
unzip ./d2l-en-1.0.3.zip
rm -rf __*
asdf install python 3.11
asdf local python 3.11
pip install -U pip wheel
pip install -U jupyterlab  numpy
pip install -U install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu
pip install -U d2l
cd pytorch/chapter_preliminaries
jupyter lab

Finally, double-click on index.ipynb in JupyterLab's file browser.

slewsys avatar Jul 18 '24 14:07 slewsys

Hi @slewsys ! 🙂

I think It should be upgraded, doesn't it ? I can't go back to 3.9 or 3.11. Numpy is 2.0.0 and Python is 3.14. They are faster and many improvements. I don't use Jupyter. I use Spyder. Before upgrade Python, I was testing the code on 3.11 and it was working quite well. But, go back to 3.11... I can't. Sorry. 😇

TheJeffah avatar Jul 18 '24 14:07 TheJeffah

The following works for me using Python 3.12.4. I didn't adjust the version in d2l/__init__.py because only setup.py is modified:

git clone https://github.com/d2l-ai/d2l-en.git
cd ./d2l-en
patch <<EOF
--- setup.py.orig	2024-07-19 06:38:57.169915071 +000
+++ setup.py		2024-07-19 06:40:25.545595707 +000
@@ -2,13 +2,13 @@
 import d2l
 
 requirements = [
-    'jupyter==1.0.0',
-    'numpy==1.23.5',
-    'matplotlib==3.7.2',
-    'matplotlib-inline==0.1.6',
-    'requests==2.31.0',
-    'pandas==2.0.3',
-    'scipy==1.10.1'
+    'jupyterlab==4.2.2',
+    'numpy==2.0.0',
+    'matplotlib==3.9.1',
+    'matplotlib-inline==0.1.7',
+    'requests==2.32.3',
+    'pandas==2.2.2',
+    'scipy==1.14.0'
 ]
 
 setup(
EOF
pip install -U pip wheel setuptools
python ./setup.py bdist_wheel
pip install -U ./dist/d2l-1.0.3-py3-none-any.whl

slewsys avatar Jul 19 '24 06:07 slewsys

Man ! You nailed it ! Python skills ! Working beautifully here. I was waiting for three weeks and now I can go back to test the codes. Thanks @slewsys ! 🙂

But, could the requirements be like 'numpy>=1.23.5' ? If so, it's just a matter of upgrade the setup.py on github. Isn't it ?

TheJeffah avatar Jul 19 '24 14:07 TheJeffah

Bad news, @slewsys... 🙁

This is the message after executing the code: A module that was compiled using NumPy 1.x cannot be run in NumPy 2.0.0 as it may crash. To support both 1.x and 2.x versions of NumPy, modules must be compiled with NumPy 2.0. Some module may need to rebuild instead e.g. with 'pybind11>=2.12'. If you are a user of the module, the easiest solution will be to downgrade to 'numpy<2' or try to upgrade the affected module. We expect that some modules will need time to support NumPy 2.

Ok. We tried. Let's go back to square one. D2l should be upgraded in its code to numpy 2.0.0, isn't it ?

TheJeffah avatar Jul 19 '24 14:07 TheJeffah

I'm not sure what module was compiled with NumPy 1.x? Python does a poor job of dependency resolution. So the burden is on the user to create a pristine environment for Python when installing packages with lots of dependencies. The most common way of doing that is with a so-called virtual environment:

python -m venv d2l-venv
source d2l-venv/bin/activate
# Inside the Python virtual environment d2l-venv, run:
pip install -U pip wheel
pip install -U dist/d2l-1.0.3-py3-none-any.whl

You'll want to reinstall Spyder and so on in this virtual environment as well. To leave the virtual environment, run:

deactivate

To return to the virtual environment at some later point, cd to the d2l-en repository and run:

source d2l-venv/bin/activate

If you still encounter issues, try to provide the steps needed to reproduce the problem. Hope that helps!

slewsys avatar Jul 20 '24 02:07 slewsys

Almost there. The virtual environment worked quite well. Everything installed. But now the problem is spyder. It's getting segmentation fault when launching. I see python 3.12 as interpreter in the virtual environment. I think it won't work. We are trying to make a solution for something downgraded. It's just a matter of upgrade the project to numpy 2 and that's it !

TheJeffah avatar Jul 21 '24 17:07 TheJeffah

It should work using pip install numpy==1.26.4 or pip install "numpy<2" following by pip install --no-deps d2l, but this is far from ideal. In the requirements above, you can use either of those version specifiers instead of 2.0.0, which being a major version update will likely cause problems.

flayman avatar Feb 11 '25 13:02 flayman