I am working on a python project using Visual Studio Code on Ubuntu OS and I need to set environment variables without using the integrated terminal, I want to be able to set it using a file or an efficient medium asides my terminal.
Please help
I am working on a python project using Visual Studio Code on Ubuntu OS and I need to set environment variables without using the integrated terminal, I want to be able to set it using a file or an efficient medium asides my terminal.
Please help
2
Answers
So I was able to find a solution that enabled me specify my variables in a .env file in Visual Studio Code
I used a python module called python-dotenv the setup for installing it can be found in https://pypi.org/project/python-dotenv/
So follow these steps:
In your Visual Studio Code integrated terminal, install python-dotenv using
pip install python-dotenv
In your python code add this at the top of the code
In your code folder i.e where the python code specified above lies, create a file called .env
Now specify all your environment variables inside the .env file e.g
/etc/environment
is the second boot file when logging into the Linux system.You can use the following command to open, or open the file in the directory:
Environment variables are defined here. We can add environment variables you need, such as:
So we add anaconda2 to PATH environment variable.