Skip to content

Instantly share code, notes, and snippets.

@kbfreder
Created August 4, 2020 19:39
Show Gist options
  • Save kbfreder/f5747b7b0e2187bfe8b0cb0da36a46eb to your computer and use it in GitHub Desktop.
Save kbfreder/f5747b7b0e2187bfe8b0cb0da36a46eb to your computer and use it in GitHub Desktop.
after you make a virtualenv --relocatable, you need this file
!#python
"""
After you make a virtualenv relocatable (https://pypi.org/project/virtualenv/1.3.3/#making-environments-relocatable), pip will execute a file called 'activate_this.py' in <ENV_NAME>/bin if you go to install another module. In Python3 (? not sure of the cause), this file doesn't get created, so you have to make it. Through trial & error (no copy-and-paste correct answer was out there), I got this code to work.
"""
import os
activator = <path to activate_this.py> # ex: '/home/kfrederick/repos/domain_twists/env/bin/activate_this.py'
virtual_env = <path to virutal env> # ex: '/home/kfrederick/repos/domain_twists/env'
os.environ['PATH'] = os.pathsep.join([
os.path.join(virtual_env, 'bin'),
os.getenv('PATH', '')])
@kbfreder
Copy link
Author

kbfreder commented Aug 4, 2020

After you make a virtualenv relocatable (https://pypi.org/project/virtualenv/1.3.3/#making-environments-relocatable), pip will execute a file called 'activate_this.py' in <ENV_NAME>/bin if you go to install another module. In Python3 (? not sure of the cause), this file doesn't get created, so you have to make it. Through trial & error (no copy-and-paste correct answer was out there), I got this code to work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment