Showing posts with label numpy. Show all posts
Showing posts with label numpy. Show all posts

Sunday, June 11, 2017

Instaling TensorFlow on mac OSX Yosemite


I wanted to try out TensorFlow, so I started with the installation steps. First create virtualenv, and then try to do pip install, there are bunch of different ways you can install as per the instructions provided here, though I went with below and it at least for the first part installed it right.

pip install --ignore-installed --upgrade \ https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-1.1.0-py2-none-any.whl

Above is CPU-only installation with Anaconda. My mac default python runs under anaconda, so above worked well for me compared to other installation mechanism described in documentation.

After the installation I followed below step to try out test of tensorflow installation success -

$ python
>> import tensorflow as tf

Though I ran into error -
    _mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description) 
ImportError: numpy.core.multiarray failed to import

It was because of the numpy, it was pointing to the wrong one. I tried below to check the path of numpy -

$ python
>> import numpy
>> print numpy.__path__
['/usr/local/lib/python2.7/site-packages/numpy']

Which is an issue, as its using /local/lib/python2.7 installation and not local virtualenv installation -
Go to the path and remove the file explicitly. After that I tried again to review the path of numpy -

>> print numpy.__path__
['/Users/jpatel/Apps/tensorflow/venv/lib/python2.7/site-packages/numpy']

However, at this point I run into another error -

    from google.protobuf import descriptor as _descriptor
ImportError: No module named protobuf

Its because of issue with protobuf installation version, after looking at few of the online documentation help,  I updated to below -

$ pip uninstall protobuf
$ pip install protobuf==3.0.0a3

though error continues, 

    from google.protobuf import any_pb2 as google_dot_protobuf_dot_any__pb2
ImportError: cannot import name any_pb2


so figured another version from online help -

$ pip install --upgrade protobuf==3.0.0b2


After that it started working fine. -

>>> import tensorflow as tf
>>> hello = tf.constant("Hello, TensorFlow")
>>> sess = tf.Session()
2017-06-11 09:45:35.310965: W t
>>> print(sess.run(hello))
Hello, TensorFlow

>>> node1 = tf.constant(3.0, tf.float32)
>>> node2 = tf.constant(4.0)
>>> print(node1, node2)
(, )


If I do more experimentation around it, will share more examples and issues I run into and how to solve..

Monday, October 14, 2013

install ipython notebook on mac

First why you need IPython to getting started with -

- It provides interactive capability with rich architecture
- Browser based support
- Visualization
- Save your exercise capability
- High performance tool for parallel computing and statistics analysis on datasets.

How to install ipython notebook on mac -

There are various ways you can install it, and you can find so many resources online, though I try here listing down the steps which I followed.


You can follow below instruction to install it -

$ pip install readline ipython
$ sudo pip install pyzmq
$ sudo pip install jinja2
$ sudo pip install tornado

Once all those gets installed fine, run following command to check whether it installed fine or not. You can check on command prompt first by typing ipython. 

You should be able to see on command prompt if you just run ipython -

Python 2.7.1 (r271:86832, Jul 31 2011, 19:30:53)
Type "copyright", "credits" or "license" for more information.

IPython 1.1.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]:
.....

Once it comes up fine, start notebook

$ ipython notebook --pylab=inline

and it should open browser with -



You can click on New Notebook and try out few things to check its working fine, like 1+1, or 5*5 etc.





All Set!

Other clean recommended way to install is with proper virtualenv and requirement.txt file -


Create a seperate virtual env and run following requirement.txt

numpy==1.7.1
pandas==0.11.0
python-dateutil==2.1
pytz==2013b
pyzmq==2.1.11
six==1.3.0
wsgiref==0.1.2

And install pip install -r requirement.txt

Above instruction is for mac, which is comparatively easy compared to other environments. Feel free to post comments or issues you run into while installing.