Quick Python Console
Once or twice a day, I need to run python console. I end up importing some modules and set some ipython magic. I have setup few configurations for this purpose. This applies to Linux machines.
Create Virtual Environment
python -m venv ~/venvs/local-console
Install modules
~/venvs/local-console/bin/python -m pip install pandas seaborn
Setup Python startup script
Create .pythonrc in ~/venvs/local-console/bin/
touch ~/venvs/local-console/bin/.pythonrc
Fill with file with your initialization requirements
get_ipython().magic("%matplotlib auto")
import pandas
import seaborn
#...Setup Batch File for Python Initialization
Get Aydin Sener’s stories in your inbox
Join Medium for free to get updates from this writer.
Create py.sh ~/venvs/local-console/bin/
touch ~/venvs/local-console/bin/py.sh
Fill with startup conditions
PYTHONSTARTUP=~/venvs/local-console/bin/.pythonrc ~/envs/local-console/bin/python3.9 -m IPythonPYTHONSTARTUP environment variable defines the startup script. -m option loads the given module (ipython)
Do not forget to make file executable:
chmod u+x py.sh
Create an Allias
Add the allias to your shell initialization script for Bash ~/.bashrc
alias py=~/venvs/local-console/bin/py.sh
Now you can just run py
Test




