'Could not find platform dependent libraries <exec_prefix> Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>] for Python 3.9

I am trying to install Python 3.9 in order to access some updated libraries compared to Python 3.6. However, when I run my code, none of the previous libraries I have used in 3.6 seem accessible, and I get this error:

Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]
Traceback (most recent call last):
  File "/home/jsmith/Data/client_v3.py", line 1, in <module>
    import asyncio
  File "/usr/local/lib/python3.9/asyncio/__init__.py", line 8, in <module>
    from .base_events import *
  File "/usr/local/lib/python3.9/asyncio/base_events.py", line 23, in <module>
    import socket
  File "/usr/local/lib/python3.9/socket.py", line 51, in <module>
    import _socket
ModuleNotFoundError: No module named '_socket'

I have seen that I may needto set the location of the installation somehow, but I have no idea how I can dothis. I have tried performing:

export PYTHONHOME= '/usr/local/bin/python3.9'

But this results in:

bash: export: `/usr/local/bin/python3.9': not a valid identifier

How do I get my new installation of Python 3.9 to function as expected?



Solution 1:[1]

I think your problem is in the space between PYTHONHOME= and the source of the directory. Try removing it and report back if you still have a problem!

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 maynouf