1

Using the ! magic I can access env type environment variables, but not ones defined in my terminal, or .bashrc.

$:/<path>/balter/chip-seq-analysis/chipseq$ echo $hg38
/<path>/genomes/hg38/release-85/Homo_sapiens.GRCh38.dna.primary_assembly.fa
balter@exalab3:/<path>/balter/chip-seq-analysis/chipseq$ ipython
Python 2.7.12 |Continuum Analytics, Inc.| (default, Jul  2 2016, 17:42:40)
Type "copyright", "credits" or "license" for more information.

IPython 5.1.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: !echo $hg38


In [2]: !echo $SHELL
/usr/bin/bash

In [3]:
4
  • 1
    if your variables are not exported, no subprocess can access them, pyhton or not. Commented Nov 21, 2016 at 20:29
  • So, in my .bashrc I need to have export hg38=.... with the export? I'll try that. Commented Nov 21, 2016 at 21:40
  • 1
    yes, it's necessary! Commented Nov 21, 2016 at 21:43
  • @Jean-FrançoisFabre please make it an answer so I can accept! Commented Nov 21, 2016 at 22:01

1 Answer 1

2

if your variables are not exported, no subprocess can access them, python or not.

foo=value

is only seen by the current process (here: bash)

but if you do (in your .bashrc):

export foo

or set & export:

export foo=value

then the variable becomes visible by subprocesses. That's your fix.

BTW, to get an env. variable in python, the real python way is:

import os
print(os.getenv("foo"))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.