Current OS: Windows 10.
How to get a programmer-friendly python environment which simplify your life as much as possible? I don’t know if this is the very final answer to such a question (also considering that not everybody has the same needs…) but I must admit I’ve had a very good time since I installed two simple tools: Anaconda and Jupyter Notebook.
About Anaconda and Python environments
Anaconda can be used as terminal to install every future missing module you need. There is an important thing to point out. If you want to install a set of module and you are not sure about what global effects they have on your python installation, you can install such python modules in so called environments which are independent of each other: if you create two environments and install a module in one of them, the other one will not be affected from it.
Here some basic commands you could need in the future, after installing Anaconda (see later steps):
- conda env list : shows a list of existing environments; your current environment should be market (with *)
- conda create --name myenv : creates a new environment, where “myenv” is the environment name
- conda activate myenv : activate the environment named “myenv”, which will be considered as the current one
- conda deactivate : deactivate the current environment; the base environment will be again considered as the current one
- conda create --name myclone --clone myenv : clone “myenv” as “myclone”
About Jupyter Notebook
Jupyter Notebook allows you to:
- program in python using your browser
- mix code, plain text (headings, body, …), plots (or more in general, code ouputs)
- piecewise execute python code blocks (called cells) in the same page in any arbitrary execution order
- export everything in other format (e.g. PDF)
- run IPython commands, example:
- %run ./jupy1.ipynb : executes code contained in “jupy1.ipynb”
- %load ./hello.py : after running this code, it will be replaced with the content of hello.py
- %store my_var1 : allows to pass variable “my_var1” to other jupyter notebooks by calling it with %store -r my_var1 (even if you delete it with del my_var1 ! Use %store -z my_var1 to permanently delete “my_var1” instead)
- %%time : prints the execution time of the cell containing it; put it at the beginning of the cell
- %%writefile code.py : write the cell content into a file (“code.py”); the opposite command is %pycat code.py showing you the content of “code.py”
- write in Latex (in “Markdown” cells)
- show the documentation of every object by pressing Shift + Tab
If you need a complete Python environment, follow these steps:
- Install the full version of Anaconda from the official website. Follow the instructions you will find during the installation, but please remember two main things in order to avoid time wasting problems in the near future:
- Choose C:\ as installation path.
- Tick the box “Add Anaconda to my PATH environment variable”
- After installing the latest Anaconda (having Python 3 version), you should automatically have Jupyter Notebook available. To run it, just go somewhere (in a folder you want to work in), open the terminal in that position by typing “cmd” in the Explorer address bar and enter jupyter notebook in the new terminal (or directly entering it in the Explorer address bar!). If everthing works, a new browser page should appear in a few seconds showing your current working directory. From here you can create (and load) as many Jupyter Notebooks (.ipynb) as you want and decide in which Python environment they should work (directly from the “New” drop down menu).
[UPDATE] Problem: I do not find Anaconda environments in the Jupyter Notebook drop down menu! What to do?
Enter this command in the Anaconda terminal to automatically add all Anaconda environments:
conda install nb_conda_kernels