Pip, Crontab
Pip, Crontab
command line
D ATA P R O C E S S I N G I N S H E L L
Susan Sun
Data Person
Python basics
Python
can be used with GUI interfaces (e.g Jupyter Notebook, Spyder, PyCharm, etc.)
man python
...
-V , --version
Prints the Python version number of the executable and exits.
python --version
Python 3.5.2
which python
/usr/bin/python
which python
/anaconda3/bin/python
python
>>> exit()
$
Alternative:
Create a .py le using a text editor on the command line (e.g. nano, Vim, Emacs)
Create a .py le by echo -ing the Python syntax into the hello_world.py le,
instantiating the Python le in the same step.
cat hello_world.py
print('hello world')
ls
hello_world.py
python hello_world.py
hello world
Susan Sun
Data Person
Python standard library
Python standard library has a collection of:
can be installed through pip , the standard package manager for Python, via the command line
pip -h
Usage:
pip <command> [options]
Commands:
install Install packages.
uninstall Uninstall packages.
freeze Output installed packages in requirements format.
list List installed packages.
pip --version
python --version
Python 3.5.2
WARNING: You are using pip version 19.1.1, however version 19.2.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
Collecting pip
|################################| 1.4MB 10.7MB/s
Successfully installed pip-19.2.1
pip list
Package Version
- - - - - - - - - - - -
agate 1.6.1
agate-dbf 0.2.1
agate-excel 0.2.3
agate-sql 0.5.4
Babel 2.7.0
Collecting scikit-learn
Downloading https://files.pythonhosted.org/packages/1f/af/e3c3cd6f61093830059138624dbd
|################################| 6.6MB 32.5MB/s
Collecting scipy>=0.17.0 (from scikit-learn)
Downloading https://files.pythonhosted.org/packages/14/49/8f13fa215e10a7ab0731cc95b0e9
|################################| 25.1MB 35.5MB/s
...
Collecting scikit-learn==0.19.2
Downloading https://files.pythonhosted.org/packages/b6/e2/a1e254a4a4598588d4fe88b45ab8
|################################| 4.9MB 15.6MB/s
Installing collected packages: scikit-learn
Successfully installed scikit-learn-0.19.2
Collecting scikit-learn
Downloading https://files.pythonhosted.org/packages/1f/af/e3c3cd6f61093830059138624dbd
|################################| 6.6MB 41.5MB/s
Requirement already satisfied, skipping upgrade: numpy>=1.11.0 in /usr/local/lib/python3
Collecting scipy>=0.17.0 (from scikit-learn)
Installing collected packages: scipy, joblib, scikit-learn
Successfully installed joblib-0.13.2 scikit-learn-0.21.3 scipy-1.3.0
cat requirements.txt
scikit-learn
statsmodel
Most Python developers include requirements.txt les in their Python Github repos.
In our example:
is the same as
Susan Sun
Data Person
What is a scheduler?
Scheduler runs jobs on a pre-determined schedule
cron scheduler is
simple
free
customizable
purely command-line
is a time-based job-scheduler
can be installed in Windows via Cygwin or replaced with Windows Task Scheduler
is used to automate jobs like system maintenance, bash scripts, Python jobs, etc.
crontab -l
Documentation:
man crontab
crontab -l
* * * * * python create_model.py
Interpretation:
Run every minute of every hour of every day of every month and of every day of the week.
Further resources:
Susan Sun
Data Person
Data downloading on the command line
How to download data les via curl and wget