Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Python

do export statement in Python script

 

 

Python python RSS feed   Index | Next | Previous | View Threaded


Simon.Strobl at gmail

Oct 22, 2008, 4:19 AM

Post #1 of 4 (237 views)
Permalink
do export statement in Python script

Hello,

a program of mine, which is supposed to be used in a project, uses
nltk. I want the other users to be able to use my program without
having to fiddle around with their environment. Therefore, I tried
this code:

#!/usr/bin/
python

import os

os.system("export NLTK_DATA=/opt/nltk/data/")

import nltk

This doesn't work, although running "export NLTK_DATA=/opt/nltk/data/"
on the command line before running the program works. Why?

Simon
--
http://mail.python.org/mailman/listinfo/python-list


deets at nospam

Oct 22, 2008, 4:20 AM

Post #2 of 4 (219 views)
Permalink
Re: do export statement in Python script [In reply to]

Simon Strobl wrote:

> Hello,
>
> a program of mine, which is supposed to be used in a project, uses
> nltk. I want the other users to be able to use my program without
> having to fiddle around with their environment. Therefore, I tried
> this code:
>
> #!/usr/bin/
> python
>
> import os
>
> os.system("export NLTK_DATA=/opt/nltk/data/")
>
> import nltk
>
> This doesn't work, although running "export NLTK_DATA=/opt/nltk/data/"
> on the command line before running the program works. Why?

because export is a shell-command that affects only the current shell, not
the parent process environment. And os.system spawns a child-process.

Instead, use

os.environ["NLTK_DATA"] = "/opt/nltk/data"

Diez
--
http://mail.python.org/mailman/listinfo/python-list


prologic at shortcircuit

Oct 22, 2008, 4:24 AM

Post #3 of 4 (211 views)
Permalink
Re: do export statement in Python script [In reply to]

On Wed, Oct 22, 2008 at 9:19 PM, Simon Strobl <Simon.Strobl [at] gmail> wrote:
> #!/usr/bin/
> python
>
> import os
>
> os.system("export NLTK_DATA=/opt/nltk/data/")

Try:

os.environ["NLTK_DATA"] = "/opt/nltk/data/"

if that doesn't work, consider wrapping up NLTK
in a bash script that contains the shell statement:
export var=...

cheers
James

--
--
-- "Problems are solved by method"
--
http://mail.python.org/mailman/listinfo/python-list


Simon.Strobl at gmail

Oct 22, 2008, 4:30 AM

Post #4 of 4 (212 views)
Permalink
Re: do export statement in Python script [In reply to]

On 22 Okt., 13:24, "James Mills" <prolo...@shortcircuit.net.au> wrote:
> On Wed, Oct 22, 2008 at 9:19 PM, Simon Strobl <Simon.Str...@gmail.com> wrote:
> > #!/usr/bin/
> > python
>
> > import os
>
> > os.system("export NLTK_DATA=/opt/nltk/data/")
>
> Try:
>
> os.environ["NLTK_DATA"] = "/opt/nltk/data/"
>
> if that doesn't work, consider wrapping up NLTK
> in a bash script that contains the shell statement:
> export var=...
>
> cheers
> James
>
> --
> --
> -- "Problems are solved by method"

Thanks for the answers. "os.environ["NLTK_DATA"] = "/opt/nltk/data/"
works.

Simon
--
http://mail.python.org/mailman/listinfo/python-list

Python python RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.