Download and install Python
- If you don’t have Python on your system, download and install version 3.11 or later now. Note: in Windows, be sure to check the “Add python.exe to PATH” box in the installer. Otherwise, you’ll need to type the complete path to
python.exe
when creating the virtual environment.
- Create a Python virtual environment in your project folder using the commands below based on your particular machine:
MacOS
- In a Terminal window, navigate to the directory where you want to store your environment (this is typically the project folder where your files and code are) type following commands (i.e. the text after the
$
):
$ python3 -m venv deep_venv
$ source deep_venv/bin/activate
(deep_venv) $ python -m pip install -U pip
(deep_venv) $ pip install tensorflow scikit-learn jupyterlab seaborn ipywidgets ipympl
Linux/Unix:
- In a Terminal window, navigate to the directory where you want to store your environment (this is typically the project folder where your files and code are) type following commands (i.e. the text after the
$
):
$ python -m venv deep_venv
$ source deep_venv/bin/activate
(deep_venv) $ python -m pip install -U pip
(deep_venv) $ pip install tensorflow scikit-learn jupyterlab seaborn ipywidgets ipympl
On Windows
- In a PowerShell terminal, navigate to the directory where you want to store your environment (this is typically the project folder where your files and code are) type the following commands (i.e. the text after the
>
):
C:\Users\you\Enthought_DEEP> python -m venv deep_venv
C:\Users\you\Enthought_DEEP> .\deep_venv\Scripts\Activate.ps1
(deep_venv)C:\Users\you\Enthought_DEEP> python -m pip install -U pip
(deep_venv)C:\Users\you\Enthought_DEEP> pip install tensorflow scikit-learn jupyterlab seaborn ipywidgets ipympl
Test Your Installation
- Launch Jupyter lab from a command line
- Open a new Python 3 Notebook (use the blue button with a white +)
- Paste the following code into a cell and run it with Shift-Enter:
import tensorflow as tf
print(f'TensorFlow version: {tf.__version__}')
gpus = tf.config.list_physical_devices('GPU')
gpus = gpus[0] if gpus else None
print(f'List GPUS: {gpus}')
print('-' * 100)
print()
# Cache the dataset locally (relative to ~/.keras/datasets).
(x_train, y_train), (x_test, y_test) = tf.keras.datasets.mnist.load_data()
# Rescale from [0, 255] to [0, 1]
x_train, x_test = x_train / 255.0, x_test / 255.0
model = tf.keras.models.Sequential(
[
tf.keras.layers.Flatten(input_shape=(28, 28)),
tf.keras.layers.Dense(128, activation='relu'),
tf.keras.layers.Dense(10, activation='softmax'),
],
name='simple_model_1',
)
model.compile(
optimizer='adam',
loss='sparse_categorical_crossentropy',
metrics=['sparse_categorical_accuracy'],
)
model.fit(x_train, y_train, epochs=3, batch_size=32)
print('Done.')