Inkyu Kim
Inkyu Kim

Reputation: 155

How to import a module once I have installed the module on a virtual environment - TensorFlow

I am very new to this virtual environment concept. So if you could also explain that, it would be great.

Anyways, I am using Anaconda3. Here are the steps that I took to try to use TensorFlow.

  1. From "base" anaconda I tried to install, which gave me the below error.
(base) C:\Users\ikim1>conda create -n tf tensorflow
Collecting package metadata (current_repodata.json): done
Solving environment: failed with repodata from current_repodata.json, will retry with next repodata source.
Collecting package metadata (repodata.json): done
Solving environment: done

FYI, the Environment -> base tab on Anaconda3 did not show TensorFlow - seems like some people were lucky that their Anaconda3 just came with TensowFlow Module...

  1. After reading some documentation, I realized that using virtual environment can solve the issue. And then after using "tf" as a virtual environment name, I was able to install TensorFlow.

After the install, I ran this code

conda activate tf

to activate the environment.

  1. On Spyder, I checked if TensorFlow would import with the below code
import tensorflow as tf

which gives me this error : ModuleNotFoundError: No module named 'tensorflow'

Thus my question is do I need to change directory so that Python knows where it needs to import the module from? So do I need to write a code like below in Spyder?

cd "my virtual environment" (not sure what the code would be)
import tensorflow as tf

Or did I just make some mistake installing it?

Upvotes: 0

Views: 115

Answers (1)

user11530462
user11530462

Reputation:

Please run the following command to see if Tensorflow is installed. It will either state that the package is not installed or display a bunch of information about it.

pip show tensorflow

If the Tensorflow package is not already installed, please try installing it in the environment where you are working with the following commands before attempting to import tensorflow.

# activate the environment
conda activate tf
# install tensorflow
pip install tensorflow

Upvotes: 0

Related Questions