" Is my diagnosis of the cause of Could not find platform independent libraries pre">

How to Troubleshoot Python "Could Not Find Platform Independent Libraries <Prefix>"

How can I troubleshoot Python "Could not find platform independent libraries "

If you made a virtual env, then deleted that python installation, you'll get the same error. Just rm -r your venv folder, then recreate it with a valid python location and do pip install -r requirements.txt and you'll be all set (assuming you got your requirements.txt right).

Is my diagnosis of the cause of Could not find platform independent libraries prefix correct and how can I fix it?

As I understand the above problem, the reason I am getting this error
is because I need to give a the specific path for python to look for
libraries/modules. Setting PYTHONHOME and/or PYTHONPATH should fix
this problem then.

[...]

Have I correctly diagnosed the problem?

It sounds like it. The Python interpreter chooses the default module path based either on PYTHONHOME or on its installation location and compile-time configuration, but the latter is out the window when you embed the interpreter in another program. The interpreter uses PYTHONPATH to identify additional directories to search for modules.

You should not normally set PYTHONHOME when using the standalone interpreter, but it is reasonable to do so when embedding the interpreter.

If so, what should I set these two environment variables to?

The output of python3 -h on my system includes this:

PYTHONPATH   : ':'-separated list of directories prefixed to the
default module search path. The result is sys.path.
PYTHONHOME : alternate <prefix> directory (or <prefix>:<exec_prefix>).
The default module search path uses <prefix>/pythonX.X.

Note in particular the hint about what Python expects to find in a directory named by PYTHONHOME.

In your case, you should probably set PYTHONHOME because the interpreter does not recognize how to find the system modules. The actual value that variable should take depends on where the desired Python implementation resides (and this should probably be the same implementation whose python library you linked your program against). For the system Python, on my machine, it would be

PYTHONHOME=/usr/lib:/usr/lib64

For my Anaconda 2, installed in /opt/anaconda2, it would be

PYTHONHOME=/opt/anaconda2/lib

You should not need to set PYTHONPATH (and, in fact, you might want to ensure it is unset) unless there are additional locations you want Python to search for modules.

Could not find platform independent libraries prefix Consider setting $PYTHONHOME to prefix[:exec_prefix]

You seem to have things turned around. Virtualenv creates a python environment that encapsulates a python install. So you want to do the following:

  1. Install python
  2. Create a virtualenv using that version of python (eg. virtualenv --python="path to python in 1" virt)
  3. Switch to that virtualenv (workon virt)
  4. Now install Django, etc. inside of the virtualenv virt

Here is the recipe I used to get my environment setup and running.

Are you using homebrew? I've found that's the most reliable way to get stuff on the mac.



Related Topics



Leave a reply



Submit