Dmitriy_Cert
Dmitriy_Cert

Reputation: 177

os.environ doesn't see some variables

I have one problem with os.environ. I set some variables in my bat file (for example):

set MYDIR=%CURDIR%

Then I use set command in command line of Windows to check it. Everything is fine, my variable was added. But!

Then I run my Python script and use os.environ['MYDIR'] or os.getenv('MYDIR') but my envorinment variable doesn't show up!

Why does it happen?

My OS - Windows 7 x64, Python 2.5.4

Thanks.

Upvotes: 3

Views: 2383

Answers (1)

alko
alko

Reputation: 48317

Set works on session level. WinXP, use SETX from support tools http://www.microsoft.com/en-us/download/details.aspx?id=18546 to permanently set env variable.

Or use MyComputer>Properties>Advanced>Environment Variables to set user- and system- level variables.

Never used PyCharm, but breef scan through docs shows that you might be able to set script-level environment variables within PyCharm, look here http://www.jetbrains.com/pycharm/webhelp/run-debug-configuration-python.html

Upvotes: 3

Related Questions