简体   繁体   English

在Mac OS上使用pip3安装tensorflow

[英]installing tensorflow on mac os with pip3

So I'm having some trouble getting tensorflow working on my mac. 所以我在Mac上运行tensorflow遇到了一些麻烦。 I checked my current version of python and ran the install. 我检查了我当前的python版本并运行了安装程序。 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. 但是,当我运行python并尝试导入模块时,找不到它。 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 编辑:我尝试做wpercy建议,并得到一个错误

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. 它安装成功,但是再次,当我尝试将其导入python时,模块无法识别。 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环境中进行安装(根据tensorflow文档中的说明):

$ 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. 但是现在如果我想使用tensorflow,我需要激活此conda环境...可以...但是它仍然不能解决我的原始问题。 Does anyone know how I can go about using tensorflow outside of a conda environment? 有谁知道我如何在conda环境之外使用tensorflow?

Thanks 谢谢

The tensorflow docs suggest a special approach when you're using Anaconda. 当您使用Anaconda时, tensorflow文档建议一种特殊的方法。

# 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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