I am trying to learn python using the conda platform, I added conda to VS Code but when I run my hello world I get this.Terminal Output
The code runs but still has an error. Also, I added tensorflow to my anaconda folders, the tensor flow base and folders show up in my conda environment page, but when I import
tensorflow using import tensorflow as tf and check the version with print(tf.__version__)
I get this error message
Related
I am working on my Master's project with MARL, and i decided to use RLLib. I created a conda environment for my project and installed RLLib:
pip install "ray[rllib]" tensorflow
Later on, i tried to run one experiment:
rllib train --algo DQN --env CartPole-v1
But got the following error: "ImportError: cannot import name 'type_spec_registry' from 'tensorflow.python.framework'"
I am using Tensorflow 2.11.
Thanks in advance!
I was trying to run one experiment from RLLib library in order to test if the library is correctly installed.
I have installed PyTorch by just using pip install torch. I also have the correct version of python installed (I don't have two different versions).
When I ran the following in VS code it returned the correct version, and when I check if PyTorch is installed with pip it works.
import torch
print(torch.__version__)
But for some reason VS code doesn't recognise torch when I try and import it, or try to inheret from nn.Module in a class.
I just get the error "Import torch could not be resolved" and "nn is not defined"
I'm really confused as to what to do as I cant find any other people having this issue and all PyTorch VS code examples I look at just install the python extension and have no issue.
Check if vscode is using the same python interpreter and environment in which pytorch was installed.
Hit cmd + shift + P and search for Interpreter. Click on Python Interpreter and choose the correct one.
Check the image shown below
Just selecting the interpreter in vs code won't work, you have to follow those steps.
(if you install PyTorch in an anaconda environment)
1-Open Anaconda Promote
2-Activate your environment (Conda activate --)
3-type Code -- (code) will open vscode
4-select interpreter Ctrl +shift +P then type Python:Selectinterpreter
5-select your anaconda env
For a university we are supposed to implement a TensorFlow project using the python libraries for tensorflow and keras. I can install both of them just fine using pip3, but executing any piece of code results in some kind of error.
I've settled on testing the very complicated code:
import keras
Using python 3.6 and the newest tensorflow and keras (pip3 install tensorflow keras) I get the error ModuleNotFoundError: No module named 'tensorflow.python'; 'tensorflow' is not a package. I checked, and import tensorflow finds the package, but returns some error about AVX instructions and dumps the core.
I researched, and my CPU does not support AVX instructions which are part of tensorflow >= 1.6.0. I could not find a precompiled version that runs on my laptop without AVX, and I don't have the time to compile myself.
I tried downgrading to tensorflow == 1.5.0 and keras == 2.1.3 which was the version when tensorflow == 1.5.0 was around, but I still get missing errors, for each version and import statement a different one.
For example when I use the code:
import keras
from keras.datasets import mnist
I instead get the error AttributeError: module 'keras.utils' has no attribute 'Sequence'. I'm on an Intel Pentium, which I assume is the problem. I am fully aware that my setup is in no way suitable for machine learning, and it isn't supposed to be, but nevertheless I'd like to work on that assignment.
Anyone got experience with installing TensorFlow on older machines?
System:
Ubuntu 18.04.2 LTS
Intel(R) Pentium(R) 3556U # 1.70GHz (Dual Core)
4GB RAM
I had the same trouble, but it seems to have solved it. (However, the Python version shall be 3.5. )
For CPUs that do not support AVX, the tensorflow must be version 1.5 or lower.
If you want to install Tensorflow 1.5, the Python version must be 3.5 or lower.
The successful procedure is as follows.
(1) Uninstall your Anaconda.
(2) Download the following version of Anaconda from the following
URL. Version: Anaconda3-4.2.0-Windows-x86_64.exe
URL:https://repo.anaconda.com/archive/ or https://repo.anaconda.com/archive/Anaconda3-4.2.0-Windows-x86_64.exe
(3) Double-click the anaconda icon of “(2)” above, and install the
anaconda according to the GUI instructions.
(4) Start Anaconda Prompt
(5) Enter “pip install tensorflow==1.5” in Anaconda Prompt and press
the return key. Wait for the installation to finish. (See the log)
(6) Enter "pip install keras==2.2.4" in Anaconda Prompt and press the
return key. Wait for the installation to finish.(See the log)
This completes the installation. If you Enter " import tensorflow " on Jupiter notebook, some future error may displayed.(See this log.)
System:
My PC does not support AVX like your PC. My PC's specs are as follows.
PC:Surface Go
CPU:Intel(R) Pentium(R) CPU 4415Y @ 1.60 GHz
Windows10:64bit
How to test ?
Enter and execute the following command on Jupiter Note. Or use this file.
import tensorflow as tf
print(tf.__version__)
print(tf.keras.__version__)
or
import tensorflow as tf
hello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()
print(sess.run(hello))
If your install is successful, then following message will be displayed on your Jupiter notebook
1.5.0
2.1.2-tf
P.S.
I'm not very good at English, so I'm sorry if I have some impolite or unclear expressions.
Sticking to the Pentium configuration is not recommended for default tensorflow builds because of AVX dependencies. Also many recent advances in this area are not available in earlier builds of TF and you will find it difficult to replicate research works. Options below:
Get a Google Colab (https://colab.research.google.com/) notebook, install Keras and TF and get going with your work
There have been genuine requests for this support, refer to this link [https://github.com/tensorflow/tensorflow/issues/18689] where unofficial builds are provided. See if one of them works
Build Tensorflow from scratch (very hard option), with the right set of flags for Bazel (remove all AVX/threading options)
Well, I am working on a GPU server. All other users are using keras with Theano backend.
I have installed TensorFlow using virtualenv and later I installed keras using usual pip command. When I try to run keras in this virtual environment, it is using Theano backend because of the /home/user/.keras/keras.json file. I know I can use TensorFlow by making changes in the json file but for some reason other users are not allowing this.
I would like to know if there is a way to use keras with TensorFlow installed in my virtual environment other than the globally installed "Theano".
NOTE: The other users still should be able to use Theano
OS: Ubuntu 16.04
Using #GPhilo documentation reference;
I successfully used TensorFlow backend by adding following lines at the starting of my code:
import os
os.environ['KERAS_BACKEND'] = 'tensorflow'
# rest of the code
Make sure you have activated your virtual environment.
From Keras' documentation:
You can also define the environment variable KERAS_BACKEND and this
will override what is defined in your config file :
KERAS_BACKEND=tensorflow python -c "from keras import backend"
Using TensorFlow backend.
My keras.json has backend specified to be tensorflow and if I open Spyder and Jupyter IDE then tensorflow is used as a backend.
Strangely if I open python or ipython shell within my WinPython installation, the backend defaults into theano. Has anyone seen this behaviour before and if so what was the solution?
I have tried playing with environment variables to no effect.
Looks like existing notebooks still say Theano. But If I create new one and enter the following then I get proper result as tensorflow
import os
os.environ['KERAS_BACKEND']='tensorflow'
import keras
keras.backend.backend()
Using TensorFlow backend.
Out[1]:
'tensorflow'
In [ ]:
I have exactly same issue. Some how after I installed shell kernel Ipython/Jupyter is pointing properly to tensor flow
import os
os.environ['KERAS_BACKEND']='tensorflow'
import keras
keras.backend.backend()