I am trying to install TensorFlow on my MacPro 2.7 GHz Intel Core i5 8 GB 1867 MHz DDR3 | El Capitan.
I used: $ pip install https://storage.googleapis.com/tensorflow/mac/tensorflow-0.5.0-py2-none-any.whl
This is what I got:
Collecting tensorflow==0.5.0 from [website from above]
100% |████████████████████████████████| 9.8MB 65kB/s
Installing collected packages: tensorflow
Successfully installed tensorflow-0.5.0
However, when I open a Python shell and use:
MacPro:TesnsorFlow myName $ python
import TensorFlow
I get the following messages:
Traceback (most recent call last):
File "", line 1, in
ImportError: No module named TensorFlow
I am not sure why it shows like if I am inside of a TensorFlow folder. For example:
MacPro:TesnsorFlow myName $
When I Type MacPro:TesnsorFlow myName $ python I get the error
If you have clear instructions on how to install tensorflow, please share it with me. I tried the instructions from www.tensorflow.org and I got more lost. I even installed Anaconda-Navigator because someone told me it had tensorflow and it did not. Guys/girls, I am trying without any success.
Note: I am having issue with Stackoverflow
In fact, there was nothing wrong with your installation of TensorFlow, it was just an import error.
You should use import tensorflow instead of import Tensorflow because Python is case sensitive!
Try to install in virtual-env:
pip install TensorFlow
Then:
import tensorflow
For me, this worked: python3 -m pip install --upgrade https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-0.12.0-py3-none-any.whl
Related
I am trying to install the Coral Edge TPU software on MacOS 11.5 by following these instructions:
https://coral.ai/docs/accelerator/get-started/#3-run-a-model-on-the-edge-tpu
But by the time I enter the following command into the console:
python3 examples/classify_image.py --model test_data/mobilenet_v2_1.0_224_inat_bird_quant_edgetpu.tflite --labels test_data/inat_bird_labels.txt --input test_data/parrot.jpg
I get the following error:
Traceback (most recent call last):
File "/Users/fabrizio/Desktop/work/MagneticChessResearch/machine learning/Coral/edgetpu_runtime/coral/pycoral/examples/classify_image.py", line 36, in <module>
from pycoral.adapters import classify
ModuleNotFoundError: No module named 'pycoral.adapters'
Any ideas?
I have the same issue on Windows 10. If you are using Python 3.9.x, and used the command pip3 install --extra-index-url https://google-coral.github.io/py-repo/ pycoral to install pycoral, then you will be installing a very old version of pycoral which does not have pycoral.adapters module. I think this is because the pycoral repo currently (June 2021) does not have the package built for Python 3.9.x.
The solution is to either build and install pycoral from source on your Mac using Python 3.9.x, or downgrade Python to 3.8.x and install pycoral again.
I followed this tutorial, https://www.youtube.com/watch?v=ykCY_tJbhNw to install tensorflow in a mac (M1 processor). However when I import tensrflow I get the following error. Any ideas what it might be?
The steps include,
installing brew (was alreadyy installed)
install conda (was already installed)
installing miniforge
download tensorflow-macos from github page
conda activate mlEnv
/Users/imantha/Software/tensorflow_macos/install_venv.sh -p
When prompted to input the path : /Users/imantha/Software/anaconda3/envs/mlEnv/
and select yes to install tensorflow
tensorflow was successfully installed and when typed conda list, the package is listed.
However when I start python session in the shell and type import tensorflow as tf, I get the following error
Traceback (most recent call last):
File "/Users/imantha/Software/anaconda3/envs/mlEnv/lib/python3.8/site-packages/tensorflow/python/pywrap_tensorflow.py", line 64, in <module>
from tensorflow.python._pywrap_tensorflow_internal import *
ImportError: dlopen(/Users/imantha/Software/anaconda3/envs/mlEnv/lib/python3.8/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so, 6): no suitable image found. Did find:
/Users/imantha/Software/anaconda3/envs/mlEnv/lib/python3.8/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so: mach-o, but wrong architecture
/Users/imantha/Software/anaconda3/envs/mlEnv/lib/python3.8/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so: mach-o, but wrong architecture
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/imantha/Software/anaconda3/envs/mlEnv/lib/python3.8/site-
packages/tensorflow/__init__.py", line 41, in <module>
from tensorflow.python.tools import module_util as _module_util
File "/Users/imantha/Software/anaconda3/envs/mlEnv/lib/python3.8/site-
packages/tensorflow/python/__init__.py", line 39, in <module>
from tensorflow.python import pywrap_tensorflow as _pywrap_tensorflow
File "/Users/imantha/Software/anaconda3/envs/mlEnv/lib/python3.8/site-
packages/tensorflow/python/pywrap_tensorflow.py", line 83, in <module>
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "/Users/imantha/Software/anaconda3/envs/mlEnv/lib/python3.8/site-
packages/tensorflow/python/pywrap_tensorflow.py", line 64, in <module>
from tensorflow.python._pywrap_tensorflow_internal import *
ImportError:
dlopen(/Users/imantha/Software/anaconda3/envs/mlEnv/lib/python3.8/site-
packages/tensorflow/python/_pywrap_tensorflow_internal.so, 6): no suitable image
found. Did find:
/Users/imantha/Software/anaconda3/envs/mlEnv/lib/python3.8/site-
packages/tensorflow/python/_pywrap_tensorflow_internal.so: mach-o, but wrong
architecture
/Users/imantha/Software/anaconda3/envs/mlEnv/lib/python3.8/site-
packages/tensorflow/python/_pywrap_tensorflow_internal.so: mach-o, but wrong
architecture
Failed to load the native TensorFlow runtime.
See https://www.tensorflow.org/install/errors
for some common reasons and solutions. Include the entire stack trace
above this error message when asking for help.
There are quite a few things to do in order to install TensorFlow on the Macbook M1 chip:
First, install Python 3.8.9 (I have tried on this version, not sure about any other versions)
Go to your project dir
install hdf5 by running brew install hdf5 if you do not have brew, you can download it here: https://brew.sh/
Above hdf5 install will spit out its location: use it and run:
export HDF5_DIR=<hdf5_location> for version 1.13.0 (my case) the following:
export HDF5_DIR=/opt/homebrew/Cellar/hdf5/1.13.0
create a virtual environment using virtualenv venv (choose whatever method for creating virtual environment or do not create virtual environment, it's fine. To install virtualenv, run pip3 install virtualenv)
(Skip this if not using virtual environment) Activate virtual environment by running: source venv/bin/activate
Now, we have everything require to install Tensorflow on mac with M1 chip including GPU version
To install Tensorflow and related libs, run following:
(If using virtual env, run following)
venv/bin/pip install --no-binary=h5py h5py
venv/bin/pip install tensorflow-macos
venv/bin/pip install tensorflow-metal
Not using virtual env, run following:
pip3 install --no-binary=h5py h5py
pip3 install tensorflow-macos
pip3 install tensorflow-metal
Now, your TensorFlow installation has been completed!
Try it out:
import tensorflow as tf
print("TF version:", tf.__version__)
print("Number GPUs Available: ", len(tf.config.experimental.list_physical_devices('GPU')))
print("Number CPUs Available: ", len(tf.config.experimental.list_physical_devices('CPU')))
Build Tensorflow from source by following the instructions mentioned here.
See this comment.
OR,
Try the workaround mentioned here.
The below way is the simplest and efficient way from which we can install tensorflow in Mac M1
NOTE: Mac M1 has ARM64 arch not X86_64 so we need to be very careful while downloading packages. Anaconda is available for Mac M1 users : https://repo.anaconda.com/archive/Anaconda3-2022.05-MacOSX-arm64.sh
Following are the steps to victory:
Download Anaconda from above link
create virtual env ( Optional )
pip install tensorflow-macos
Thats it!
Reference video link which may be useful : https://www.youtube.com/watch?v=5DgWvU0p2bk
If you want to use an Anaconda distribution, you might want to consider Miniconda3. Currently, I'm not sure whether it's possible to install TensorFlow using Anaconda.
Download Miniconda3 using this link. Both the .bash and the .pkg files should do - choose one of them. However, for M1, only the .bash file seem to have worked, while for M2 both worked.
If you used the .bash file above, then do the following to start the installation:
chmod +x ~/Downloads/Miniforge3-MacOSX-arm64.sh
sh ~/Downloads/Miniforge3-MacOSX-arm64.sh
Create a conda environment with Python 3.9: conda create -n tf_env python=3.9 (latest Python version didn't work as I'm writing this).
Install TensorFlow and dependencies:
conda install -c apple tensorflow-deps
python -m pip install tensorflow-macos
python -m pip install tensorflow-metal
At this point, you should make sure that the Numpy version is up to date to not run into errors when importing TensorFlow. I used version 1.23.3. python -m pip install numpy --upgrade.
Install jupyter notebook using conda install notebook.
If everything has been installed without errors, running the following code in a jupyter notebook should correctly import TensorFlow and print out the version as well as verifying the presence of a GPU.
import tensorflow as tf
gpu = len(tf.config.list_physical_devices('GPU')) > 0
print(f"TensorFlow Version: {tf.__version__}")
print("GPU is", "available" if gpu else "NOT available")
I'm trying to install tensorflow with pip in virtualenv in Anaconda for Windows 10. After activating my virtualenv, when I run pip install tensorflow, I get an error:
ERROR: Could not find a version that satisfies the requirement tensorflow (from versions: none)
ERROR: No matching distribution found for tensorflow
This might be because tensorflow doesn't support Python3.8 which I am using. The update of the post says that it should now work, but it doesn't for me. I tried what the answers suggest with no better luck.
So, I tried the following to downgrade to Python3.7:
conda install python=3.7.1
setting a virtualenv with Python3.7 version
creating a conda environment with Python3.7
installing an older version of Anaconda that contains Python3.7
But any of these attempts incredibly see Python switch back to version 3.8 when I activate the virtualenv. Even if I destroy the environment and create it again in the older Anaconda.
I also tried py -3.7 -m pip install tensorflow in the Anaconda with Python3.7 (it doesn't find the correct version of Python when using the more recent Anaconda). It lead to the error:
Cannot uninstall 'wrapt'. It is a distutils installed project and thus
we cannot accurately determine which files belong to it which would
lead to only a partial uninstall.
I fixed it running conda update wrapt and launched the tensorflow installation command again. After many package installations and removals, it displayed the following error:
ERROR: After October 2020 you may experience errors when installing or
updating packages. This is because pip will change the way that it
resolves dependency conflicts.
We recommend you use --use-feature=2020-resolver to test your packages
with the new resolver before it becomes the default.
pytest-doctestplus 0.2.0 requires pytest>=2.8.0, but you'll have
pytest 0.0.0 which is incompatible. pytest-astropy 0.5.0 requires
pytest>=3.1.0, but you'll have pytest 0.0.0 which is incompatible.
And in effect, I can see that the installation didn't work:
pip freeze > requirements.txt creates an empty requirements.txt
in the Python console, when I try to import keras, it resolves to:
Traceback (most recent call last):
File "C:\Users\my_private_path\venv\lib\site-packages\keras\__init__.py", line 3, in <module>
from tensorflow.keras.layers.experimental.preprocessing import RandomRotation
ModuleNotFoundError: No module named 'tensorflow'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\my_private_path\venv\lib\site-packages\keras\__init__.py", line 5, in <module>
raise ImportError(
ImportError: Keras requires TensorFlow 2.2 or higher. Install TensorFlow via `pip install tensorflow`
It seems that no matter how many paths I try, tensorflow doesn't like virtualenv in Anaconda. Would someone have a path that works?
I use virtual environments with tensorflow all the time and it works fine. First use Anaconda to create a new environment. From the Anaconda home page click on Environments.
When the Environment page appears click on create. A new window will pop up. Give the environment a name (for example call it tf), check the python checkbox. From the dropdown select python 3.7. A new environment called tf is created with python 3.7 installed.
Now go to the Anaconda prompt which is conda. type in conda activate tf. Now use conda to install tensorflow (do not use pip). Conda automatically installs cudnn 7.6.5 and CUDA Toolkit 10.1.243 and tensorflow 2.1.0. If you want tensorflow 2.2 first install 2.1.0 as described. Then use pip to install 2.2 with pip install tensorflow ==2.2.0. 2.2 is compatible with the toolkit and cudnn versions installed with 2.1. Conda can only install tensorflow up to version 2.1.0. Install whatever other packages you need using either pip or conda.
I have anaconda installed on my Win 7 machine with a GTX1070.
I have been trying to install tensorflow gpu version for the past hour with no luck. I followed the tutorials on the tensorflow website to no success. They ask for you to install CUDA 8.0 and Cudll 6.0 which I do. I then add the location of cudnn64_6.dll, cudart64_80.dll and the libnvvp folder to my path variables. I then set up a virtual environment in conda and run the following command:
(tensorflow)C:> pip install --ignore-installed --upgrade tensorflow-gpu
I believe when I do this, it installs tensorflow 1.5 which seems to require CUDA tools 9.0 because I get an error saying that cudart64_80.dll cannot be found. So I update my CUDA tools to 9.0 and download the corresponding Cuda library. I then change my path variables. Now I dont get any missing dll errors however, I am now faced with the following error
ModuleNotFoundError: No module named 'absl'
Does anyone have any suggestions as to what I can do from here on?
This was caused by a Python version issue for me. I had the absl package installed on my Python 2.x, but my Python 3.x didn't have it. So I just made sure that both Pythons on my machine had the package installed:
pip install absl-py
pip3 install absl-py
Here is how I solved it in my end.
I was getting the error even though absl-py was already installed.
When I used pip install absl-py I got the following error:
Requirement already satisfied: absl-py in c:\users\stack\appdata\local\programs\python\python38\lib\site-packages (0.9.0)
Requirement already satisfied: six in c:\users\stack\appdata\local\programs\python\python38\lib\site-packages (from absl-py) (1.15.0)
I fixed it by reinstalling, i.e. by using:
pip uninstall absl-py
pip install absl-py
Then I faced a similar error with wrapt:
ModuleNotFoundError: No module named 'wrapt'
Fixed wrapt as well by uninstalling and then installing it again.
pip uninstall wrapt
pip install wrapt
Try:
conda install tensorflow
conda install -c anaconda absl-py
This worked for me.
For more information see: https://anaconda.org/anaconda/absl-py
I was facing the same issues and pip (or pip3) install absl-py was not working.
python --version showed I was using the wrong python version (2.7). So I changed the python version to 3.5 (https://askubuntu.com/questions/320996/how-to-make-python-program-command-execute-python-3)
This worked for me.
You can use the Anaconda GUI to install absl-py pack to solve the problem:
Select the uninstall columnand search absl-py to apply it.
Try another version of absl-py. My default absl version is 0.8.1 and python is 3.6:
$pip install absl-py==0.8.0
works for me.
Or change my environment python version to 3.7 also works.
This is quite late but still worth posting. What they don't tell you on the NVidia website is that there is one more path you need to add to your environment variables. The path is;
c:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\extras\CUPTI\libx64
It may not be exactly the same on your installation as it depends on where you installed your CUDA tools.
You could also just use pip to install TF GPU version but pip installs TF 1.1 which is fairly old.
For me, "pip3 install absl-py" don't work:
I received: "ModuleNotFoundError: No module named 'absl' ", when I was trying import tensorflow:
import tensorflow
Traceback (most recent call last):
File "", line 1, in
File "/opt/anaconda3/lib/python3.6/site-packages/tensorflow/init.py", line 22, in
from tensorflow.python import pywrap_tensorflow # pylint: disable=unused-import
File "/opt/anaconda3/lib/python3.6/site-packages/tensorflow/python/init.py", line 63, in
from tensorflow.python.framework.framework_lib import * # pylint: disable=redefined-builtin
File "/opt/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/framework_lib.py", line 25, in
from tensorflow.python.framework.ops import Graph
File "/opt/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 55, in
from tensorflow.python.platform import app
File "/opt/anaconda3/lib/python3.6/site-packages/tensorflow/python/platform/app.py", line 24, in
from tensorflow.python.platform import flags
File "/opt/anaconda3/lib/python3.6/site-packages/tensorflow/python/platform/flags.py", line 25, in
from absl.flags import * # pylint: disable=wildcard-import
ModuleNotFoundError: No module named 'absl'
But if I compile absl-py from scratch, all goes right:
jk#D17:~/py/004/abseil-py-master$ python setup.py install
running install
running bdist_egg
running egg_info
.......
Using /opt/anaconda3/lib/python3.6/site-packages
Finished processing dependencies for absl-py==0.4.0
and then:
import tensorflow
is OK
Find the absl-py related folder in your site-packages folder and delete it. Try reinstalling pip3 install absl-py. I solved this way, I hope to be useful to you.
If you are using Anaconda make sure you install jupyter notebook from Home. if not you can import it from python CLI but it will give "No module named 'absl' error when importing TensorFlow"
In hopes that this might help someone in the future. I had similar issues installing/using tensorflow and by extension the absl python package. There were some issues relating to a pure pip installation so I had to find an alternate route.
This is the process I followed.
Download and install miniconda:
wget https://repo.continuum.io/miniconda/Miniconda3-3.7.0-Linux-x86_64.sh -O ~/miniconda.sh
bash ~/miniconda.sh -b -p $HOME/miniconda
add conda to PATH (Optional):
export PATH="$HOME/miniconda/bin:$PATH"
activate the conda environment:
source $HOME/miniconda/bin/activate
At this point you should have (base) as your sourced condo environment. From this environment perform the following:
conda create -n tensorflow python=3.7
activate tensorflow
Just to note, at this point you should be working in the (tensorflow) environment. It would have replaced the base environment. It is also the env where you would run your tensorflow related job (that failed and brought you here).
pip install --ignore-installed --upgrade tensorflow
pip install absl-py
At this point you might need to install additional dependencies such as numpy.
My goal was to be able to run tensorflow tools and this worked for my ends. Hope it may be useful to someone else in the future.
I got the No module named absl error when I tried to install tf-nightly 2.9.0.dev20220203 on my Ubuntu 20.04.3 machine.
Reinstalling absl-py did not directly worked.
While reinstalling absl, I got this error: ERROR: tf-nightly 2.9.0.dev20220203 has requirement gast<=0.4.0,>=0.2.1, but you'll have gast 0.5.3 which is incompatible.
So I uninstalled absl-py:
pip uninstall absl-py
Then downgraded gast:
pip uninstall gast
pip install gast==0.4.0
Finally,
pip install absl-py
Trying to install OpenCV and running into an issue where attempting to import cv2 results in this output -
RuntimeError: module compiled against API version 9 but this version of numpy is 7
Traceback (most recent call last):
File "<pyshell#4>", line 1, in <module>
import cv2
ImportError: numpy.core.multiarray failed to import
I'm running on Windows 7 x64, Python v 2.7.9
Thanks!
The error is telling you that you have an out of date version of numpy. If you used pip to install things you can simply run pip install numpy -U, or download the appropriate version from their website.
In case
pip install -U numpy
doesn't work (even with sudo), you may want to make sure you're using the right version of numpy. I had the same "numpy.core.multiarray failed to import" issue, but it was because I had 1.6 installed for the version of Python I was using, even though I kept installing 1.8 and assumed it was installing in the right directory.
I found the bad numpy version by using the following command in my Mac terminal:
python -c "import numpy;print numpy.version;print numpy.file";
This command gave me the version and location of numpy that I was using (turned out it was 1.6.2). I went to this location and manually replaced it with the numpy folder for 1.8, which resolved my "numpy.core.multiarray failed to import" issue. Hopefully someone finds this useful!
I had a similar problem and I solved it by downgrading my numpy version.
What I did was:
pip install opencv-python
pip uninstall numpy
pip install numpy=1.18
This has worked for me using
Python 3.7
opencv-python 4.4.0.46
numpy 1.18.0
linux: sudo apt-get install python-numpy
if you are using ubuntu bionic beaver then try running: sudo apt-get install python-numpy
had the same issue, resolve by running the above command.
Hope it helps
In your environment you can try this command:
conda uninstall numpy
conda install -c conda-forge numpy
I use Python 3.7 # RPI 4.
For opencv to install properly I had to install the listed libraries below.
(Not every package was actually installed, after request)
Regarding Numpy, I think one should stick to the latest version.
For me what worked is to uninstall the existing version 1.16.2 and stick with the current stable 1.21.2.
Stackoverflow topic at missing libraries here: ImportError: libcblas.so.3: cannot open shared object file: No such file or directory.