I try to learn TensorFlow with Python. My problem is with import TF module. Here is my configuration: Python 3.6.1, Windows 7 (with MSVCP140.dll)
I've installed TensorFlow by command (in power shell). It works.
python -m pip install --upgrade tensorflow
But when I run python environment and try import Tensor Flow
import tensorflow as tf
I get errors, this error raise another errors related with it, but at the beginning I want to resolve this first
Traceback (most recent call last): File
"C:\Users\Jacek\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\pywrap_tensorflow.py",
line 18, in swig_import_helper
fp, pathname, description = imp.find_module('_pywrap_tensorflow', [dirname(file)]) File
"C:\Users\Jacek\AppData\Local\Programs\Python\Python36\lib\imp.py",
line 296, in find_module
raise ImportError(_ERR_MSG.format(name), name=name) ImportError: No module named '_pywrap_tensorflow'
The problem was the cuDNN Library for me - for whatever reason cudnn-8.0-windows10-x64-v6.0 was NOT working - I used cudnn-8.0-windows10-x64-v5.1 - ALL GOOD!
My setup working with Win10 64 and the Nvidia GTX780M:
Be sure you have the lib MSVCP140.DLL by checking your system/path - if not get it here
Run the windows installer for python 3.5.3-amd64 from here - DO NOT try newer versions as they probably won't work
Get the cuDNN v5.1 for CUDA 8.0 from here - put it under your users folder or in another known location (you will need this in your path)
Get CUDA 8.0 x86_64 from here
Set PATH vars as expected to point at the cuDNN libs and python (the python path should be added during the python install)
If you run Windows 32 be sure to get the 32 bit versions of the files mentioned above.
Solution is downgrade Python to version 3.5, and install again TensorFlow. It works for me
This is a known error. There is a file named MSVCP140.DLL, that you will need in your system to run TensorFlow. Check if this file is in your %path%. If it is not, download Visual Studio C++. It is free and you can download it here: https://www.visualstudio.com/vs/cplusplus.
Solution:-
Don't suffer a lot. Simply downgrade your python version from 3.6.1 to 3.5.2 and
install tensorflow again.. you need not to upgrade the package.
"pip install tensorflow" will automatically download latest version (probably
1.0.1)
Steps:-
Step 1:- conda search python
Step 2:- conda install python=3.5.2
Step 3:- pip install tensorflow
Step 4:- import tensorflow as tf
Horray!!.. It works..
Hope you may not get the same error again!!
At first, I used an anaconda environment with Python 3.5 and PIP version 19 but had the same problem. so instead of PIP, I used Conda package manager:
conda install TensorFlow
it worked well after using Conda instead of PIP
If you have a GPU in your system and it is conflicting with the current set of libraries or throwing a cudnn error then you can add the following line in your code to disable the GPU
os.environ["CUDA_VISIBLE_DEVICES"] = "-1"
put this in your code and it should be fine.
pip install tensorflow-gpu
Install this package this helps me to solve my issues
or else use python 3.9.7
Related
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.
Everything was working smoothly until I started getting the following error:
Traceback (most recent call last):
File "", line 1, in
File "/home/user/Workspace/Practices/Tensorflow/tensorflow2/venv/lib/python3.7/site-packages/tensorflow/init.py", line 98, in
from tensorflow_core import *
File "/home/user/Workspace/Practices/Tensorflow/tensorflow2/venv/lib/python3.7/site-packages/tensorflow_core/init.py", line 40, in
from tensorflow.python.tools import module_util as _modle_util
ModuleNotFoundError: No module named 'tensorflow.python.tools'; 'tensorflow.python' is not a package
My environment setup:
python-3.7
Using venv module to create virtual environment
tensorflow 2.0.0
pip 19.0.3
Manjaro Linux
Now, I even can't import tensorflow module as well. It gives same above error. Tried reinstalling with cache and without cache as well, but no luck. Recreated virtual environment as well, no luck. This is really weird and have no clue where to start troubleshooting as well. Looking at virtual environment site packages, everything seems fine.
I just faced this problem right now. I ran the source code on another computer and it showed the same error. I went ahead and compared the version of TensorFlow and turns out that the other computer was running tensorflow==2.1.0 and mine was running tensorflow==1.14.0.
In short, downgrade your tensorflow installation (pip install tensorflow==1.14.0)
Found a noob problem. I was using my file name as csv.py which already exist in python library, which I think was messing up the paths. But don't know how yet.
Try uninstalling and reinstalling. First run:
pip uninstall tensorflow
then reinstall:
pip install tensorflow==2.0
After you uninstall, in the python shell, run:
help('modules')
TensorFlow should not be there in that list. Only then proceed to install it.
You don't need to uninstall tensorflow what version you have because it will take time to reinstall. You can fix this issue just by installing tensorflow==2.0.
pip install tensorflow==2.0
I am currently using Python 3.5.5 on Anaconda and I am unable to import torch. It is giving me the following error in Spyder:
Python 3.5.5 |Anaconda, Inc.| (default, Mar 12 2018, 17:44:09) [MSC v.1900
64 bit (AMD64)]
Type "copyright", "credits" or "license" for more information.
IPython 6.2.1 -- An enhanced Interactive Python.
import torch
Traceback (most recent call last):
File "<ipython-input-1-eb42ca6e4af3>", line 1, in <module>
import torch
File "C:\Users\trish\Anaconda3\envs\virtual_platform\lib\site-
packages\torch\__init__.py", line 76, in <module>
from torch._C import *
ImportError: DLL load failed: The specified module could not be found.
Many suggestions on the internet say that the working directory should not be the same directory that the torch package is in, however I've manually set my working directory to C:/Users/trish/Downloads, and I am getting the same error.
Also I've already tried the following: reinstalling Anaconda and all packages from scratch, and I've ensured there is no duplicate "torch" folder in my directory.
Pls help! Thank you!
I had this similar problem in windows 10...
Solution:
Download win-64/intel-openmp-2018.0.0-8.tar.bz2 from https://anaconda.org/anaconda/intel-openmp/files
Extract it and put the dll files in Library\bin into C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\bin
Make sure your cuda directory is added to your %PATH% environment variable
I had the same problem. In my case I didn't want the GPU version of pytorch.
I uninstalled it. The version was pytorch: 0.3.1-py36_cuda80_cudnn6he774522_2 peterjc123.
The problem is that cuda and cudnn . then installed with the following command and now it works!
conda install -c peterjc123 pytorch-cpu
I also encountered the same problem when I used a conda environment with python 3.6.8 and pytorch installed by conda from channel -c pytorch.
Here is what worked for me:
1:) conda create -n envName python=3.6 anaconda
2:) conda update -n envName conda
3:) conda activate envName
4:) conda install pytorch torchvision cudatoolkit=9.0 -c pytorch
and then tested torch with the given code:
5:) python -c "import torch; print(torch.cuda.get_device_name(0))"
Note: 5th step will return your gpu name if you have a cuda compatible gpu
Summary: I just created a conda environment containing whole anaconda and then to tackle the issue of unmatched conda version I updated conda of new environment from the base environment and then installed pytorch in that environment and tested pytorch.
For CPU version, here is the link for my another answer: https://gist.github.com/peterjc123/6b804651288e76db7b5fabe5348e1f03#gistcomment-2842825
https://gist.github.com/peterjc123/6b804651288e76db7b5fabe5348e1f03#gistcomment-2842837
Had the same problem and fixed it by re-installing numpy with mkl (Intel's math kernel library)
https://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy
Download the right .whl for your machine. For me it was numpy‑1.14.5+mkl‑cp36‑cp36m‑win_amd64.whl (python 3.6, windows, 64-bit)
and then install using pip.
pip install numpy‑1.14.5+mkl‑cp36‑cp36m‑win_amd64.whl
I am using a Windows 10 computer with an NVIDIA GeForce graphics card. NVIDIA showed I had CUDA 10.1, but I was getting this error when running import torch in Jupyter Lab and suspected it had something to do with CUDA support.
I fixed this problem by downloading and installing the CUDA Toolkit directly from NVIDIA. It installed all required Visual Studio components. When I returned to Jupyter Lab, import torch ran without error.
Make sure you installed the right version of pytorch for your enviroment. I had the same problem I was using pytorch on windows but I had the default package installed which was meant for cuda 8. So I reinstalled the pytorch package for cpu which was what I needed.
I had the same issue with running torch installed with pure pip and solved it by switching to conda.
Following steps:
uninstall python 3.6 from python.org (if exists)
install miniconda
install torch in conda ("conda install pytorch -c pytorch")
Issue with pip installation:
import torch
File "C:\Program Files\Python35\lib\site-packages\torch\__init__.py", line 78, in <module>
from torch._C import *
ImportError: DLL load failed: The specified module could not be found.
After switching to conda it works fine. I believe the issue was resolved by conda through installing the vs_redist 2017
vs2017_runtime 15.4.27004.2010 peterjc123
But I have tried it w/o conda and it did not help. Could not find how to check (and tweak) Python's vs_redist.
Windows10 Solution(This worked for my system):
I was having the same issue in my system. Previously I was using Python 3.5 and I created a virtual environment named pytorch_test using the virtualenv module because I didn't want to mess up my tensorflow installation(which took me a lot of time). I followed every instruction but it didn't seem to work. I installed python 3.6.7 added it to the path. Then I created the virtual environment using:
virtualenv --python=3.6 pytorch_test
Then go to the destination folder
cd D:\pytorch_test
and activate the virtual environment entering the command in cmd:
.\Scripts\activate
After you do this the command prompt will show:
(pytorch_test) D:\pytorch_test>
Update pip if you have not done it before using:
(pytorch_test) D:\pytorch_test>python -m pip install --upgrade pip
Then go for installing numpy+mkl from the site:
https://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy
Choose the correct version from the list if you have python 3.6.7 go with the wheel file:
numpy‑1.15.4+mkl‑cp36‑cp36m‑win_amd64.whl (For 64 bit)
(Note if the whole thing doesnot work just go with simple numpy installation and mkl installation separately)
Then go for installing openmp using:
(pytorch_test) D:\pytorch_test>pip install intel-openmp
Now you are done with the prerequisites. To install pytorch go to the previous versions site:
https://pytorch.org/get-started/previous-versions/
Here select the suitable version from the list of Windows Binaries. For example I am having CUDA 9.0 installed in my system with python 3.6.7 so I went with the gpu version:
cu90/torch-1.0.0-cp36-cp36m-win_amd64.whl
(There are two available versions 0.4.0 and 1.0.0 for pytorch, I went with 1.0.0)
After downloading the file install it using pip(assuming the whl file is in D:).You have to do this from the virtual environment pytorch_test itself:
(pytorch_test) D:\pytorch_test>pip install D:\torch-1.0.0-cp36-cp36m-win_amd64.whl
Prerequisites like six, pillow will be installed automatically.
Then once everything is done, install the models using torchvision.
Simply type :
(pytorch_test) D:\pytorch_test>pip install torchvision
To check everything is working fine try the following script:
import torch
test = torch.rand(4, 7)
print(test)
If everything was good then it wont be an issue. Whenever there is an issue like this it is related to version mismatch of one or more dependencies. This also occurred during tensorflow installation.
Deactivate the following virtual environment using the command deactivate in the cmd:
(pytorch_test) D:\pytorch_test>deactivate
This is the output of pip list in my system:
Package Version
------------ -----------
intel-openmp 2019.0
mkl 2019.0
numpy 1.16.2
Pillow 6.0.0
pip 19.0.3
setuptools 41.0.0
six 1.12.0
torch 1.0.0
torchvision 0.2.2.post3
wheel 0.33.1
Hope this helps. This is my first answer in this community, hope you all find it helpful. I setup pytorch today in the afternoon after trying all sorts of combinations. The same import problem occurred to me while installing CNTK and tensorflow. Anyway I kept them separate in different virtual environments so that I can use them anytime.
I'm using OS X El Capitan (10.11.4).
I just downloaded TensorFlow using the pip install instructions here.
Everything went pretty smoothly, though I did get a few warning messages like:
The directory '/Users/myusername/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want the -H flag.
and
You are using pip version 6.0.8, however version 8.1.2 is available. Even though I just installed pip.
Then, when I tested TensorFlow in Python, I got the error:
>>> import tensorflow as tf
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/tensorflow/__init__.py", line 23, in <module>
from tensorflow.python import *
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/tensorflow/python/__init__.py", line 48, in <module>
from tensorflow.python import pywrap_tensorflow
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/tensorflow/python/pywrap_tensorflow.py", line 28, in <module>
_pywrap_tensorflow = swig_import_helper()
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/tensorflow/python/pywrap_tensorflow.py", line 24, in swig_import_helper
_mod = imp.load_module('_pywrap_tensorflow', fp, pathname, description)
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/imp.py", line 243, in load_module
return load_dynamic(name, filename, file)
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/tensorflow/python/_pywrap_tensorflow.so, 10): Library not loaded: #rpath/libcudart.7.5.dylib
Referenced from: /Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/tensorflow/python/_pywrap_tensorflow.so
Reason: image not found
Now, when I try to do pip uninstall tensorflow-0.10.0rc0 it tells me that it's not installed.
The closest thing I've found to resembling this problem is this issue in the TensorFlow GitHub docs (which I have not tried).
How can I uninstall whatever it did install and get TensorFlow up and running correctly?
This error message is displayed if you install the GPU-enabled Mac OS version of TensorFlow (available from release 0.10 onwards) on a machine that does not have CUDA installed.
To fix the error, install the CPU version for Python 2.7 or 3.x, as follows:
# Mac OS X, CPU only, Python 2.7:
$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-0.12.0-py2-none-any.whl
$ sudo pip install --upgrade $TF_BINARY_URL
# Mac OS X, CPU only, Python 3.4 or 3.5:
$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-0.12.0-py3-none-any.whl
$ sudo pip3 install --upgrade $TF_BINARY_URL
See tensorflow versions: https://www.tensorflow.org/versions/
To add to #mrry's answer, if you already have CUDA installed but you still get the error, it could be because the CUDA libraries are not on your path. Add the following to your ~/.bashrc or ~/.zshrc:
# export CUDA_HOME=/Developer/NVIDIA/CUDA-7.5 ## This is the default location on macOS
export CUDA_HOME=/usr/local/cuda
export DYLD_LIBRARY_PATH="$CUDA_HOME/lib:$DYLD_LIBRARY_PATH"
export PATH="$CUDA_HOME/bin:$PATH"
Uncomment either of the CUDA_HOMEs or edit it so that it contains your CUDA install. If you do not know where it is installed, try:
find / -name "*libcudart*"
Certainly installing CUDA is essential, as is ensuring that all the paths are correct. I'm running:
TensorFlow 0.12r0
OSX 10.12.1
python 2.7 from brew
virtualenv to separate my python environments
CUDA 8.0.55
cudnn-8.0-osx-x64-v5.1
On my system I have also had further issues where it appears that the problem originates from the dynamic libraries internally referencing relative paths.
To discover the #rpath being referenced from _pywrap_tensorflow.so the following code is run:
otool -l /Users/norman_h/.virtualenvs/env_name/lib/python2.7/site-packages/tensorflow/python/_pywrap_tensorflow.so
which returned, amongst other things, the following:
Load command 15
cmd LC_RPATH
cmdsize 128
path $ORIGIN/../../_solib_darwin/_U#local_Uconfig_Ucuda_S_Scuda_Ccudart___Uexternal_Slocal_Uconfig_Ucuda_Scuda_Slib (offset 12)
Load command 16
cmd LC_RPATH
cmdsize 48
path ../local_config_cuda/cuda/lib (offset 12)
Load command 17
cmd LC_RPATH
cmdsize 56
path ../local_config_cuda/cuda/extras/CUPTI/lib (offset 12)
It can be seen that the dynamic library is attempting to find the CUDA libraries within my virtual environment where I installed TensorFlow with pip. It's not looking within my systems environment paths.
A hack around of a solution is to dynamically link the CUDA libraries from their /usr/local/cuda/lib location into the site-packages where pip installed TensorFlow inside my virtual environment.
mkdir /Users/norman_h/.virtualenvs/env_name/lib/python2.7/site-packages/tensorflow/local_config_cuda
cd /Users/norman_h/.virtualenvs/env_name/lib/python2.7/site-packages/tensorflow/local_config_cuda
ln -s /usr/local/cuda .
Will need to re-link when pip upgrades TensorFlow from within the virtual environment.
I think this all goes back to the original compilation of TensorFlow that is done for the pip install and I have no idea how to submit a fix, or even if I am correct. Perhaps the original compilation of Tensorflow needs to be more dynamic and not static.
Best of luck!
This issue popped up on my macOS when i tried to import pyTorch. I found the solution in a japanese site which can't make heads and tails out of which simply gave the solution as brew install libomp . Cheers! Sorry for posting to an old thread, but I thought it necessary.