繁体   English   中英

在Mac OS上使用pip3安装tensorflow

[英]installing tensorflow on mac os with pip3

所以我在Mac上运行tensorflow遇到了一些麻烦。 我检查了我当前的python版本并运行了安装程序。 从结果中,我可以清楚地看到它已经存在:

$ 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)

但是,当我运行python并尝试导入模块时,找不到它。 为什么会这样呢?

$ 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'

编辑:我尝试做wpercy建议,并得到一个错误

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

所以我尝试了

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

这个没有给我一个错误,但是我确实收到了这个警告:

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.

它安装成功,但是再次,当我尝试将其导入python时,模块无法识别。 这个警告与它有关吗?

好了,所以我终于开始工作了,它需要我在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

但是现在如果我想使用tensorflow,我需要激活此conda环境...可以...但是它仍然不能解决我的原始问题。 有谁知道我如何在conda环境之外使用tensorflow?

谢谢

当您使用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