ModuleNotFoundError: No module named 'privacyidea'

I am in the process of setting up PrivacyIdea on Redhat using Python3.X. I have gone through the install instructions multiple times but after I get Apache calling the privacyideaapp.py I keep getting the error below. I am obviously missing something but I do not know where to look. I am at the point where when I go back through the instructions all of the PIP installs say it is already there. I can get into the virtualenv and all of the pi-manage stuff worked fine. The DB was created fine. Just can’t get the instance to start from apache because for whatever reason this error flies. Any advice or tips as to where to look for my mistake is appreciated.

Here is the error:
[Wed Feb 02 17:12:17.554636 2022] [cgid:error] [pid 1260:tid 139964268381952] [client some IP Address:65295] File “/etc/privacyidea/privacyideaapp.py”, line 5, in : /etc/privacyidea/privacyideaapp.py
[Wed Feb 02 17:12:17.554666 2022] [cgid:error] [pid 1260:tid 139964268381952] [client some IP Address:65295] from privacyidea.app import create_app: /etc/privacyidea/privacyideaapp.py
[Wed Feb 02 17:12:17.554684 2022] [cgid:error] [pid 1260:tid 139964268381952] [client some IP Address:65295] ModuleNotFoundError: No module named ‘privacyidea’: /etc/privacyidea/privacyideaapp.py
[Wed Feb 02 17:12:17.554693 2022] [cgid:error] [pid 1260:tid 139964268381952] [client some IP Address:65295] End of script output before headers: privacyideaapp.py
[Wed Feb 02 17:12:17.584629 2022] [cgid:error] [pid 1261:tid 139964403398400] [client some IP Address:65294] Traceback (most recent call last):: /etc/privacyidea/privacyideaapp.py, referer: WebAddresssomeURL/
[Wed Feb 02 17:12:17.584667 2022] [cgid:error] [pid 1261:tid 139964403398400] [client some IP Address:65294] File “/etc/privacyidea/privacyideaapp.py”, line 5, in : /etc/privacyidea/privacyideaapp.py, referer: WebAddresssomeURL/
[Wed Feb 02 17:12:17.584682 2022] [cgid:error] [pid 1261:tid 139964403398400] [client some IP Address:65294] from privacyidea.app import create_app: /etc/privacyidea/privacyideaapp.py, referer: WebAddresssomeURL/
[Wed Feb 02 17:12:17.584700 2022] [cgid:error] [pid 1261:tid 139964403398400] [client some IP Address:65294] ModuleNotFoundError: No module named ‘privacyidea’: /etc/privacyidea/privacyideaapp.py, referer: WebAddresssomeURL/
[Wed Feb 02 17:12:17.586393 2022] [cgid:error] [pid 1261:tid 139964403398400] [client some IP Address:65294] End of script output before headers: privacyideaapp.py, referer: WebAddresssomeURL/

Welcome @sehepler to the privacyIDEA community.

Go, authenticate, use it and help others in the future according to your abilities.

I think you might acually missing sth like

WSGIPythonHome /opt/privacyidea

in your Apache2 config. This would be why the default Python interpreter in your Apache can not find the privacyIDEA installation.

Hm, the enterprise packages for RHEL actually do this already…

Thank you for the reply.
I tried to add that and apache would not start up with that line in the conf. I know I have to be missing something easy that makes it when Apache executes the privacyideaapp.py it knows where the install is. I just can’t figure out where that is. It is definitely not in the instructions that I can find. I went through the Python install path and the CentOS path since RHEL is within that realm.

I take that back…I just fat fingered it. I still get the exact same error in the logs though.
ModuleNotFoundError: No module named ‘privacyidea’: /etc/privacyidea/privacyideaapp.py, referer:

The wsgi process can not find the python module.

What would I do an experienced and very analytic linux guy?

  • I would check for all log files, run a tail on it
  • Check that the location is right
  • check the access rights - if wsgi can not find the module, it could not read it
  • check for SELinux - after all you decided to go through the pain of running on RHEL :wink:

Good luck!

So I was in the exact same place with my Redhat 8.4 install. I must have installed privacyidea as root and not as user privacyidea. I had to uninstall privacyidea and then followed this:
Install the privacyIDEA server
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Now switch to that user and install the virtual environment for the privacyIDEA
server::

$ su - privacyidea

Create the virtual environment::

$ virtualenv /opt/privacyidea

activate it::

$ . /opt/privacyidea/bin/activate

and install/update some prerequisites::

(privacyidea)$ pip install -U pip setuptools

If this should be a pinned installation (that is the environment we use to build and test),
we need to install some pinned dependencies first. They should match the version of the targeted
privacyIDEA. You can get the latest version tag from the GitHub release page <https://github .com/privacyidea/privacyidea/releases>_ or the PyPI package history <https://pypi .org/project/privacyIDEA/#history>_ (e.g. “3.3.1”)::

    (privacyidea)$ export PI_VERSION=3.6.3
    (privacyidea)$ pip install -r https://raw.githubusercontent.com/privacyidea/privacyidea/v${PI_VERSION}/requirements.txt

Then just install the targeted privacyIDEA version with::

    (privacyidea)$ pip install privacyidea==${PI_VERSION}

After the I was able to access PrivacyIdea via Apache(httpd).

To make it short, it means that you lacked some “dependencies” for the libraries you wanted to use. This is a common problem when installing python packages, mainly in windows. Before trying to use any kind of library, first it is suggested to look up whether it needs another library in python “family”.

The solution is to provide the python interpreter with the path-to-your-module/library. The simplest solution is to append that python path to your sys.path list. In your notebook, first try:

import sys
sys.path.append('my/path/to/module/folder')

This isn’t a permanent change in sys.path, because when you log out, your environment is reset, so any variables you may have set are lost.

The better (and more permanent) way to solve this is to set your PYTHONPATH, which provides the interpreter with additional directories look in for python packages/modules.

from BASH type: export PYTHONPATH=/path/to/new/folder:/another/path/...../

#each path must be separated by a colon