How to get a clean Python environment on Zorin :)

Python is available regardless of the window display server (X11 or Wayland). A Python virtual environment does not come by default. It wouldn't make sense to, either: you create and destroy them as needed, and you have to enable them explicitly on each shell session anyway.

You don't have to use a virtual environment if you don't want to, it's just a way to get things organized.

  1. Install the python3-venv package:

    sudo apt install python3-venv
    
  2. Create a new virtual environment:

    python3 -m venv my_new_environment
    

    The name of the environment is entirely up to you. You'd often see online that people prefix it with a dot . to make it a hidden directory.

  3. Activate and deactivate it using:

    source path/to/my_new_environment/bin/activate
    

    Notice the prompt changes slightly to show the name of your environment. You can start running commands from there like installing anything that you need:

    (my_new_environment) zenzen@zenzen:~$ pip3 install numpy

    When you're done, you can run:

    deactivate
    
  4. A tip: create an alias for python3 and pip3 since it's quite annoying to have to type that all the time. In your ~/.bashrc add this at the bottom:

     alias python='python3'
     alias pip='pip3'
    

I haven't installed any of those libraries myself so I can't say what's the best way to do so. But you can just create a new environment and start over, since the dependencies will be kept independent from the rest of the system, and other environments anyway.

1 Like