2

I'd like to set up a setup.py script to install tensorflow, but there isn't just a simple pip install method to install it.

The only way I've figured out is this extremely hacky way, is there a better, official way to do it?

from setuptools import setup
from setuptools.command.install import install

from subprocess import call
from sys import platform as _platform

#linux or ios
if _platform == "linux" or _platform == "linux2":
    tensorfow_url = "https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.8.0-cp27-none-linux_x86_64.whl"
elif _platform == "darwin":
    tensorfow_url = "https://storage.googleapis.com/tensorflow/mac/tensorflow-0.8.0-py2-none-any.whl"


class CustomInstallCommands(install):
    """Installs tensorflow the hacky way"""

    def run(self):
        call(['pip', 'install', '--upgrade', tensorfow_url])
        install.run(self)


setup(name='tensorflow_project',
      version='0.1',
      description='project with tensorflow',
      packages=['tensorflow_project'],
      install_requires=[
          'scipy',
          'numpy',
          'pandas',
          'scikit-learn',

      ],
      zip_safe=False,
      cmdclass={
          'install': CustomInstallCommands,
          'develop': CustomInstallCommands,
      })
Roman
  • 8,826
  • 10
  • 63
  • 103

2 Answers2

0

Since tensorflow 1.0, you can just

pip install tensorflow
Roman
  • 8,826
  • 10
  • 63
  • 103
0

There are two TF modes that you can install it in, one that runs only on CPU and the other that tries to utilise your GPU first.

The URL of the TensorFlow Python package will keep updating and can be found at Installing TensorFlow on Ubuntu

To install, follow this

#(Optional step: you may also want to consider installing it in a Virtual environment)
virtualenv  ~/tensorflow
source ~/tensorflow/bin/activate

Then set the URL corresponding to the TF package that best suits your system configuration and version needs

export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.0.0-cp27-none-linux_x86_64.whl 
#(this is the cpu version)

or

export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.0.0-cp27-none-linux_x86_64.whl 
#(this is the gpu version)

then

pip install --upgrade $TF_BINARY_URL

PS: If you had installed it in a Virtual environment, you need to activate it by the above mentioned "source" command to activate the environment

abhinonymous
  • 329
  • 2
  • 13