如何解决 Python“找不到平台独立库 <prefix>”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19292957/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 13:21:55  来源:igfitidea点击:

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

pythonpathimporterror

提问by Lars

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

我正在尝试使用 Fontcustom 来创建使用 svg 文件和 fontforge 的图标字体。我在 OSX.7 上。但是,每当我运行程序时,我都会收到错误消息

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`

As a Python/Unix newbie I don't even know where to start trying to solve this. Can anyone offer any advice? What are <prefix>and <exec_prefix>referring to?

作为 Python/Unix 新手,我什至不知道从哪里开始尝试解决这个问题。任何人都可以提供任何建议吗?什么是<prefix><exec_prefix>指什么?

When I type python --versionI get Python 2.7.1. And in the directory /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7, there is a big list of modules, and site.py is definitely in that folder. How can I get my computer to find the modules?

当我输入时,python --version我得到Python 2.7.1. 并且在目录/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7 中,有一个很大的模块列表,而site.py 肯定在该文件夹中。如何让我的计算机找到模块?

回答by jayhendren

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

试试export PYTHONHOME=/usr/local。Python 应该安装在/usr/localOS 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/liband exec_prefix/lib, where prefixand exec_prefixare configuration options. If the PYTHONHOMEenvironment variable is set, then the value of prefixand exec_prefixare inherited from it. If the PYTHONHOMEenvironment variable is not set, then prefixand exec_prefixdefault to /usr/local(and I believe there are other ways to set prefix/exec_prefixas well, but I'm not totally familiar with them).

通常,Python 在路径prefix/lib和中查找其库exec_prefix/lib,其中prefixexec_prefix是配置选项。如果PYTHONHOME设置了环境变量,则从它继承prefix和的值exec_prefix。如果PYTHONHOME没有设置环境变量,然后prefixexec_prefix默认/usr/local(我相信还有其他的方法来设置prefix/exec_prefix为好,但我不完全熟悉它们)。

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 prefixhas an empty value, then you get the rather cryptic messages posted in the question. One way to get an empty prefixwould be to set PYTHONHOMEto an empty string. More info about PYTHONHOME, prefix, and exec_prefixis available in the official docs.

通常,当您收到错误消息时Could not find platform independent libraries <prefix>,字符串<prefix>将被替换为 的实际值prefix。但是,如果prefix有一个空值,那么您会收到问题中发布的相当神秘的消息。获取空值的一种方法prefix是设置PYTHONHOME为空字符串。有关更多信息PYTHONHOMEprefix以及exec_prefix在现有的官方文档

回答by jimmy

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

将PYTHONHOME改为python的bin文件的父文件夹,如/usr,即/usr/bin的父文件夹。

回答by Erich

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.

我遇到了这个问题,并花了几个小时试图解决它。我通过更改路径修复了前缀错误,但我仍然遇到编码导入错误。这是通过重新启动我的计算机来解决的。

回答by Peter Mitrano

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

如果你创建了一个虚拟环境,然后删除了那个 python 安装,你会得到同样的错误。只是rm -r你的 venv 文件夹,然后用一个有效的 python 位置重新创建它,然后pip install -r requirements.txt你就全部设置好了(假设你的 requirements.txt 是正确的)。

回答by vsky man

When the first lion of python script is #!/usr/bin/env python,maybe it's /usr/bin/envissue. You can run /usr/bin/envto see if error ,if it runs with error,you can update /usr/bin/env with yum(and so on) install coreutils.

当python脚本的第一个狮子是时#!/usr/bin/env python,也许是/usr/bin/env问题。您可以运行/usr/bin/env以查看是否出错,如果运行出错,则可以使用 yum(等等)安装 coreutils 来更新 /usr/bin/env。

回答by Jesus

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+hif you can't find the folder in your documents, install the software again and should work again.

我的 pycharm ce 有同样的错误,很容易修复它,如果有人有这个错误,只需卸载并删除该文件夹,ctrl+h如果您在文档中找不到该文件夹​​,请使用,再次安装该软件,应该可以再次运行。

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

记得在擦除 pycharm 文件夹之前保存 Scratches 文件夹。

回答by DavidW

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

sudo make altinstall在 Opensuse linux 上使用安装的 Python 时遇到了这个问题。似乎已编译的库已安装在中,/usr/local/lib64但 Python 正在/usr/local/lib.

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

我通过创建一个指向相关目录的动态链接来解决它 /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 libdiras an argument to configure(at the start of the build process) but I haven't tested it that way.

我怀疑最好的做法是将其指定libdirconfigure(在构建过程开始时)的参数,但我还没有以这种方式对其进行测试。