Error loading tensorflow module

Asked 2 years ago, Updated 2 years ago, 104 views

I know how to install tensorflow in an anaconda virtual environment and use tensorflow through Jupiter laptop.

Can't I write the tensorflow code using vcode instead of jupyter notebook? If you write code through cmd, atom, or vscode, you can't always find the tensorflow module.

import tensorflow as tf

hello = tf.constant("hello, tensorflow!")
sess = tf.Session()
print(sess.run(hello))

When you type,

//[Running] python "c:\WD\simple_net.py"
Traceback (most recent call last):
  File "c:\WD\simple_net.py", line 1, in <module>
    import tensorflow as tf
ImportError: No module named 'tensorflow'

[Done] exited with code=1 in 0.088 seconds

I always see this error, how can I solve it? /

python tensorflow vscode

2022-09-22 20:26

2 Answers

There seems to be no answer, so it's not enough, but I'll tell you my case.

Based on the VS code, at the integrated terminal below, Check the installed module with the pip list command If the tensorflow is not installed
If you install tensor flow with the pip install command directly in the integrated terminal window, I think it'll work. (At this time, it seems that condas are installed as basic environments, not virtual environments. I don't do anything to manage multiple versions of modules by project, so I install all modules in the basic environment.)

If numpy mat plotlib is also a problem, remove the Anaconda and enter the Visual Studio installation option, and Python, Anaconda (lately, there seems to have been TensorFlow).I think it was possible to use it without any major problems if I installed it. (In my case... Maybe the environmental variables like path were a bit of a fix.)

Anyway, I decided to use the code instead of the Anaconda installation version and Jupiter laptop I installed Python modules (anaconda) necessary for the installation of the visual studio that I used together, and tensor flow was installed with the pip command, so I am using it without any difficulty...


2022-09-22 20:26

Use the tl;dr Python: Select Interpreter command to select the Python binary within the virtual environment.

I think this problem occurred because Python virtualenv was not set in vscode.

Please refer to the official document for instructions on how to set up your Python virtual environment.


2022-09-22 20:26

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.