115

I'm trying to use Fontcustom to create an icon font using svg files and fontforge. I'm on OSX.7. However, whenever I run the program I get the error

Could not find platform independent libraries <prefix>
Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]
ImportError: No module named site

What do <prefix> and <exec_prefix> mean here? How can I fix the problem?

On my system, python --version reports Python 2.7.1. I checked the corresponding library directory /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7, and it includes site.py. Why isn't that module found?

Karl Knechtel
  • 62,466
  • 11
  • 102
  • 153
Lars
  • 7,908
  • 11
  • 52
  • 70

6 Answers6

75

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).

Peter Mitrano
  • 2,132
  • 28
  • 31
  • 8
    This worked for me when I upgraded my server from Ubuntu 14.04 LTS to Ubuntu 16.04 LTS. I also had to solve this problem: https://stackoverflow.com/questions/36954983/installing-scrapy-on-mac-pyasn1-distribution-not-found – tytk Jun 13 '17 at 18:34
  • 1
    `cd ` then `pipenv shell` then `pipenv --venv` – Ashkan Kh. Nazary Jul 05 '18 at 12:50
  • 1
    1. I'm getting the above but have no idea where is? and 2. `pipenv` gives me: `zsh: command not found: pipenv` – Snowcrash Jul 16 '20 at 13:42
  • This was the issue that caused the same error message for me, but the fix that worked was `pipenv --rm` – Nicolay77 Aug 23 '22 at 13:49
  • this was helpful for me: https://help.pythonanywhere.com/pages/RebuildingVirtualenvs/ – TmTron Jan 12 '23 at 14:30
64

Try export PYTHONHOME=/usr/local. Python should be installed in /usr/local on OS X.

This answer has received a little more attention than I anticipated, I'll add a little bit more context.

Normally, Python looks for its libraries in the paths prefix/lib and exec_prefix/lib, where prefix and exec_prefix are configuration options. If the PYTHONHOME environment variable is set, then the value of prefix and exec_prefix are inherited from it. If the PYTHONHOME environment variable is not set, then prefix and exec_prefix default to /usr/local (and I believe there are other ways to set prefix/exec_prefix as well, but I'm not totally familiar with them).

Normally, when you receive the error message Could not find platform independent libraries <prefix>, the string <prefix> would be replaced with the actual value of prefix. However, if prefix has an empty value, then you get the rather cryptic messages posted in the question. One way to get an empty prefix would be to set PYTHONHOME to an empty string. More info about PYTHONHOME, prefix, and exec_prefix is available in the official docs.

jayhendren
  • 4,286
  • 2
  • 35
  • 59
  • 3
    What should I do if I am using two different virtualenvs: One for Python 2.7 and one for Python 3.6? – Elias Strehle Jul 23 '18 at 15:05
  • Had this issue when compiled C code that calls Python function using Cython as in this question: https://stackoverflow.com/questions/22589868/call-python-code-from-c-via-cython/58847011#58847011 . The executable complained about the missing libraries and modules. Defining both PYTHONHOME and PYTHONPATH solved the issue. Thanks. – AlexF Jun 01 '23 at 16:25
11

I had this issue while using Python installed with sudo make altinstall on Opensuse linux. It seems that the compiled libraries are installed in /usr/local/lib64 but Python is looking for them in /usr/local/lib.

I solved it by creating a dynamic link to the relevant directory in /usr/local/lib

sudo ln -s /usr/local/lib64/python3.8/lib-dynload/ /usr/local/lib/python3.8/lib-dynload

I suspect the better thing to do would be to specify libdir as an argument to configure (at the start of the build process) but I haven't tested it that way.

Edit: Can confirm that ./configure --libdir=/usr/local/lib works, and is probably better than creating links.

DavidW
  • 29,336
  • 6
  • 55
  • 86
  • Indeed that solved my problem. I also moved the file libpython3.8.a and pkgconfig folder as described here https://www.reddit.com/r/openSUSE/comments/7cmawa/installing_latest_python/ – ciencia Sep 23 '20 at 11:01
9

change PYTHONHOME to the parent folder of the bin file of python, like /usr,which is the parent folder of /usr/bin.

jimmy
  • 111
  • 1
  • 3
6

I had this problem and spent a few hours trying to fix it. I fixed the prefix error by changing the path but I still had an encoding import error. This was fixed by restarting my computer.

Erich
  • 1,902
  • 1
  • 17
  • 23
1

My pycharm ce had the same error, was easy to fix it, if someone has that error, just uninstall and delete the folder, use ctrl+h if you can't find the folder in your documents, install the software again and should work again.

Remember to save the scratches folder before erasing the pycharm folder.

Marcello B.
  • 4,177
  • 11
  • 45
  • 65
Jesus
  • 11
  • 1