Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #105518 > unrolled thread
| Started by | Hongyi Zhao <hongyi.zhao@gmail.com> |
|---|---|
| First post | 2016-03-23 07:12 +0000 |
| Last post | 2016-03-23 19:08 +1100 |
| Articles | 5 — 3 participants |
Back to article view | Back to comp.lang.python
Obtain the variable in bash. Hongyi Zhao <hongyi.zhao@gmail.com> - 2016-03-23 07:12 +0000
Re: Obtain the variable in bash. Chris Angelico <rosuav@gmail.com> - 2016-03-23 18:19 +1100
Re: Obtain the variable in bash. Hongyi Zhao <hongyi.zhao@gmail.com> - 2016-03-23 08:35 +0000
Re: Obtain the variable in bash. Chris Angelico <rosuav@gmail.com> - 2016-03-23 19:45 +1100
Re: Obtain the variable in bash. Ben Finney <ben+python@benfinney.id.au> - 2016-03-23 19:08 +1100
| From | Hongyi Zhao <hongyi.zhao@gmail.com> |
|---|---|
| Date | 2016-03-23 07:12 +0000 |
| Subject | Obtain the variable in bash. |
| Message-ID | <nctfkg$kt7$1@aspen.stu.neva.ru> |
Hi all, I exported a variable in my .bashrc as follows: export MY_VAR="fdsfads" Then I soured the .bashrc and do the testing as follows: werner@debian-01:~$ python -c "import os; print os.environ['MY_VAR']" fdsfads But, when I run the same commands in pycharm and wing ide, I failed the obtain the value of this variable. I'm very confused with this issue. Any hints? Regards -- .: Hongyi Zhao [ hongyi.zhao AT gmail.com ] Free as in Freedom :.
[toc] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2016-03-23 18:19 +1100 |
| Message-ID | <mailman.32.1458717548.2244.python-list@python.org> |
| In reply to | #105518 |
On Wed, Mar 23, 2016 at 6:12 PM, Hongyi Zhao <hongyi.zhao@gmail.com> wrote: > I exported a variable in my .bashrc as follows: > > export MY_VAR="fdsfads" > > Then I soured the .bashrc and do the testing as follows: > > werner@debian-01:~$ python -c "import os; print os.environ['MY_VAR']" > fdsfads > > But, when I run the same commands in pycharm and wing ide, I failed the > obtain the value of this variable. > > I'm very confused with this issue. > Did you start pycharm/wing from the same session in which you sourced .bashrc? If not, they won't see that change. My guess is that you started the IDEs from your GUI in some way (the Applications menu or something). If that's the case, they'll inherit their environment from your GUI. You _may_ be able to have them "notice" your change to .bashrc by logging out and in again, or rebooting; it depends how your system is configured. ChrisA
[toc] | [prev] | [next] | [standalone]
| From | Hongyi Zhao <hongyi.zhao@gmail.com> |
|---|---|
| Date | 2016-03-23 08:35 +0000 |
| Message-ID | <nctkgu$p7s$1@aspen.stu.neva.ru> |
| In reply to | #105519 |
On Wed, 23 Mar 2016 18:19:04 +1100, Chris Angelico wrote: > Did you start pycharm/wing from the same session in which you sourced > .bashrc? If not, they won't see that change. Thanks a lot for this explanations. It does behaves as you said which I previously not noticed. > > My guess is that you started the IDEs from your GUI in some way (the > Applications menu or something). If that's the case, they'll inherit > their environment from your GUI. You _may_ be able to have them "notice" > your change to .bashrc by logging out and in again, or rebooting; it > depends how your system is configured. I tried and find that I must set the variable in .profile file, instead of .bashrc, in order to let the IDEs started from my GUI to recognize them after I logged out and in again. Regards > > ChrisA -- .: Hongyi Zhao [ hongyi.zhao AT gmail.com ] Free as in Freedom :.
[toc] | [prev] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2016-03-23 19:45 +1100 |
| Message-ID | <mailman.39.1458722711.2244.python-list@python.org> |
| In reply to | #105524 |
On Wed, Mar 23, 2016 at 7:35 PM, Hongyi Zhao <hongyi.zhao@gmail.com> wrote: >> My guess is that you started the IDEs from your GUI in some way (the >> Applications menu or something). If that's the case, they'll inherit >> their environment from your GUI. You _may_ be able to have them "notice" >> your change to .bashrc by logging out and in again, or rebooting; it >> depends how your system is configured. > > I tried and find that I must set the variable in .profile file, instead > of .bashrc, in order to let the IDEs started from my GUI to recognize > them after I logged out and in again. Yep, that would do it! Sometimes your GUI will be started from an interactive shell (or one that thinks it's interactive), in which case .bashrc will be processed, but in your case, .profile is the solution. ChrisA
[toc] | [prev] | [next] | [standalone]
| From | Ben Finney <ben+python@benfinney.id.au> |
|---|---|
| Date | 2016-03-23 19:08 +1100 |
| Message-ID | <mailman.33.1458720535.2244.python-list@python.org> |
| In reply to | #105518 |
Hongyi Zhao <hongyi.zhao@gmail.com> writes: > I exported a variable in my .bashrc as follows: > > export MY_VAR="fdsfads" That ‘export’ means that child processes of this one (i.e., the shell in which that command executed) will inherit that variable in their environment. Processes that are not children of this one, will not be affected. > Then I soured the .bashrc and do the testing as follows: > > werner@debian-01:~$ python -c "import os; print os.environ['MY_VAR']" > fdsfads Yes. Because that ‘python’ process is started from a process which has that exported variable, that ‘python’ process inherits the variable in its environment. > But, when I run the same commands in pycharm and wing ide, I failed the > obtain the value of this variable. Were they started as child processes from the shell that is exporting the variable? See <URL:https://en.wikipedia.org/wiki/Environment_variable#Unix_2> for a discussion of how the process environment variables are inherited. -- \ “Every man would like to be God, if it were possible; some few | `\ find it difficult to admit the impossibility.” —Bertrand | _o__) Russell, _Power: A New Social Analysis_, 1938 | Ben Finney
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web