Skip to content

Commit 6b5f1ca

Browse files
Add ipykernel installation
1 parent 73f38ef commit 6b5f1ca

File tree

5 files changed

+221
-7
lines changed

5 files changed

+221
-7
lines changed

.devcontainer/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ All packages from `requirements.txt` are pre-installed:
4242
- `pyjwt` - JWT token handling
4343
- `pytest` & `pytest-cov` - Testing framework
4444
- `azure.storage.blob` & `azure.identity` - Azure SDK components
45+
- `jupyter`, `ipykernel`, `notebook` - Jupyter notebook support
4546

4647
### Environment Configuration
4748
- **PYTHONPATH** - Automatically configured to include shared Python modules
@@ -83,6 +84,17 @@ The container mounts your local `~/.azure` directory to preserve authentication
8384

8485
## 🐛 Troubleshooting
8586

87+
### Container Creation Failed with ipykernel Error
88+
If you see an error like `/usr/local/bin/python: No module named ipykernel`:
89+
1. This has been fixed in the latest version
90+
2. If you're still experiencing issues, manually rebuild the container:
91+
- Command Palette → "Dev Containers: Rebuild Container"
92+
3. Or run the manual setup:
93+
```bash
94+
pip install ipykernel jupyter notebook
95+
python -m ipykernel install --user --name=apim-samples --display-name="APIM Samples Python"
96+
```
97+
8698
### Python Path Issues
8799
If you encounter import errors:
88100
```bash
@@ -92,6 +104,7 @@ python setup/setup_python_path.py --generate-env
92104
### Jupyter Kernel Not Found
93105
Restart VS Code or refresh the Jupyter kernel list:
94106
- Command Palette → "Jupyter: Refresh Kernels"
107+
- Or manually check available kernels: `jupyter kernelspec list`
95108

96109
### Azure CLI Issues
97110
Check Azure CLI status:

.devcontainer/setup.ps1

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,19 @@ try {
4747
# ------------------------------
4848

4949
Write-Host "📓 Setting up Jupyter environment..." -ForegroundColor Yellow
50-
# Install Jupyter kernel
51-
python -m ipykernel install --user --name=apim-samples --display-name="APIM Samples Python"
50+
# Install Jupyter kernel (with error handling)
51+
try {
52+
python -c "import ipykernel" 2>$null
53+
if ($LASTEXITCODE -eq 0) {
54+
python -m ipykernel install --user --name=apim-samples --display-name="APIM Samples Python"
55+
} else {
56+
Write-Host "⚠️ Warning: ipykernel not found. Installing it now..." -ForegroundColor Yellow
57+
pip install ipykernel
58+
python -m ipykernel install --user --name=apim-samples --display-name="APIM Samples Python"
59+
}
60+
} catch {
61+
Write-Host "⚠️ Warning: Failed to install Jupyter kernel, but continuing..." -ForegroundColor Yellow
62+
}
5263

5364
# ------------------------------
5465
# WORKSPACE CONFIGURATION
@@ -95,9 +106,20 @@ $azVersion = az --version | Select-Object -First 1
95106
Write-Host $azVersion
96107

97108
Write-Host "Pip packages installed:" -ForegroundColor Cyan
98-
pip list | Select-String -Pattern "(requests|pandas|matplotlib|pytest|azure|jwt)"
109+
pip list | Select-String -Pattern "(requests|pandas|matplotlib|pytest|azure|jwt|jupyter|ipykernel)"
110+
111+
Write-Host "Jupyter kernels available:" -ForegroundColor Cyan
112+
try {
113+
jupyter kernelspec list 2>$null
114+
} catch {
115+
Write-Host "⚠️ Jupyter kernels could not be listed" -ForegroundColor Yellow
116+
}
99117

100118
Write-Host "🎉 Development environment setup complete!" -ForegroundColor Green
119+
120+
Write-Host "🔍 Running final verification..." -ForegroundColor Yellow
121+
python .devcontainer/verify-setup.py
122+
101123
Write-Host ""
102124
Write-Host "📋 Next steps:" -ForegroundColor Yellow
103125
Write-Host "1. Sign in to Azure: az login"

.devcontainer/setup.sh

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,14 @@ az extension add --name front-door --only-show-errors 2>/dev/null || true
4040
# ------------------------------
4141

4242
echo "📓 Setting up Jupyter environment..."
43-
# Install Jupyter kernel
44-
python -m ipykernel install --user --name=apim-samples --display-name="APIM Samples Python"
43+
# Install Jupyter kernel (with error handling)
44+
if python -c "import ipykernel" 2>/dev/null; then
45+
python -m ipykernel install --user --name=apim-samples --display-name="APIM Samples Python" || echo "⚠️ Warning: Failed to install Jupyter kernel, but continuing..."
46+
else
47+
echo "⚠️ Warning: ipykernel not found. Installing it now..."
48+
pip install ipykernel
49+
python -m ipykernel install --user --name=apim-samples --display-name="APIM Samples Python" || echo "⚠️ Warning: Failed to install Jupyter kernel, but continuing..."
50+
fi
4551

4652
# ------------------------------
4753
# WORKSPACE CONFIGURATION
@@ -83,9 +89,16 @@ echo "Azure CLI version:"
8389
az --version | head -1
8490

8591
echo "Pip packages installed:"
86-
pip list | grep -E "(requests|pandas|matplotlib|pytest|azure|jwt)"
92+
pip list | grep -E "(requests|pandas|matplotlib|pytest|azure|jwt|jupyter|ipykernel)"
93+
94+
echo "Jupyter kernels available:"
95+
jupyter kernelspec list 2>/dev/null || echo "⚠️ Jupyter kernels could not be listed"
8796

8897
echo "🎉 Development environment setup complete!"
98+
99+
echo "🔍 Running final verification..."
100+
python .devcontainer/verify-setup.py
101+
89102
echo ""
90103
echo "📋 Next steps:"
91104
echo "1. Sign in to Azure: az login"

.devcontainer/verify-setup.py

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
#!/usr/bin/env python3
2+
"""
3+
Verification script for the APIM Samples dev container setup.
4+
Run this script to verify that all dependencies are properly installed.
5+
"""
6+
7+
import sys
8+
import subprocess
9+
import importlib.util
10+
11+
# ------------------------------
12+
# CONSTANTS
13+
# ------------------------------
14+
15+
REQUIRED_PACKAGES = [
16+
'requests',
17+
'pandas',
18+
'matplotlib',
19+
'jwt',
20+
'pytest',
21+
'azure.storage.blob',
22+
'azure.identity',
23+
'jupyter',
24+
'ipykernel'
25+
]
26+
27+
REQUIRED_COMMANDS = [
28+
'az',
29+
'python',
30+
'pip',
31+
'jupyter'
32+
]
33+
34+
# ------------------------------
35+
# VERIFICATION FUNCTIONS
36+
# ------------------------------
37+
38+
def check_python_packages():
39+
"""Check if all required Python packages are installed."""
40+
print("🐍 Checking Python packages...")
41+
missing_packages = []
42+
43+
for package in REQUIRED_PACKAGES:
44+
if importlib.util.find_spec(package) is None:
45+
missing_packages.append(package)
46+
else:
47+
print(f" ✅ {package}")
48+
49+
if missing_packages:
50+
print(f" ❌ Missing packages: {', '.join(missing_packages)}")
51+
return False
52+
53+
return True
54+
55+
56+
def check_commands():
57+
"""Check if required command-line tools are available."""
58+
print("\n🔧 Checking command-line tools...")
59+
missing_commands = []
60+
61+
for command in REQUIRED_COMMANDS:
62+
try:
63+
subprocess.run([command, '--version'],
64+
capture_output=True,
65+
check=True,
66+
timeout=10)
67+
print(f" ✅ {command}")
68+
except (subprocess.CalledProcessError, FileNotFoundError, subprocess.TimeoutExpired):
69+
missing_commands.append(command)
70+
print(f" ❌ {command}")
71+
72+
if missing_commands:
73+
print(f" ❌ Missing commands: {', '.join(missing_commands)}")
74+
return False
75+
76+
return True
77+
78+
79+
def check_jupyter_kernel():
80+
"""Check if the custom Jupyter kernel is installed."""
81+
print("\n📓 Checking Jupyter kernel...")
82+
try:
83+
result = subprocess.run(['jupyter', 'kernelspec', 'list'],
84+
capture_output=True,
85+
text=True,
86+
check=True,
87+
timeout=10)
88+
89+
if 'apim-samples' in result.stdout:
90+
print(" ✅ APIM Samples kernel found")
91+
return True
92+
else:
93+
print(" ❌ APIM Samples kernel not found")
94+
return False
95+
96+
except (subprocess.CalledProcessError, subprocess.TimeoutExpired):
97+
print(" ❌ Failed to check Jupyter kernels")
98+
return False
99+
100+
101+
def check_azure_cli():
102+
"""Check Azure CLI installation and extensions."""
103+
print("\n☁️ Checking Azure CLI...")
104+
try:
105+
# Check Azure CLI
106+
result = subprocess.run(['az', '--version'],
107+
capture_output=True,
108+
text=True,
109+
check=True,
110+
timeout=10)
111+
112+
print(" ✅ Azure CLI installed")
113+
114+
# Check for useful extensions
115+
extensions = ['containerapp', 'front-door']
116+
for ext in extensions:
117+
if ext in result.stdout:
118+
print(f" ✅ Extension {ext} installed")
119+
else:
120+
print(f" ⚠️ Extension {ext} not found (optional)")
121+
122+
return True
123+
124+
except (subprocess.CalledProcessError, subprocess.TimeoutExpired):
125+
print(" ❌ Azure CLI not working properly")
126+
return False
127+
128+
129+
def main():
130+
"""Main verification function."""
131+
print("🔍 Verifying APIM Samples dev container setup...\n")
132+
133+
checks = [
134+
check_python_packages(),
135+
check_commands(),
136+
check_jupyter_kernel(),
137+
check_azure_cli()
138+
]
139+
140+
print("\n" + "="*50)
141+
142+
if all(checks):
143+
print("🎉 All checks passed! Your dev container is ready to use.")
144+
print("\n📋 Next steps:")
145+
print("1. Sign in to Azure: az login")
146+
print("2. Execute shared/jupyter/verify-az-account.ipynb")
147+
print("3. Explore the samples and infrastructure folders")
148+
return 0
149+
else:
150+
print("❌ Some checks failed. Please review the output above.")
151+
print("\n🔧 Try these troubleshooting steps:")
152+
print("1. Rebuild the container: Dev Containers: Rebuild Container")
153+
print("2. Manually run: pip install -r requirements.txt")
154+
print("3. Check the .devcontainer/README.md for more help")
155+
return 1
156+
157+
158+
# ------------------------------
159+
# MAIN EXECUTION
160+
# ------------------------------
161+
162+
if __name__ == "__main__":
163+
sys.exit(main())

requirements.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,7 @@ pyjwt
88
pytest
99
pytest-cov
1010
azure.storage.blob
11-
azure.identity
11+
azure.identity
12+
jupyter
13+
ipykernel
14+
notebook

0 commit comments

Comments
 (0)