Skip to content

Instantly share code, notes, and snippets.

@r0oland
Last active July 2, 2024 11:20
Show Gist options
  • Save r0oland/ab9508055b3d9d79208866b87c10fba9 to your computer and use it in GitHub Desktop.
Save r0oland/ab9508055b3d9d79208866b87c10fba9 to your computer and use it in GitHub Desktop.
Useful Python snippets
# create new empty env
conda create --name myenv
# export currently activated env to environment.yml without prefixes etc
conda env export --from-history | findstr -v "prefix" > environment.yml
# install environment based on such a environment.yml
conda env create -f environment.yml
# or even better, using Mamba
mamba env create -f environment.yml
# list existing environments
conda env list
# delete existing env
conda env remove -n ENV_NAME
# update an existing Conda environment with a .yml file
mamba env update --file environment.yml --prune
name: generic
channels:
- conda-forge
dependencies:
- numpy
- scipy
- pandas
- matplotlib
- seaborn
- jupyter
- regex
- autopep8
- openpyxl
- pyserial
- tqdm
- pip
# - pip:
# - git+https://github.com/blaze/dask.git#egg=dask[complete]

With a folder structure such as:

meta_project
    libs
        __init__.py
        module.py
    notebook_folder
        notebook.jpynb

If you want to import module.py from notebook.jpynb, you can use the following code:

import os
import sys
module_path = os.path.abspath(os.path.join('..'))
if module_path not in sys.path:
    sys.path.append(module_path)

from libs import module
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment