Hacker News new | ask | show | jobs
by BaculumMeumEst 712 days ago
Dude I just started getting into deep learning and have been flabbergasted getting stuff working. I installed jupyter and torch via homebrew. I can use torch fine from programs, or in venvs, but when I try to use torch in a Jupyter notebook it cannot find the module. Is it a different python environment or something?
5 comments

It can be confusing. The key is that you probably have multiple versions of python installed on your computer (that's normal). Secondly, the default "kernel" in Jupyter was probably not the one you used to install torch.

I'd suggest 2 things to help: 1. Try `pyenv` for python version management 2. See this tutorial for how to create a virtual environment and add it as a Jupyter kernel: https://selvamsubbiah.com/run-jupyter-notebook-in-a-virtual-...

Satyrn makes it easier to add virtual environments as a kernel, but you still will need to create the virtual environment and install torch there yourself.

That's a really great point you made about how confusing it is to pip install stuff with `!pip` when working in the notebook. Right now Satyrn does not support the `!` commands, but I will add this soon and try to make it so `!pip` works with the expected virtual environment you are working with.

Jupyter and pytorch can be installed completely as python packages via pip thanks to the modern wheel distribution format. Because of that, I would generally not recommend using an external package manager for project dependencies. I prefer installing python via the Python.org downloads, then creating a dedicated virtual environment where I can pip install any packages. That way I known where all my dependencies are installed, and I can make seperate environments for different Python or library versions.
Hey, I used to run into the same issue and figured out installing conda, and utilizing its python was the easiest to keep things straight. Once you install conda and can activate your environment, then when using pip, don’t just call `pip install` because your path could be using a different pip than you expect. Instead use `python -m pip install` after activating your conda environment but make sure you’re using the right Python (`which python` & `conda env list`)
Python packaging etc can be a real pain point. I would suggest not using homebrew for these, in fact uninstall them. For jupiter/torch heavy work, I would install anaconda and then use that exclusively. Best of luck, it can be annoying but follow a good guide online you'll be OK.
Package management is a fundamentally hard problem, and it's not all technical.

Nowadays, before I try anything new, I mentally reserve one or two days for the inevitable problems with configuring, compiling and installing. Also, it happens regularly that the cost of trying something turns out to be too high, and I just move on to the next thing.

Of course, sometimes stuff works out of the box, but that is only in a small fraction of cases.

It is sad that it has come to this, and it makes me wonder how we'll cope in a future when software has even more layers of complexity.