473,473 Members | 1,889 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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
Oct 22 '08 #1
3 9451
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
Oct 22 '08 #2
On Wed, Oct 22, 2008 at 9:19 PM, Simon Strobl <Si**********@gmail.comwrote:
#!/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"
Oct 22 '08 #3
On 22 Okt., 13:24, "James Mills" <prolo...@shortcircuit.net.auwrote:
On Wed, Oct 22, 2008 at 9:19 PM, Simon Strobl <Simon.Str...@gmail.comwrote:
#!/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
Oct 22 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: ls | last post by:
Hi All, I looking for help with ZODB data export to text file. I have file Data.fs (file becomes from Plone CMS) and I have to display content structure, data like intro, body of article, etc...
6
by: Clay Beatty | last post by:
When you create database diagrams in Enterprise Manager, the details for constructing those diagrams is saved into the dtproperties table. This table includes an image field which contains most of...
3
by: Tor Erik Soenvisen | last post by:
Hi, I need to export an Oracle database to a DDL-formated file. On the Web, I found a Python script that did exactly this for a MS Access database, but not one for Oracle databases. Does...
2
hemantbasva
by: hemantbasva | last post by:
Note We need to have a template on server for generating report in multiple sheet as we do not had msoffice on server moreover this require a batch job to delete excel file created by the...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.