Try   HackMD

Python, conda and jupyter create virtual environment

tags: Python

Why use it:

If the Python environment become too big or too messy, we will always suggest you to use “Virtual environment” instead, which you would benefit with it by:

  1. You can save your environment in different location, even copy and move your environment to other machine for use
  2. You can always create different virtual environment for different project, to make sure that project will be run smoothly in a clear environment without facing weird issues, might be some module installed by previous working project is not compatible with current project.

How to install it:

To do so, you may just simply install it by the command:
python -m pip install --user virtualenv

Do see the quick manual, you can view it by:
python -m virtualenv –help


How to use it:

Now you can create a new virtual environment, for example, create one called venv under /mnt/huge_store by:
python -m virtualenv /mnt/huge_store/venv

The virual envrioment will be seen as folder only, you can always copy it to any where else, and remove it by simply delete the folder.

It will create one under the folder “/mnt/huge_store/venv”, where your virual environment installed. Then once you want to work on the virtual environment, simply type:
source /mnt/huge_store/venv/bin/active

Then you will see your bash shell changed as (venv)(bash) username@hostname to notice you where you are now working on. You can alias this command, or study with virualenvwrapper if you really want to work it as a shorten command for your future convenient.

For Virualenv Doc: https://virtualenv.pypa.io/
For Virualenvwrapper Doc: https://virtualenvwrapper.readthedocs.io/


This will also work for conda and jupyter with the same method or concept.
Here is the simple guides to do so.

For conda v-env Doc: https://conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html

For Jupyter v-env Doc: https://queirozf.com/entries/jupyter-kernels-how-to-add-change-remove