Package installed in conda but module not found. How is that possible?

Question:

It seems that many people struggle with this problem, but I can’t find any answer that works.
I think that I am doing everything right but it still doesn’t work.
I’ve built my own package and installed it in my conda environment.
When I do conda list, it turns up in the list, at the end (I’ve called it zzpackagerps):

...
zlib                      1.2.11            h62dcd97_1010    conda-forge
zstd                      1.4.9                h6255e5f_0    conda-forge
zzpackagerps              0.0.1                     dev_0    <develop>

Now when I run python, in this environment (py39), and try to import the package, I get the infamous ModuleNotFoundError:

(py39) s:Sources>python
Python 3.9.4 | packaged by conda-forge | (default, May 10 2021, 22:10:34) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import zzpackagerps
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'zzpackagerps'
>>>

How is this possible? Or, more importantly, how do I get this to work?
(by the way: running on Windows)

Asked By: Reinier

||

Answers:

Cannot comment so asking here.

Did you install the package as root? If yes, execute the following:

sudo chmod -R a+rX /home/deeplearning/anaconda3/envs/

If not, then it can be a Potential Path Problem:

Your python command might refer to a different python than the python which is in your active conda environment folder. Check this by running in the terminal which conda and which python.

Alternatively, reinstall conda.

Answered By: Anurag.k

One possible issue is that the package name may not be identical to the module name. If you locate the site-packages where the package is installed, you can try looking at the folder structure and where there are __init__.py files defined.

Answered By: merv

I had a similar problem. I discovered that my Conda env was not activated at the time that I installed the module. So I did "conda activate myenv", before doing "conda install " again. And this time it was picked up correctly. If you are not sure which virtual env are available, use "conda env list" to list them. The one with the asterisk beside it is the currently active env.

Answered By: user20325015

Windows users read this:

When using the Anaconda prompt on Windows, type "python" instead of "py" to run Python in the Anaconda environment with all your modules loaded. Typing "py" will run Python outside of the Anaconda environment. This is because, on Windows, typing "python" in the cmd will open the Microsoft store, so "py" is used as a shortcut to run Python from the command line.

Answered By: Florian Fasmeyer