簡體   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