-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathhelpers.py
More file actions
38 lines (34 loc) · 1.71 KB
/
Copy pathhelpers.py
File metadata and controls
38 lines (34 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import os, sys
def check_venv():
"""
Check if the script/notebook is running in the correct virtual environment.
Check for the existence of a local .venv directory, then check if this script is being run from within it.
"""
if not os.path.exists('.venv'):
print('No virtual environment found.')
print('Make sure to follow the instructions, including the `python -m venv .venv` command!')
print('You may need to restart Visual Studio Code after creating the virtual environment.')
print('On Mac or Linux, you may need to use `python3` instead of `python`, i.e. `python3 -m venv .venv`.')
return False
elif not sys.prefix.endswith('.venv'):
print('Please run this script from within the virtual environment.')
print('Check if, in the right top of the notebook, your .venv virtual environment is selected.')
print('If not, select it from the dropdown menu.')
print('You may need to restart Visual Studio Code after creating the virtual environment before you can select it.')
return False
else:
return True
def check_pillow():
"""
Check if Pillow is installed.
"""
try:
import PIL
return True
except ImportError:
print('Pillow is not installed.')
print('Make sure to follow the instructions, including the `pip install Pillow` command.')
print('You need to install Pillow in your virtual environment from the terminal.')
print('If you don\'t see a green (.venv) in your terminal, try manually activating the virtual environment first:')
print('Run `source .venv/bin/activate` on Mac or Linux, or `./.venv/Scripts/Activate.ps1` on Windows.')
return False