Go to terminal, check python version
$ python --version Python 2.7.3 $ python3 --version Python 3.2.3We want to use Python 3, so for the rest of this tutorial, make sure you're using
python3
and not just python
.Go into the Python 3 interpreter:
$ python3 Python 3.2.3 (default, Apr 12 2012, 21:55:50) [GCC 4.6.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>>
See if you have NumPy already installed:
>>> from numpy import * Traceback (most recent call last): File "<stdin>", line 1, in <module> ImportError: No module named numpyNope, it's not there, so we need to install. Exit the Python interpreter.
>>> exit()
Install NumPy using apt-get
Instead of browsing web forums and finding the right package to download and compile, just let Ubuntu's built-in package manager, apt-get, do the work. This is just like installing NumPy for the standard python installation, but because we need NumPy for the Python3 installation, we'll affix the '3' where needed:$ sudo apt-get install python3-numpy python3-scipyLet it have all the dependencies it wants (just type 'yes' when prompted).
See if it worked
To see if it worked, go back into the Python interpreter, import NumPy, create a NumPy array, and make sure it's a NumPy array:>>> from numpy import * >>> type(array([1,2,4,5])) <type 'numpy.ndarray'>
Yup it worked.
Conclusion
In Ubuntu 12.04, just use apt-get to install NumPy for python 3 using$ sudo apt-get install python3-numpy python3-scipyEverything just works.
Fantastic stuff, man. You presented it in a clear and easily to follow manner while maintaining professionalism.
ReplyDeleteCheers
Coming from Windows 7 and knowing almost nothing about programming, you saved me.
ReplyDeleteHow can you know that it is python3-numpy and python3-scipy and not any other stuff like, python3 scipy or just scipy or scipy3 or whatever?
Please answer me and keep up the good work.
Cheers.
Bit late to be of help, but for the record - there's a tool called apt-file that supports such searches...
ReplyDeletesudo apt-get install apt-file
apt-file --package-only find python3 | grep numpy
you give the clearest instruction!!! Thanks
ReplyDelete
ReplyDeleteThanks for sharing amazing information about python .Gain the knowledge and hands-on experience in python online training