3

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.

Robin Kohrs
  • 655
  • 7
  • 17

2 Answers2

4

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.

merv
  • 67,214
  • 13
  • 180
  • 245
  • Thanks so much!! Really helped clearing things up! What if I just copied the folder with a lot of .py (no __init__.py though) -files into the site-packes folder of my conda-environment? Could I still import the .py-modules from there into another module when I work with this specific conda environment? – Robin Kohrs Oct 20 '19 at 20:03
  • @RobinKohrs I think you need to have the `__init__.py` for it to be recognized as a module. – merv Oct 20 '19 at 20:05
  • Thanks a lot! I'll give it a try;) – Robin Kohrs Oct 20 '19 at 20:34
1

If you're using Python on Windows, then it may be best to resolve this by adding PYTHONPATH to the system variables, or if it's already set, then you may want to append the folder path to the variable.

Picture

If you don't already know how to access the system variables, or are confused on how to adjust PYTHONPATH for your needs, then you can check out this StackOverflow question, which has several in-depth answers that explain how to set/update PYTHONPATH on Windows: How to add to the PYTHONPATH in Windows, so it finds my modules/packages?

Someguy123
  • 1,324
  • 13
  • 27
ankulek07
  • 11
  • 1