Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add my own Module to my Anaconda environment

Basically the question is already up there. I created my environemt for the project with miniconda. Now I want to include some modules, bundled in directory into this environemt. So what I did was putting the directory in the '''/miniconda/env/..../sitepackages/mymodule/''' directory. When I run the module from the command line, where my current working directory is this directory it works. As soon as I just activate this conda environment and work in a different directory it tells me ModuleNotFoundError: No module named 'stdiio'

Hope it kind of makes sense and got more or less clear the question. Any help would be really appreciated.

like image 352
Robin Kohrs Avatar asked Sep 06 '25 03:09

Robin Kohrs


1 Answers

If your module is installable (e.g., you have a setup.py), then you can activate your Conda env and install using pip:

conda activate -n myenv
pip install /some/path/to/mymodule

If you are actively developing the module, then use pip install -e, instead.

If your module is not installable, but just some source folders with __init__.py files, then another option is to add the containing folder to PYTHONPATH. For example, if your module is in /some/path/to/mymodule, then you would use

export PYTHONPATH="/some/path/to:$PYTHONPATH"

Be careful with PYTHONPATH - one can encounter confusing problems if you allow conflicting outside modules to "leak" into your Conda environment (e.g., adding a site-packages from another Python install).

Installation should be the preferred option, and if you need to use PYTHONPATH, set it in an env-specific manner using activation hooks.

like image 83
merv Avatar answered Sep 07 '25 23:09

merv