Skip to content

Commit d54e69e

Browse files
committed
feat: better windows support
1 parent c284ff0 commit d54e69e

File tree

2 files changed

+25
-10
lines changed

2 files changed

+25
-10
lines changed

DEEPNOTE_KERNEL_IMPLEMENTATION.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ This implementation adds automatic kernel selection and startup for `.deepnote`
4343
- Finds an available port (starting from 8888)
4444
- Starts the server with `python -m deepnote_toolkit server --jupyter-port <port>`
4545
- **Sets environment variables** so shell commands use the venv's Python:
46-
- Prepends venv's bin directory to `PATH`
47-
- Sets `VIRTUAL_ENV` to the venv path
48-
- Removes `PYTHONHOME` to avoid conflicts
46+
- Prepends venv's bin directory to `PATH` (POSIX: `<venv>/bin`, Windows: `<venv>\Scripts`)
47+
- Sets `VIRTUAL_ENV` to the venv path (both platforms)
48+
- Removes `PYTHONHOME` to avoid conflicts (both platforms)
4949
- Monitors server output and logs it
5050
- Waits for server to be ready before returning connection info
5151
- Reuses existing server for the same `.deepnote` file if already running
@@ -383,9 +383,9 @@ These changes ensure that Deepnote notebooks can execute cells reliably by:
383383

384384
2. **Environment variable configuration** (ensures shell commands use venv Python):
385385
- When starting the Jupyter server, set environment variables:
386-
- Prepend venv's `bin/` directory to `PATH`
387-
- Set `VIRTUAL_ENV` to point to the venv
388-
- Remove `PYTHONHOME` (can interfere with venv)
386+
- Prepend venv's bin directory to `PATH` (POSIX: `<venv>/bin`, Windows: `<venv>\Scripts`)
387+
- Set `VIRTUAL_ENV` to point to the venv (both platforms)
388+
- Remove `PYTHONHOME` (can interfere with venv, both platforms)
389389
- This ensures `!pip install` and other shell commands use the venv's Python
390390

391391
**Result**: Both the kernel and shell commands now use the same Python environment (the venv), so packages installed via `!pip install` or `%pip install` are immediately available for import.

src/kernels/deepnote/deepnoteServerStarter.node.ts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,17 +99,32 @@ export class DeepnoteServerStarter implements IDeepnoteServerStarter {
9999
const processService = await this.processServiceFactory.create(interpreter.uri);
100100

101101
// Set up environment to ensure the venv's Python is used for shell commands
102-
const venvBinDir = interpreter.uri.fsPath.replace(/\/python$/, '').replace(/\\python\.exe$/, '');
103102
const env = { ...process.env };
104103

104+
// Get the virtual environment directory from the Python interpreter path
105+
const interpreterPath = interpreter.uri.fsPath;
106+
let venvPath: string;
107+
let venvBinDir: string;
108+
109+
if (process.platform === 'win32') {
110+
// Windows: Python executable is typically in <venv>\Scripts\python.exe
111+
// Extract venv path by removing \Scripts\python.exe
112+
venvPath = interpreterPath.replace(/[\\/]Scripts[\\/]python\.exe$/i, '');
113+
venvBinDir = interpreterPath.replace(/[\\/]python\.exe$/i, '');
114+
} else {
115+
// POSIX: Python executable is typically in <venv>/bin/python
116+
// Extract venv path by removing /bin/python
117+
venvPath = interpreterPath.replace(/\/bin\/python$/, '');
118+
venvBinDir = interpreterPath.replace(/\/python$/, '');
119+
}
120+
105121
// Prepend venv bin directory to PATH so shell commands use venv's Python
106122
env.PATH = `${venvBinDir}${process.platform === 'win32' ? ';' : ':'}${env.PATH || ''}`;
107123

108-
// Also set VIRTUAL_ENV to indicate we're in a venv
109-
const venvPath = venvBinDir.replace(/\/bin$/, '').replace(/\\Scripts$/, '');
124+
// Set VIRTUAL_ENV to indicate we're in a venv (both platforms)
110125
env.VIRTUAL_ENV = venvPath;
111126

112-
// Remove PYTHONHOME if it exists (can interfere with venv)
127+
// Remove PYTHONHOME if it exists (can interfere with venv, both platforms)
113128
delete env.PYTHONHOME;
114129

115130
// Get the directory containing the notebook file to set as working directory

0 commit comments

Comments
 (0)