Virtual Environment


Different projects require different setup of packages, especially in Python. One of the best practice is to do package requirement file by pip freeze | grep .

Virtual Environment is also useful. Simply, virtualenv -p /usr/bin/python3 envname. Then activate it by source envname/bin/activate. Finish coding, remember to deactivate.

To open the jupyter notebook in specific environment, please do,


ipython kernel install --user --name=envname
jupyter notebook
    

Anaconda


conda create -n my_env
conda activate my_env
conda env update -n my_env --file config.yaml
python -m ipykernel install --user --name=my_env
jupyter notebook
    

Troubleshootings

  1. RuntimeError: failed to query /usr/bin/python3.6 with code 1 err. This occurs in Ubuntu 20.04.
  2. 
    sudo add-apt-repository ppa:deadsnakes/ppa
    sudo apt-get update
    sudo apt-get install python3.6
    apt-get update
    apt-get install python3-virtualenv
    virtualenv -p /usr/bin/python3.6 venv 
          
  3. ModuleNotFoundError: No module named 'virtualenv.seed.embed.via_app_data' when using virtualenv.
  4. 
    python3 -m venv my_env
          

References


  1. Jupyter notebook in a virtual environment (virtualenv)
  2. conda Managing environments
  3. How to add your Conda environment to your jupyter notebook in just 4 steps
  4. How to install packages from yaml file in Conda
  5. Ubuntu – Problem with creating Python 3.6 virtual environment on Ubuntu 20.04
  6. ModuleNotFoundError: No module named 'virtualenv.seed.embed.via_app_data' when I created new env by virtualenv