简体   繁体   中英

installing tensorflow on mac os with pip3

So I'm having some trouble getting tensorflow working on my mac. I checked my current version of python and ran the install. From the result I can clearly see it's already there:

$ python --version
Python 3.4.3 :: Anaconda 2.3.0 (x86_64)
$ pip3 install tensorflow
Requirement already satisfied: tensorflow in 

/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages
Requirement already satisfied: six>=1.10.0 in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (from tensorflow)
Requirement already satisfied: protobuf>=3.1.0 in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (from tensorflow)
Requirement already satisfied: numpy>=1.11.0 in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (from tensorflow)
Requirement already satisfied: wheel>=0.26 in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (from tensorflow)
Requirement already satisfied: setuptools in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (from protobuf>=3.1.0->tensorflow)
Requirement already satisfied: appdirs>=1.4.0 in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (from setuptools->protobuf>=3.1.0->tensorflow)
Requirement already satisfied: packaging>=16.8 in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (from setuptools->protobuf>=3.1.0->tensorflow)
Requirement already satisfied: pyparsing in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (from packaging>=16.8->setuptools->protobuf>=3.1.0->tensorflow)

But when I run python and try importing the module it can't be found. Why is this the case?

$ python
Python 3.4.3 |Anaconda 2.3.0 (x86_64)| (default, Mar  6 2015, 12:07:41) 
[GCC 4.2.1 (Apple Inc. build 5577)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named 'tensorflow'

Edit: I tried doing what wpercy suggested and got an error

PermissionError: [Errno 13] Permission denied: '/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/wheel/__init__.py'

So then I tried

sudo pip3 install --ignore-installed --upgrade $TF_BINARY_URL

This one didn't give me an error, but I did receive this warning:

The directory '/Users/daltyboy11/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 sudo's -H flag.
The directory '/Users/daltyboy11/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.

It installed successfully, but again, when I try importing it in python the module is not recognized. Does this warning have something to do with it?

Alright so I finally got it working, and it required me to do the installation in a conda environment (from the instructions in the tensorflow docs):

$ conda create -n tensorflow python=3.4
$ source activate tensorflow
(tensorflow)$  # Your prompt should change

# Linux/Mac OS X, Python 2.7/3.4/3.5, CPU only:
(tensorflow)$ conda install -c conda-forge tensorflow

but now if I want to use tensorflow I am required to activate this conda environment... This is OK... but it still did not resolve my original problem. Does anyone know how I can go about using tensorflow outside of a conda environment?

Thanks

The tensorflow docs suggest a special approach when you're using Anaconda.

# 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.1-py3-none-any.whl

# Mac OS X, GPU enabled, Python 3.4 or 3.5:
$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/mac/gpu/tensorflow_gpu-0.12.1-py3-none-any.whl

# Install with Python 3
$ pip3 install --ignore-installed --upgrade $TF_BINARY_URL

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM