Issue
I'm trying to import tensorflow as ts
in my script. While everything is fine in a Notebook, when I try to recreate the same script in a .py file the import returns the following, popular message:
ModuleNotFoundError: No module named 'tensorflow'
Note that both Jupyter and terminal are using the same virtual environment. In Notebook it's picked as a Kernel and in terminal it's activated with conda
.
I was convinced the whole Kernel/env idea was about preventing exactly that kind of situations. Although I'm new to python so maybe I'm missing something basic.
Also, this might have something to do with that I'm using an M1 and macos, so I have the tensorflow-macos
installed. But please consider there might be other reasons.
Solution
Make sure your pyenv
installation doesn't interfere with the conda environments. Pyenv can overrule which python installation is used even if the conda environment has picked another. In my case it was the reason. Jupyter Notebook wasn't affected by pyenv. There are two solutions:
- Remove
pyenv
- Make sure it is clear to you how both
pyenv
andconda
are affecting your setup and correct it. Some considerations and suggestions are mentioned in this question: Installing anaconda with pyenv, unable to configure virtual environment
Answered By - wiktus239
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.