DEV Community

Clarice Bouwer
Clarice Bouwer

Posted on

3

How to configure python environs for Visual Studio Code

If you need to store environment variables for Python that does not automatically get detected by VS Code then this answer should hopefully help you.

I am doing a Data Science bootcamp and need to store a specific path for one of my challenges.

Exporting PYTHONPATH in ~/.zshrc works perfectly when I run the notebook directly from Juypter, however the environment variable is not detected through VS Code.

I created a global file in my home directory from the pwd (present working directory) that I wanted to store in my path:

echo "export PYTHONPATH=$(pwd):$PYTHONPATH" >> ~/.python-env
Enter fullscreen mode Exit fullscreen mode

I opened the JSON User Settings in VS Code and added the python.envFile setting which points directly to ~/.python-env

{
    "python.envFile": "~/.python-env"
}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more