<jupyter_start><jupyter_text>Re-runnable virtual environment setupThis notebook is a re-runnable set of instructions to set up a virtual environment and install a package `pygeode` into it.<jupyter_code># Define package name - to install
PACKAGE = 'pygeode'
# Import the required packages
import virtualenv
import pip
import os
import pydoc

# Define and create the base directory install virtual environments
venvs_dir = os.path.join(os.path.expanduser("~"), "nb-venvs")

# Create base venvs directory if not already there
if not os.path.isdir(venvs_dir):
    os.makedirs(venvs_dir)

# Define the venv directory
venv_dir = os.path.join(venvs_dir, 'venv-notebook')

if not os.path.isdir(venv_dir):
    # Create the virtual environment
    print(f'[INFO] Creating: virtual env at: {venv_dir}')
    virtualenv.create_environment(venv_dir)
    
# Activate the venv
activate_file = os.path.join(venv_dir, "bin", "activate_this.py")
exec(open(activate_file).read(), dict(__file__=activate_file))

# Try to import the package, if it fails, then try to pip install it,
# and import again
try:
    import pygeode
except Exception as exc:
    # pip install a package using the venv as a prefix
    print(f'[INFO] Pip installing "{PACKAGE}"')
    pip.main(["install", "--prefix", venv_dir, PACKAGE])
    import pygeode

print(f'[INFO] "{PACKAGE} has been imported.')
print(pygeode)

print(f'NOTE: You can now work with the package "{PACKAGE}" as usual...')<jupyter_output>[INFO] "pygeode has been imported.
<module 'pygeode' from '/home/users/astephen/nb-venvs/venv-notebook/lib/python3.7/site-packages/pygeode/__init__.py'>
NOTE: You can now work with the package "pygeode" as usual...
{'fraction_non_alphanumeric': 0.110381861575179, 'fraction_numerical': 0.0011933174224343676, 'mean_word_length': 4.843205574912892, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '391715', 'license': 'BSD-2-Clause', 'n_tokens_mistral': 560, 'n_tokens_neox': 549, 'n_words': 177, 'path': 'notebooks/pygeode-virtualenv.ipynb', 'repo_name': 'feggleton/ceda-notebooks', 'size': '1676'}