Visual Studio Code: ModuleNotFoundError: No module named 'tensorflow' - tensorflow

Setup:
Anaconda3, TensorFlow 2.6.3, cuDNN Archive v8.1.0, CUDA Toolkit 11.2.0, VS Vode 1.64.2
Hello everyone,
since the beginning of this week I have problems importing the tensorflow module.
After pressing the "Run Python File" button in VS Code I get the following error message (highlighted in red):
error module tensorflow
If I start the Python script "manually" (python test.py) everything works as usual (see picture above. Highlighted in green).
Can recently executed Windows updates cause the problem?
I am grateful for any feedback.
Greetings
Chris

The error is caused by the new Python extension version in vscode:
https://github.com/microsoft/vscode-python/issues/18634
For now, I resolved this issue by switching back to previous version:
https://github.com/microsoft/vscode-python/issues/18639#issuecomment-1060216458

Related

Import pandas could not be resolved from source Pylance(reportMissingModuleSource)

I've been trying to use the packages pandas, numpy, matplotlib, seaborn in my "Visual Studio Code", but the program keeps showing me the following message:
"import pandas could not be resolved from source Pylance(reportMissingModuleSource)"
Previously to Visual Studio Code I installed "Anaconda" to use Jupyter, and now it says that i have the existing packages (pandas, numpy...) but keeps appearing this message that doesn't allow me to use pandas in my Visual Studio.
Anyone could help me to solve this issue?
I tried installing again all the packages to check if they didn't exist but apparently are installed all of them but in another route. I can't find how is the way to put them so the Visual Studio Code recognizes them and I can use them.
I also received similar an error on my IDE VSCode and currently using mac m1 .First we need to make sure that the python3 interpreter version from terminal version is the same with our python version selection in VSCode.
open terminal.
type 'python3'
then you will see your python version.(my python3 version is 3.9.12)
python3 version
open your IDE VSCode
open any/current folder that related to python project on IDE VSCode
Check your python version at the bottom right on IDE VSCode (in my case the python version is 3.10.64)
change or switch VSCode python version from 3.10.64 to 3.9.12 (same with your python version on your pc)
done
I also had this problem and it was because of version mismatches.
I had installed Python AND Anaconda. If anyone else has done this and gets this error, you need to uninstall both. Then install Anaconda only; Python (the compatible version) is installed as part of that process.
See https://docs.anaconda.com/anaconda/install/windows/
Also, you can click on the interpreter version at the bottom left corner of the screen (Vs.code 2022) it should show a dropdown menu with a list of the available and selected python interpreter. Click on add interpreter path and paste the path to the python interpreter with all the required modules installed and click enter. This should resolve the problem.
I re-entered the path to Python interpreter and warning disappeared. Hope that helps you.
Another way I solved this issue having followed every other installation process to the letter was deactivating Pylance. Works a (py)charm now.
I encountered this problem in VSCode under remote to WSL2 of Windows 10. The Python version is correct as interpreter (3.9.13) and the terminal in VSCode is also under the same envs (ie. VSCode ran "conda activate xx" and (xx) is shown in prompt)
Originally, I tried to install the pandas by the following command.
sudo apt-get install python3-pandas
Pandas was installed successfully as stated in the terminal but the problem is still there.
When I try to install pandas by the following command, the problem solved.
pip install pandas

Error with installation of pycocotools for Detr Tensorflow

I'm trying to use Detr Tensorflow models and need to install pycocotools. On a Windows 10 PC, I'm executing this in a Visual Studio Code. I'm following the steps provided in this
GitHub repo : https://github.com/Visual-Behavior/detr-tensorflow#install
I attempted to pip-install pycocotools and received the following error (fails to construct wheel):
Screenshot of Error
Any idea on how to remove this error ?
The solution is in the error output.
You need to install Microsoft C++ Build Tools.

Cannot import tensorflow in Spyder

When I run import keras in Spyder, the error message states that keras cannot find a tensorflow with version > 2.2
When I run import tensorflow, I get the following error message:
File "C:\Users\xxx\Anaconda3\Lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 64, in
from tensorflow.python._pywrap_tensorflow_internal import *
ImportError: DLL load failed while importing _pywrap_tensorflow_internal: Det går inte att hitta den angivna modulen.
(Last message in local tribal language translates as "Can not find the specified module")
I have installed keras and tensorflow via Anaconda using pip. The tensorflow version installed is 2.4.0, Keras 2.4.3 and Python 3.8
If I look in the folder C:\Users\xxx\Anaconda3\Lib\site-packages\tensorflow\python_pywrap_tensorflow_internal, there is a file called _pywrap_tensorflow_internal.lib
I am not a Python expert, but I am guessing this file contains the binary code that should be called when the error is thrown ? The folder C:\Users\xxx\Anaconda3\Lib\site-packages is added to the Python path manager from within Spyder-
I used to being able to run Keras with this computer (Windows 10, x64). But since I formatted the hard drive and reinstalled everything from scratch it does not work. No GPU involved.
Sidenote: Some replies (1, 2) to similar questions on this site suggests it has to do with the Visual studio distribution. I have installed VS 2015, previously I used VS 2019. I would prefere not to install VS 2019 if it can be avoided
Installing the Microsoft Visual C++ 2015 Redistrutable Update 3 solved the problem. I think I found it here

On win7 when import tensoreflow it shows "no module named_pywrap_tensorflow" after i do use the vc_redist

the redist(x86) is different from those answers provided before(x64).Is that the point?
Meanwhile it shows "Unless you are using bazel, you should try to import tensorflow from its source directory".But i didn't do that.
Ensure that you have Visual Studio Installed and that MSVCP140.DLL is on your computer AND in your PATH envVar. You shouldn't be building from source on Windows as it is not supported. I assume that you installed via pip?
Check for the DLL, VS, your PATH variables and, if that doesn't work, redownload the vc_redist_x64 version.
Failing that, uninstall Tensorflow and try again with pip install tensorflow or from a nightly. I had a similar issue and starting fresh seemed to help.

PyPlot in Julia giving "no module named site" error

I have started playing with Julia today. I was following Steven's MIT turorials to get started. However, when I reached the Plotting section I tried importing PyPlot with:
using PyPlot
however it gave me the following error:
ImportError: No module named site
WARNING: backtraces on your platform are often misleading or partially incorrect
could not load module python: The specified module could not be found.
at C:\Users\Dipto\.julia\PyPlot\src\PyPlot.jl:32
at In[1]:1
in pyinitialize at C:\Users\Dipto\.julia\PyCall\src\PyCall.jl:406
I use Canopy as my Python installation, so all modules required by pyplot should already be available on the machine.
N.B. As indicated in the tutorial I did use Pkg.add("PyPlot") in Julia to install pyplot in Julia as well.
It looks like problem is that PyCall (the bridge between Julia and Python) does not work with Canopy. See: https://github.com/stevengj/PyCall.jl/issues/42.
I ran into the same problem recently after doing a package update, Pkg.update(). It gave me some errors with Nettle and whatnot during the update.
The solution was to delete the .julia directory and reinstall all the needed packages.
The only caveat I feel I have to give is that previous to this recent "reinstall" I used http instead of git for downloading Julia packages. I don't expect this to be an issue though.
Setup
Windows 7 Pro 64-bit
Julia 0.2.0 (2013-11-16 23:44 UTC)
Python 3.3.2 (v3.3.2:d047928ae3f6)
PyPlot 1.1.0
Anaconda (unknown version, installed October 28, 2013)