Skip to content

Instantly share code, notes, and snippets.

@ruslanmv
Created February 17, 2024 19:10
Show Gist options
  • Save ruslanmv/f896a68780b8130903f67dd1dc55d978 to your computer and use it in GitHub Desktop.
Save ruslanmv/f896a68780b8130903f67dd1dc55d978 to your computer and use it in GitHub Desktop.
Run Python commands with custom python environment in background from Jupyter Notebook
# Create a shell script
script_content = f'''
#!/bin/bash
source activate automatic
"$@"
'''
# Write the script to a file
script_filename = 'run'
with open(script_filename, 'w') as script_file:
script_file.write(script_content)
# Make the script executable
!chmod +x 'run'
# Run the script
!./run python --version
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment