Problem scenario
You have Python 2 and Python 3 installed. When you run Python 3 programs, you get an error message about selinux. The message is consistent with libselinux-python not being installed.
When you enter the Python interpreter for Python 2, you can run this command without errors: import selinux
But when you enter the Python interpreter for Python 3 (e.g., python3), you get errors when you run this command: import selinux
Security of the server is not critical, and you have no access to download packages from the internet. What should you do?
Solution
- Run this command from a terminal:
python -v
- From the Python 2 interpreter line, run this command: import selinux
- The output of the above should show where selinux is. Enter this command to get back to a command prompt:
quit()
- Find where Python 3's packages should be with this command:
sudo find / -name site-packages | grep python3
- Run a command like this to create site-packages in a Python 3 directory if you found nothing from step #4.
sudo mkdir -P /path/to/destination/site-packages
- Run a modified version of this command:
sudo cp -R /path/to/source /path/to/destination
/site-packages
But replace /path/to/source with the site-packages directory found in step #2's results. Replace /path/to/destination with the site-packages directory found in step #4 or created in step #5.