简体   繁体   中英

Tensorflow and Keras Installation Problems JupyterLab / Anaconda (Debian)

I've been trying to install keras and tensorflow for Jupyter-lab (python). I first tried with pip, but the notebook stopped functioning everytime I imported keras. After some research on different feeds, I decided to uninstall it with pip and try to reinstall it with anaconda3.
Then, there was a path issue installing tensorflow with the conda command. So I researched more and wrote this in the terminal:

export PATH="/home/myname/anaconda3/bin:$PATH"

I created another environment and could install tensorflow with (same for keras):

conda activate myenv
conda install tensorflow

I came back on the local JupyterLab and imported keras. But it couldn't find the module named keras. I tried again with pip:

!pip install keras
import keras

And got the same:

Requirement already satisfied: keras in /home/myname/.conda/envs/myenv/lib/python3.9/site-packages (2.9.0)

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
Input In [6], in <cell line: 10>()

---> 10 import keras

ModuleNotFoundError: No module named 'keras'

Is it a path problem? How can I solve it? I don't understand how it can find it, but not import it correctly. Thank you for your help !

After creating the virtual environment(myenv) in conda, open a new jupyter notebook in the same environment and you need to install TensorFlow in that environmnet using the below code:

!pip install tensorflow

import tensorflow as tf
tf.__version__

Now you can access the Keras from TensorFlow as below:

from tensorflow import keras
keras.__version__

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM