Cannot import tensorflow in vscode - python

I have installed tensorflow in a virtual environment and can import Tensorflow in jupyter notebook or terminal. I am now learning to use VScode, so I try to launch it in the jupyter notebook within the VScode, but Tensorflow cannot be imported.
It shows ModuleNotFoundError: No module named 'tensorflow', but I have installed it and it can be used in the terminal or jupyternotebook.
I also tried to define the path of the python interpreter, but it did not work. Could someone help me out? Tons of thanks.

Try:
This works for me.
pip --version
python -m pip install --upgrade pip
pip3 install tensorflow==2.0.0

pip --version
python -m pip install --upgrade pip
pip3 install tensorflow==2.8.0
Worked for me.

Related

How can I solve this Tensorflow using and installing Error?

I had used tensorflow before this time.Now,tensorflow is installed but it cannot be imported.Moreover,it cannot be installed again.What happened in tensorflow?I searched many solutions for this error but I cannot find.When tensorflow is installed with pip,this error appears.
Unable to create process using 'C:\Users\hp\Anaconda3\envs\tf-gpu\python.exe C:\Users\hp\Anaconda3\envs\tf-gpu\Scripts\pip-script.py install tensorfow'
And when it is installed with anaconda,it can be installed,but cannot be imported,"ModuleNotFoundError: No module named 'tensorflow'".How can I solve this trouble to reuse tensorflow without reinstalling anaconda ,please help me.Thanks a lot in advance!!
You can uninstall and reinstall the pip:
python -m pip uninstall pip
python -m pip install --upgrade pip
or update pip:
python -m pip install -upgrade pip

Jupyter notebook cannot import package already installed via pip

python 3.8.12 installed by pyevn seems working as expected, but numpy installed using pip cannot be imported.
pip --list ran in Jupiter notebook shows the package has been installed already.
So as per the path you stated in your comment (reply), execute this command:
/usr/local/opt/python#3.9/bin/python3.9 -m pip install pandas

ModuleNotFoundError: No module named 'tensorflow_hub'

I followed instructions given in the TensorFlow website to install tensorflow_hub and installed it within a conda environment.
$ pip install "tensorflow>=2.0.0"
$ pip install --upgrade tensorflow-hub
I ran the above in anaconda prompt
But I'm still getting ModuleNotFoundError for 'tensorflow_hub'.
Any help here is appreciated. Thanks in advance
First thing
Check whether you have installed tensorflow_hub within that environment
conda list
If you can not find it there, maybe you have been installing it to another environment which does not matter, just install it again here.
pip install tensorflow_hub
You have probably done that so most likely you are using another kernel within your jupyter notebook, so either go to the environment of that kernel and install your package there. Or the preferred way, install your current environment yourenvironment as a new kernel and use that one in your jupyter notebook
python -m ipykernel install --user --name=yourenvironment
Now start your jupyter notebook and enjoy your package

Tensorflow module not found by Jupyter notebook

Problem: Jupyter says "Module not found" when I try to import Tensorflow on Mac.
Background:
Virtualenv 16.7.9 installed & activated (venv)
Python 3.7.6 installed
PIP 19.3.1 installed
Tensorflow 2.1.0 installed using PIP as per official install instructions
At the command line, I can activate venv, start python3 then import tensorflow and display the tensorflow version correctly. But Tensorflow won't import from within Jupiter. And if I try to change the kernel within a Jupyter notebook, only Python3 is listed.
On other threads, people recommend using anaconda, but I've used PIP to install Tensorflow as recommended in the above link.
Any ideas?
Install a Jupyter Kernel
You need to install a kernel inside the env and then use Jupyter.
ipython kernel install --user --name=.venv
Then restart jupyter, click new, you should see .venv in your kernel list.

Matlab kernel in Jupyter [duplicate]

When I execute jupyter notebook in my virtual environment in Arch Linux, the following error occurred.
Error executing Jupyter command 'notebook': [Errno 2] No such file or directory
My Python version is 3.6, and my Jupyter version is 4.3.0
How can I resolve this issue?
It seems to me as though the installation has messed up somehow. Try running:
# For Python 2
pip install --upgrade --force-reinstall --no-cache-dir jupyter
# For Python 3
pip3 install --upgrade --force-reinstall --no-cache-dir jupyter
This should reinstall everything from PyPi. This should solve the problem as I think running pip install "ipython[notebook]" messed things up.
For me the issue was that the command jupyter notebook changed to jupyter-notebook after installation.
If that doesn't work, try python -m notebook, and if it opens, close it, then
export PATH=$PATH:~/.local/bin/, then refresh your path by opening a new terminal, and try jupyter notebook again.
And finally, if that doesn't work, take a look at vim /usr/local/bin/jupyter-notebook, vim /usr/local/bin/jupyter, vim /usr/local/bin/jupyter-lab (if you have JupyterLab) and edit the #!python version at the top of the file to match the version of python you are trying to use. As an example, I installed Python 3.8.2 on my mac, but those files still had the path to the 3.6 version, so I edited it to #!/Library/Frameworks/Python.framework/Versions/3.8/bin/python3
Try this command: python -m IPython notebook
Credits to the GitHub user Milannju who provided the solution here.
This worked for me. (Python 3.6 on Ubuntu 18.04 LTS)
export PATH=$PATH:~/.local/bin/
On Ubuntu 18.10, the following command helped me out.
sudo apt-get install jupyter-notebook
Jupyter installation is not working on Mac Os
To run the jupyter notebook:-> python -m notebook
Use the command below and if you are using pip3 replace pip by pip3
pip install --upgrade --force-reinstall jupyter
This worked for me.
Since both pip and pip3.6 was installed and
pip install --upgrade --force-reinstall jupyter
was failing, so I used
pip3.6 install --upgrade --force-reinstall jupyter
and it worked for me.
Running jupyter notebook also worked after this installation.
Deactivate your virtual environment if you are currently in;
Run following commands:
python -m pip install jupyter
jupyter notebook
For me the fix was simply running pip install notebook
Somehow the original Jupiter install got borked along the way.
I'm trying to get this going on VirtualBox on Ubuntu. Finally on some other post it said to try jupyter-notebook. I tried this and it told me to do sudo apt-get jupyter-notebook and that installed a bunch of stuff. Now if I type command jupyter-notebook, it works.
If you are on Fedora installing python3-notebook resolved my problem.
# dnf install python3-notebook

Categories