James Bond
James Bond

Reputation: 7913

how to load shell environment variables when Emacs starts py-shell?

I'm working for a university and they have their own libraries and paths for python libraries. Every time I start ipython, I need to run a shell script (e.g. /etc/university/env.sh)

The problem is that emacs doesn't recognize the env.sh file. When I do py-shell, emacs always envokes Python WITHOUT any pre-set environment variables.

Is there a way to make emacs run /etc/corporate/env.sh before starting python?

Upvotes: 1

Views: 413

Answers (2)

Andreas Röhler
Andreas Röhler

Reputation: 4804

After running your /etc/university/env.sh, start Emacs from this shell. Then the variables set before are known.

Upvotes: 0

abo-abo
abo-abo

Reputation: 20372

In /home/ccfenix/mypython.sh (make sure chmod +x, Emacs does this on auto):

#!/bin/bash

# . /etc/corporate/env.sh
export SOMEVAR=10
python "$@"

In ~/.emacs:

(defun my-python ()
  (interactive)
  (ansi-term "/home/ccfenix/mypython.sh"))

And to test: M-x mypython:

import os
print os.environ["SOMEVAR"]
# => 10

Upvotes: 1

Related Questions