Week 6 - Anaconda & VScode installation, uses and commands

Liaw Bei Le · April 28, 2021

Anaconda

Install Anaconda

We usually use Anaconda to create environments for isolating our projects that use different versions of Python and/or different version of packages.

We also use it to install, uninstall, and update packages in our project environments.

Installation

Create new environment

Anaconda Navigator > Environment > Create new environment


VSCode

Install VSCode

Visual Studio Code is a code editor and IDE, an environment for programming projects or working on text files.

Installation

Select environment
VSCode > “CTRL + Shift + P” to open the command palette. > find “Python: Select Interpreter” > Select your environment

or

VSCode > View > Command Palette > find “Python: Select Interpreter” > Select your environment

To create a new file, e.g. in projects folder in desktop
Click file icon on left (for Windows users without Linux)

To delete a file
Delete manually in computer folder (for Windows users without Linux)

  • You can’t be inside the folder/ file if you want to delete that particular file
    (enter ‘pwd’ to check which folder or file you are in)
    (consider entering ‘cd ..’ in terminal if you are in the folder/ file that you want to delete)

In the editor of VSCode:

Save code
Ctrl+S

Import & use function from insider one file to the other
E.g. if there’s 2 files, calculator.py and main.py, in main.py file’s editor,

  • can type one line of code, ‘import calculator’ OR
  • ‘from calculator import sum_all’ (custom function name in calculator.py)
    then can type e.g. number_sum = calculator.sum_all(num1,num2)

In the terminal of VSCode:

Run code in VSCode terminal:

  • Go to terminal and type: python .\file_name.py
  • Enter to run code

Stop the code from running in VSCode terminal:

  • Go to terminal and Ctrl+C

Terminal Commands

rm -> remove

  • e.g. rm .\filename.py

cp -> copy

  • e.g. cp .\file1name.py .\file2name.py

mv -> rename

  • e.g. mv .\oldfilename.py .\newfilename.py

ls -> list

  • e.g. ls .\foldername\

pwd -> print working directory (see what is the current folder or file you are in)
cd -> change directory

  • e.g. cd .\foldername\

cd .. -> go to the directory containing the file or folder you are currently in

  • e.g. your current directory is desktop\learnpython, then you use cd .. to go to desktop

mkdir -> make directory (create a new folder)

  • e.g. mkdir nameofnewdirectory (don’t need .\ in front)

cp-r -> copy all (recursively select all)

  • e.g. cp - r .\folderone\ .\foldertwo\
    (moves all files in folder one to folder two)

press up/down keys -> cycle past commands
press tab -> to get file name quickly via autofill

touch -> create a new file (for linux)
rm-rf -> (same as above, but for linux)

Twitter, Facebook