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!
I had the exact same issue. I think it's all due to your "varying pip list". You probably have installed bunch of libraries via pip install before you created the shims path (prior your pyenv installation). You may also have installed some others after the shims creation. So your jupyter-notebook and jupyter-lab may not have access to the priorly installed libraries.
Since you have installed pyenv via homebrew, without touching anything else just re-installing the jupyterlab via homebrew might take care of it.
I used this:
brew install jupyterlab
And it solved my problem.
source: https://formulae.brew.sh/formula/jupyterlab
Related
python 3.8.12 installed by pyevn seems working as expected, but numpy installed using pip cannot be imported.
pip --list ran in Jupiter notebook shows the package has been installed already.
So as per the path you stated in your comment (reply), execute this command:
/usr/local/opt/python#3.9/bin/python3.9 -m pip install pandas
My code:
import numpy as np
import tensorflow
Output:
NameError Traceback (most recent call last)
< ipython-input-1-87dbf2ff9b36 > in < module >
----> 1 x = np.random.randint(0,100)
NameError: name 'np' is not defined
What I don't understand is that even though I have already imported the library it is not getting detected and gives me a NameError, Same is the case with a lot of libraries.
I am currently using Jupyter Lab through Anaconda.
=================================>
Got the solution for all the Issues while installing TensorFlow on M1 Macbook
Follow the below link:
https://naturale0.github.io/machine%20learning/setting-up-m1-mac-for-both-tensorflow-and-pytorch#:~:text=Macs%20with%20ARM64%2Dbased%20M1,both%20from%20consumers%20and%20developers.
Thank you #Akella Niranjan for the reference. For the benefit of community providing solution here as written by #Sihyung Park.
Install TensorFlow-macOS for Apple Silicon M1
It is easy to install it with the system python since the installation script is given by Apple. However, my goal was to install it with other python so that I can install additional packages for data science without difficulty.
I mainly followed instructions from here to install tensorflow-macos, and then created ipykernel of it so that I can run this environment any time by switching the kernel inside jupyter notebook.
First install miniforge, which natively supports M1. The installation defaults to directory ~/miniforge3/.
Create virtual environment named tf_macos with conda and install Python 3.8.
conda create -n tf_macos
conda activate tf_macos
conda install -y python=3.8
I specified the version 3.8 so that it matches requirement of tensorflow-macos.
Download and install tensorflow-macos from Apple Github.
git clone https://github.com/apple/tensorflow_macos.git
cd tensorflow_macos/arm64
pip install --force pip==20.2.4 wheel setuptools cached-property six
pip install --upgrade --no-dependencies --force numpy-1.18.5-cp38-cp38-macosx_11_0_arm64.whl grpcio-1.33.2-cp38-cp38-macosx_11_0_arm64.whl h5py-2.10.0-cp38-cp38-macosx_11_0_arm64.whl tensorflow_addons-0.11.2+mlcompute-cp38-cp38-macosx_11_0_arm64.whl
pip install absl-py astunparse flatbuffers gast google_pasta keras_preprocessing opt_einsum protobuf tensorflow_estimator termcolor typing_extensions wrapt wheel tensorboard typeguard
pip install --upgrade --force --no-dependencies tensorflow_macos-0.1a1-cp38-cp38-macosx_11_0_arm64.whl
Add the environment as jupyter kernel.
pip install jupyter
python -m ipykernel install --name=tf_macos
Then merely switching the ipython kernel to tf_macos allows us to use mlcompute-backend TensorFlow without a hassle
Install additional packages (optional)
conda install scipy pandas matplotlib
For more information you can refer here
got a new laptop (MacBook Air with Catalina) and installed python 3 thru Homebrew.
When trying to install and run some libraries in a jupyter notebook (also installed thru Homebrew) like:
!pip3 install pandas
and then:
import pandas as pd
I get the error:
ModuleNotFoundError: No module named 'pandas'
Same thing with numpy, matplotlib, bs4, etc. Even though when I rerun the !pip3 install something I get the message:
Requirement already satisfied: numpy in /usr/local/lib/python3.8/site-packages (1.19.2)
When I run:
!which python3
!which pip3
I get
/usr/local/bin/python3
/usr/local/bin/pip3
is there something I'm doing wrong?
I’ve catch like this problem
It helped me that:
Uninstall python
And install python
Then reboot system
I guess your Catalina use 3 version py3 this time
It’s need realias
I guess on Mac OS is better to use pip3 by terminal.
Problem seemed to be installing jupyter thru homebrew. Uninstalled it, and then reinstalled it with pip and now everything is working
I followed instructions given in the TensorFlow website to install tensorflow_hub and installed it within a conda environment.
$ pip install "tensorflow>=2.0.0"
$ pip install --upgrade tensorflow-hub
I ran the above in anaconda prompt
But I'm still getting ModuleNotFoundError for 'tensorflow_hub'.
Any help here is appreciated. Thanks in advance
First thing
Check whether you have installed tensorflow_hub within that environment
conda list
If you can not find it there, maybe you have been installing it to another environment which does not matter, just install it again here.
pip install tensorflow_hub
You have probably done that so most likely you are using another kernel within your jupyter notebook, so either go to the environment of that kernel and install your package there. Or the preferred way, install your current environment yourenvironment as a new kernel and use that one in your jupyter notebook
python -m ipykernel install --user --name=yourenvironment
Now start your jupyter notebook and enjoy your package
After installing the latest scikit-learn version (19) using conda in Anaconda Jupyter, all packages are showing ModuleNotFoundError - scikit learn, numpy, matplotlib, etc. This is happening for all conda packages. After uninstalling and reinstallling, I have the same problem.
My kernel specs :
sana#skb-linux:~$ . activate my_env
(my_env) sana#skb-linux:~$ jupyter kernelspec list
Available kernels:
python3 /home/sana/anaconda3/envs/my_env/share/jupyter/kernels/python3
My code:
# scipy
import scipy
print('scipy: %s' % scipy.__version__)
Result:
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-2-73263c49dde4> in <module>()
1 # scipy
----> 2 import scipy
3 print('scipy: %s' % scipy.__version__)
ModuleNotFoundError: No module named 'scipy'
You can check for the install packages by typing !conda list in the notebook and check for scikit-learn package is there or not.
If it's not present then you can install it by !pip install scikit-learn or !conda install -c anaconda scikit-learn
later try import sklearn it should work!.
There is a useful source here, including how to update or upgrade packages..
final solution: first need activate the environment you are working and install conda package in that particular environment using conda install and do need not to install outside of your environment
sana#skb-linux:~$ . activate my_env
(my_env) sana#skb-linux:~$ conda install scikit-learn
Solving environment: done
so the sklearn package is installed in your particular environment(in my case its installed my_env)
I encountered the same issue on installing jupyter through conda, tried a lot of things, didn't work out. Finally, I remove it and re-installed it, worked fine this time, lol!!