. Advertisement .
..3..
. Advertisement .
..4..
PyCharm software provides a complete set of tools for professional Python developers. PyCharm is built around an editor that understands code deeply, and a debugger that gives a clear view of how the code works. An important aspect of programming is understanding the code platform you’re entering. PyCharm ensures you can explore your project with just a few taps, it gives you an overview of the project structure and gives you instant access to relevant documents. Understanding a coding platform faster means speeding up your development process. Our today’s article will show you the steps to “set environment variables in PyCharm”. Let’s check it out!
Example Of Setting Environment Variables In PyCharm
Here is an example to show you how to set environment variables in Pycharm. Suppose below are the variables need to be set:
export DATABASE_URL=postgres://127.0.0.1:5432/my_db_name
export DEBUG=1
# there are other variables, but they contain personal information
Here are the steps to guide you to set the environment variables
Steps to set environment variables in PyCharm
In computer science, a variable is a store of value that changes according to a condition, which is passed to the application. Variables play an important role in the program to help programmers write flexible programs related to the operating system they are working on.
Environment variables are dynamic values that affect software and server processes. Environment variables are available on all operating systems and come in many different types. Environment variables can be created, edited, saved or deleted.
Method 1: Do the following
Pycharm doesn’t launch from a terminal, so your environment won’t load. If you want to set the variable you have to set it up as a variable in PyCharm. To set your environment variables in PyCharm, do the following:
Step 1: Open ‘File’ menu, Click ‘Settings’, “Run Configuration” tab will appear, tap on it, like the picture below:
......... ADVERTISEMENT .........
..8..
Step 2: Click on ‘+’ sign next to ‘Console’ then click on Python Console, python console box appears. Here look for the Environmental variables tab and tap on it:
......... ADVERTISEMENT .........
..8..
Step 3: Click the ‘…’ button next to environment variables
Click ‘+’ to add environment variables. Here you can also add, remove or change variables. After making adjustments, click OK to complete the process.
......... ADVERTISEMENT .........
..8..
With the support of os.environ you can completely run environment variables by declaring the command as follows:
import os
print(os.environ['SOME_VAR'])
Method 2: Use the EnvFile PyCharm plugin
Excepting the solution mentioned above, there is another solution for you to set environment variables in Pycharm. Let’s follow this guide:
With the use of the EnvFile PyCharm plugin, we were able to determine this. This plugin enables the establishment of environment variables to execute configurations from single or several files. Installation is fairly easy: Install Plugin from Preferences > Plugins > Browse Repositories > Search for “Env File” Then, we made a file called environment.env at the root of our project that has the following contents:
DATABASE_URL=postgres://127.0.0.1:5432/my_db_name
DEBUG=1
Next, we went to Run->Edit Configurations and carried out the procedures shown in the following image:
......... ADVERTISEMENT .........
..8..
In 3, we selected the environment.env file. After that, all we had to do was to hit the play button in PyCharm, and everything was flawless.
Conclusion
Thus, through the above article, we have given the steps to “set environment variables in Pycharm”. Hope the article is useful to you. Please leave a comment if you have any further questions or concerns regarding installing pip on your machine. Thank you for taking the time to read; we are always delighted anytime one of our pieces can give important information on this topic!
Read more
→ Tips On Solving The Error: “pycharm WARNING: Value for scheme.purelib does not match”
Leave a comment