.bashrc environment variables

1,019 views
Skip to first unread message

Peter Tittmann

unread,
Feb 22, 2011, 5:37:57 PM2/22/11
to spyd...@googlegroups.com
Hi,

Im using some of the the popular GRASS GIS tools from a python script. Importing the modules depends on os.getenv() returning a value for the GRASS base directory ($GISBASE in my .bashrc file). When I start python (or Ipython) from a shell  have no problem importing the grass modules. When attempting to import the grass modules within Spyder, the environment variables in .bashrc don't seem to be available as I get:

Traceback (most recent call last):
  File "<ipython console>", line 1, in <module>
  File "/usr/lib/grass64/etc/python/grass/script/__init__.py", line 1, in <module>
    from core   import *
  File "/usr/lib/grass64/etc/python/grass/script/core.py", line 35, in <module>
    gettext.install('grassmods', os.path.join(os.getenv("GISBASE"), 'locale'), unicode=True)
  File "/usr/lib/python2.6/posixpath.py", line 67, in join
    elif path == '' or path.endswith('/'):
AttributeError: 'NoneType' object has no attribute 'endswith'

which makes sense because os.env('GISBASE') returns None. 

I've temporarily solved this by duplicating an existing environment variable from the running python shell within Spyder, renaming it and assigning it the correct path. This seems cumbersome and I wonder if there is a better way to access the environment variables in the .bashrc.

Thanks much,

Peter

-- 
Peter Tittmann


Matthew Brookhart

unread,
Mar 31, 2011, 12:51:49 PM3/31/11
to spyder
Hi,

Did anyone ever get solved? I need to use a python module for data
access that uses a couple of environmental variables defined
in .bashrc and I'm having the same problem. If I load ipython in a
terminal everything is fine, but loading in spyder doesn't work.

Thanks,
Matthew

David Verelst

unread,
Nov 29, 2011, 7:12:10 AM11/29/11
to spyd...@googlegroups.com, matthewb...@gmail.com, ptit...@gmail.com
Hi,

As I recently found out, any variables set in ~.bashrc are available from the shell, and consequently anything that has been launched from that specific shell. This is not necessarily system wide. In Ubuntu 10.04, any paths set in ~.profile are available for spyder/python/whatever launched outside a shell (for instance from a desktop launcher). Note that in my case, ~.profile is only executed upon login, so for any changes to take effect I have to logout and login again.

So in conclusion and based on my system (Ubuntu 10.04), the correct place to set environment variables for spyder is in ~.profile, not ~.bashrc.

Regards,
David

--
You received this message because you are subscribed to the Google Groups "spyder" group.
To post to this group, send email to spyd...@googlegroups.com.
To unsubscribe from this group, send email to spyderlib+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/spyderlib?hl=en.


Reply all
Reply to author
Forward
0 new messages