I followed these instructions to get a python virtual environment (managed by pyenv) working in a Jupyter Notebook.
In summary, I did
brew install pyenv
pyenv install 3.8.5
pyenv virtualenv 3.8.5 myproject
pyenv shell myproject
pip install jupyter notebook matplotlib pandas numpy scipy
Then I started up jupyter notebook from terminal (I tried both jupyter notebook and jupyter lab). When I typed import numpy as np, I get
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-1-0aa0b027fcb6> in <module>
----> 1 import numpy as np
ModuleNotFoundError: No module named 'numpy'
But in the very next cell, if I evaluate !pip install numpy, I get
Requirement already satisfied: numpy in /Users/<my_username>/.pyenv/versions/3.8.5/envs/myproject/lib/python3.8/site-packages (1.19.1)
And also, !which python and !which pip return
/Users/<my_username>/.pyenv/shims/pip
/Users/<my_username>/.pyenv/shims/python
How is it even possible that in the very same jupyter notebook, it can't find numpy but pip says numpy is already installed? I can never seem to get my Python environments to just behave!