This is a working solution for me, first create a virtualenv from Pycharm and then install tensorflow there:
In Pycharm, Preferences -> Project interpreter -> Create VirtualEnv -> give the virtualenv a name and location of your choice, and select “inherit global site-packages” option -> OK.
In command line, install tensorflow in the virtualenv location you created in Step 1. For the above case, the location is ~/tensorflow_pycharm, therefore, run command virtualenv --system-site-packages ~/tensorflow_pycharm
In Pycharm, select the created project interpreter, and select the tensorflow package, double click to install the package.
If Step 3 is successful, set run configuration, and try run a sample program.
We recommend the virtualenv installation.Virtualenv is a virtual Python environment isolated from other Python development, incapable of interfering with or being affected by other Python programs on the same machine. During the virtualenv installation process, you will install not only TensorFlow but also all the packages that TensorFlow requires. (This is actually pretty easy.) To start working with TensorFlow, you simply need to “activate” the virtual environment. All in all, virtualenv provides a safe and reliable mechanism for installing and running TensorFlow.
Native pip installs TensorFlow directly on your system without going through any container or virtual environment system. Since a native pip installation is not walled-off, the pip installation might interfere with or be influenced by other Python-based installations on your system. Furthermore, you might need to disable System Integrity Protection (SIP) in order to install through native pip. However, if you understand SIP, pip, and your Python environment, a native pip installation is relatively easy to perform.
Docker completely isolates the TensorFlow installation from pre-existing packages on your machine. The Docker container contains TensorFlow and all its dependencies. Note that the Docker image can be quite large (hundreds of MBs). You might choose the Docker installation if you are incorporating TensorFlow into a larger application architecture that already uses Docker.
In Anaconda, you may use conda to create a virtual environment. However, within Anaconda, we recommend installing TensorFlow with the pip install command, not with the conda install command.
NOTE: The conda package is community supported, not officially supported. That is, the TensorFlow team neither tests nor maintains the conda package. Use that package at your own risk.
Installing with virtualenv
Take the following steps to install TensorFlow with Virtualenv:
Start a terminal (a shell). You’ll perform all subsequent steps in this shell.
Install pip and virtualenv by issuing the following commands:
where tfBinaryURL identifies the URL of the TensorFlow Python package. The appropriate value of tfBinaryURLdepends on the operating system and Python version. Find the appropriate value for tfBinaryURL for your systemhere. For example, if you are installing TensorFlow for macOS, Python 2.7, the command to install TensorFlow in the active Virtualenv is as follows:
Note that you must activate the virtualenv environment each time you use TensorFlow in a new shell. If the virtualenv environment is not currently active (that is, the prompt is not (tensorflow), invoke one of the following commands:
$ source ~/tensorflow/bin/activate # bash, sh, ksh, or zsh
$ source ~/tensorflow/bin/activate.csh # csh or tcsh
Your prompt will transform to the following to indicate that your tensorflow environment is active:
When the virtualenv environment is active, you may run TensorFlow programs from this shell.
When you are done using TensorFlow, you may deactivate the environment by issuing the following command:
The prompt will revert back to your default prompt (as defined by PS1).
If you want to uninstall TensorFlow, simply remove the tree you created. For example:
$ rm -r ~/tensorflow
Installing with native pip
We have uploaded the TensorFlow binaries to PyPI. Therefore, you can install TensorFlow through pip.
where tfBinaryURL identifies the URL of the TensorFlow Python package. The appropriate value of tfBinaryURLdepends on the operating system and Python version. Find the appropriate value for tfBinaryURLhere. For example, if you are installing TensorFlow for Mac OS and Python 2.7 issue the following command:
Launch a Docker container that contains one of the TensorFlow binary images.
The remainder of this section explains how to launch a Docker container.
To launch a Docker container that holds the TensorFlow binary image, enter a command of the following format:
$ docker run -it -p hostPort:containerPort TensorFlowImage
-p hostPort:containerPort is optional. If you’d like to run TensorFlow programs from the shell, omit this option. If you’d like to run TensorFlow programs from Jupyter notebook, set both hostPort and containerPort to 8888. If you’d like to run TensorBoard inside the container, add a second -p flag, setting both hostPort and containerPort to 6006.
TensorFlowImage is required. It identifies the Docker container. You must specify one of the following values:
We are relying on Stack Overflow to document TensorFlow installation problems and their remedies. The following table contains links to Stack Overflow answers for some common installation problems. If you encounter an error message or other installation problem not listed in the following table, search for it on Stack Overflow. If Stack Overflow doesn’t show the error message, ask a new question about it on Stack Overflow and specify the tensorflow tag.
ImportError: Traceback (most recent call last):
File ".../tensorflow/core/framework/graph_pb2.py", line 6, in
from google.protobuf import descriptor as _descriptor
ImportError: cannot import name 'descriptor'
An import tensorflow statement triggers an error such as the following:
Traceback (most recent call last):
File "", line 1, in
line 4, in
from tensorflow.python import *
line 22, in
TypeError: __init__() got an unexpected keyword argument 'syntax'
A pip install command triggers the following error:
You have not agreed to the Xcode license agreements, please run
'xcodebuild -license' (for user-level acceptance) or
'sudo xcodebuild -license' (for system-wide acceptance) from within a
Terminal window to review and agree to the Xcode license agreements.
File "numpy/core/setup.py", line 653, in get_mathlib_info
raise RuntimeError("Broken toolchain: cannot link a simple C program")
RuntimeError: Broken toolchain: cannot link a simple C program
The URL of the TensorFlow Python package
A few installation mechanisms require the URL of the TensorFlow Python package. The value you specify depends on three factors:
This section documents the relevant values for Mac OS installations.
You can skip this section unless you are seeing problems related to the protobuf pip package.
NOTE: If your TensorFlow programs are running slowly, you might have a problem related to the protobuf pip package.
The TensorFlow pip package depends on protobuf pip package version 3.1. The protobuf pip package downloaded from PyPI (when invoking pip install protobuf) is a Python-only library containing Python implementations of proto serialization/deserialization that can run 10x-50x slower than the C++ implementation. Protobuf also supports a binary extension for the Python package that contains fast C++ based proto parsing. This extension is not available in the standard Python-only pip package. We have created a custom binary pip package for protobuf that contains the binary extension. To install the custom binary protobuf pip package, invoke one of the following commands:
Installing this protobuf package will overwrite the existing protobuf package. Note that the binary pip package already has support for protobufs larger than 64MB, which should fix errors such as these: