Cord Kaldemeyer Cord Kaldemeyer - 1 month ago 17
Python Question

Anaconda: Permanently include external packages (like in PYTHONPATH)

I know how to install packages in Anaconda using

conda install
and also how to build packages that are on PyPi which is described in the manual.

But how can I permanently include packages/folders in Anaconda e.g. with code that I am currently working on?

My current approach is to use
sys
:

import sys
sys.path.append(r'/path/to/my/package')


which is not really convenient.

Any hints?

Thanks in advance!

Answer

I found two answers to my question in the Anaconda forum:

1.) Put the modules into into site-packages, i.e. the directory $HOME/path/to/anaconda/lib/pythonX.X/site-packages which is always on sys.path.

2.) Add a .pth file to the directory $HOME/path/to/anaconda/lib/pythonX.X/site-packages. This can be named anything (it just must end with .pth). A .pth file is just a newline-separated listing of the full path-names of directories that will be added to your path on Python startup.

Both work straightforward and I went for the second option as it is more flexible.

Thanks anyway!