pythonjupyteratom-editorpythonpathhydrogen

How to set the PYTHONPATH per project in ATOM editor


I wanted to replace Jupyter Notebooks with something which has a more IDE like feeling.

I stumbled upon Hydrogen which is a plugin for the Atom Editor.

It worked ok, but since I use the Cookiecutter directory layout I always had the problem that scripts I ran from my src folder needed other imports than the ones I used in the notebooks folder.

I tried a lot of other plugins like atom-python-run but I had the same problem. Depending on the directory where the script lived imports where not found.

Usually one would set the PYTHONPATH to add more folders for Python to search in, but I found no way to set the PYTHONPATH inside Hydrogen (ideally in a per project way). `


Solution

  • Cookiecutter has an .env-File in the root directory of the project.

    I added the PYTHONPATH there (caveat: do not have spaces around the equal sign!) and installed the load-dotenv-variables plugin in Atom.

    Now it is possible to start a script with hydrogen or atom-python-run independently of the current folder on a per-project basis.