Install python3 and scientific calculation library on Ubuntu (virtualenv + pip)

Installing python3 on Ubuntu

The history you put in. The included libraries are numpy, scipy, matplotlib, seaborn, jupyter, etc. Mainly installed with pip on virtualenv. There seems to be another way to put it in with apt or anaconda. (That seems to be more stable.)

Postscript: 2016/09/26 Anaconda is easier to manage, and it seems that the packages that are created are de facto, such as those that support anaconda. Therefore, the method described below is not recommended.

#Put something in.
sudo apt-get -y update
sudo apt-get -y upgrade
sudo apt-get -y install build-essential
sudo apt-get -y install python3-dev
python -V
python3 -V

#Type python to get python3.(Postscript: It seems that you should not do it because it causes a bug)
#echo alias python=python3 >> ~/.bash_aliases
#source ~/.bash_aliases
#python -V


#Insert pip.
sudo apt-get install python3-setuptools
sudo easy_install3 pip
#Make sure the location of pip is python3.
pip -V
#What is currently in
pip list


#Put virtualenv
sudo pip install virtualenv


#Create a project directory
mkdir ./projectPath
cd ./projectPath


#Create an environment and start
virtualenv venv
source venv/bin/activate


#Add to gitignore
#echo venv >> .gitignore

#Verification
pip list


#I will try to put various things below using pip.
#Put numpy.
pip install numpy


#Insert scipy. There is a fortran compiler.
sudo apt-get install libatlas-base-dev gfortran
pip install scipy


#matplotlib,Insert seaborn. There is freetype.
sudo apt-get install libpng-dev
sudo apt-get install libfreetype6-dev
pip install matplotlib
pip install seaborn
#The following may not be necessary. When using qt4 and pyside with matplotlib.
sudo apt-get install qt-sdk
sudo apt-get install cmake
sudo pip install pyside
#Write to matplotlib config file
vim ~/.config/matplotlib/matplotlibrc
#backend     : qt4agg
#backend.qt4 : PySide


#Jupyter
pip install jupyter


#test library
pip install nose


#Other
pip install quandl
pip install scikit-learn



#Write it down
pip freeze > requirements.txt

#Exit the virtual environment.
deactivate

Let's write a sample code.

test.py


import numpy as np
import pandas as pd
import seaborn as sns

x = np.random.normal(size=100)
sns.distplot(x, kde=False, rug=False, bins=10)

seaborn spits an error when importing, but it works while spitting on ipython.

ipython It seems to be an enhanced version of the dialogue environment. The following is a bulleted list of what I noticed. You can read the explanation by adding? For magic commands. (Example: #run?)

Make the graph appear in a separate window when drawing the graph.

I had to specify something like qt in my environment. It seems that you can usually go with matplotlib inline.

%matplotlib qt4

Specify when starting ipython.

ipython --matplotlib qt4

loading file

%load filename.py

Load and execute file

%run filename.py

write to file

%%writefile filename.py
...

Overwrite file with what you wrote after the command

History display

%history -n
%history -n range 2-3

Write some line to file

%save -a filename.py 2

Above, the history number is specified and saved. You can also specify In [n], Out [n], etc. Addition instead of overwriting with the -a option.

Write out the value of a variable

%store foo >> a.txt

jupyter (formerly iPython Notebook)

It feels like a word for scientific calculations in a browser editor. ipython is the core. It is a notebook cut out from iPython, and can handle not only python but also ruby and haskell notebooks (.ipynb). It can also be a server.

How to edit a notebook.

jupyter notebook

Start with

You can create a new notebook by selecting python3 from new in the upper right.

Edit line by line. You can create a new line with the plus on the upper left. The line type is code, markdown, etc. You can choose from the upper right.

If you write the code, press ctrl + enter to execute it and the result will be displayed on the screen.

If you want to display the graph

%matplotlib inline

To execute.

Recommended Posts

Install python3 and scientific calculation library on Ubuntu (virtualenv + pip)
Install Python on Windows + pip + virtualenv
Install pyenv and Python 3.6.8 on Ubuntu 18.04 LTS
Install Python 3.3 on Ubuntu 12.04
Install pip / pip3 on Ubuntu
Install MongoDB on Ubuntu 16.04 and operate via python
Install ZIP version Python and pip on Windows 10
Install OpenCV on Ubuntu + python
Install Python 3.8 on Ubuntu 18.04 (OS standard)
Install Python 2.7.9 and Python 3.4.x with pip.
Install Mecab and mecab-python3 on Ubuntu 14.04
Install and run dropbox on Ubuntu 20.04
Install OpenCV and Chainer on Ubuntu
Install CUDA 8.0 and Chainer on Ubuntu 16.04
Install Python 3.8 on Ubuntu 20.04 (OS standard)
Install fabric on Ubuntu and try
Install Python 3.9 on Ubuntu 20.04 (OS standard?)
Install confluent-kafka for Python on Ubuntu
Install Python 2.7 on Ubuntu 20.04 (OS standard?)
Install easy_install and pip on windows
Build Python3 and OpenCV environment on Ubuntu 18.04
Python virtual environment and packages on Ubuntu
Install python library on Lambda using [/ tmp]
Steps to install Python environment on Ubuntu
scipy stumbles with pip install on python 2.7.8
Install Puppet Master and Client on Ubuntu 16.04
Install python on xserver to use pip
Install Python 3.8, Pip 3.8 on EC2 (Amazon Linux 2)
I can't install Dask with pip on Ubuntu
Install python package in personal environment on Ubuntu
Notes on installing Python3 and using pip on Windows7
[Procedure memo] Install Python3 + OpenSSL locally on Ubuntu
Install OpenCV 4.0 and Python 3.7 on Windows 10 with Anaconda
Install pip and pandas with Ubuntu or VScode
Run pip install on MacOS Python 3.7 or later
Install Python and libraries for Python on MacOS Catalina
Install TensorFlow on Ubuntu
Install python on WSL
Install pip on Mavericks
[Python] pip and wheel
Install Scrapy on python3
Install Python on Mac
Install Python 3 on Mac
Install PySide2 on Ubuntu
Install Python3.4 on CentOS 6.6
Install python external library
Install JModelica on Ubuntu
Install python on windows
Install Python 2.7.3 on CentOS 5.4
build Python on Ubuntu
Install Python 3.4 on Mac
Install Theano on Ubuntu 12.04
Install angr on Ubuntu 18.04
Install Python 3.6 on Docker
Initial settings for using Python3.8 and pip on CentOS8
Install Python3 on Mac and build environment [Definitive Edition]
Install psycopg2 (pgsql library for python3) on Apple Silicon
Install selenium on Mac and try it with python
Install Apache 2.4 on Ubuntu 19.10 Eoan Ermine and run CGI
Install the 3rd party python library on Cinema 4D
I got a UnicodeDecodeError when pip install on ubuntu