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 errorIt sounds like it. The Python interpreter chooses the default module path based either on
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?
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:Note in particular the hint about what Python expects to find in a directory named byPYTHONPATH : ':'-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.
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 bePYTHONHOME=/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:
- Install python
- Create a virtualenv using that version of python (eg. virtualenv --python="path to python in 1" virt)
- Switch to that virtualenv (workon virt)
- Now install Django, etc. inside of the virtualenv virt
Are you using homebrew? I've found that's the most reliable way to get stuff on the mac.
Related Topics
How to Reverse a Dictionary That Has Repeated Values
Django - Makemigrations - No Changes Detected
Python MySQL Connector - Unread Result Found When Using Fetchone
Disable or Lock Mouse and Keyboard in Python
Python Tracing a Segmentation Fault
How to Get Windows' Special Folders for Currently Logged-In User
Increment Numpy Array with Repeated Indices
How to Update SQLalchemy Row Entry
Changing the Options of a Optionmenu When Clicking a Button
How to Delete Created Variables, Functions, etc from the Memory of the Interpreter
How Does Sklearn.Svm.Svc's Function Predict_Proba() Work Internally
Overflowerror: (34, 'Result Too Large')