I have a few problems regarding the use of .bash_profile
and Pycharm. I am using mac OS X. I created a new project on pycharm with new environment using virtualenv with base interpreter /usr/local/bin/python3.5
.
STEP 1:
I then accessed the .bash_profile from my mac OS terminal and exported 2 variables: DB_USER
and DB_PASS
as my_db_user
and my_db_pass
respectively.
STEP 2:
Using Pycharm, I imported os and then proceeded to print out the 2 variables using os.environ.get()
. Running the .py file using pycharm (F10) returns my_db_user
and my_db_pass
.
As I decided to create 2 new variables test user
and test pass
in the virtual environment, I proceeded to activate my venv (venv/bin/activate
) in the shell of pycharm. Then, I removed the changes I did in STEP 1.
However, running the .py using pycharm (F10) STILL returns my_db_user
and my_db_pass
instead of test user
and test pass
(I have already removed my_db_user
and my_db_pass
so I have no idea where it is coming from!). On top of that, when I run the python file on the shell using python test.py, it returns (None, None) instead of my desired test user
and test pass
.
I need help to sort this out so that os.environ.get()
returns my desired output. One possible reason is that I might be confused on how pycharm, shell in pycharm and terminals are interacting. Please help thanks!
import os
user = os.environ.get('DB_USER')
password = os.environ.get('DB_PASS')
print(user,password)
If I read your post correctly, you have already cleared out the .bash_profile
file, so what remains is just running
unset DB_USER DB_PASS
in each shell window that still has the environment variables.