如何解决 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
How can I troubleshoot Python "Could not find platform independent libraries <prefix>"
提问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 --version
I 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/local
on OS X.
试试export PYTHONHOME=/usr/local
。Python 应该安装在/usr/local
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).
通常,Python 在路径prefix/lib
和中查找其库exec_prefix/lib
,其中prefix
和exec_prefix
是配置选项。如果PYTHONHOME
设置了环境变量,则从它继承prefix
和的值exec_prefix
。如果PYTHONHOME
没有设置环境变量,然后prefix
和exec_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 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.
通常,当您收到错误消息时Could not find platform independent libraries <prefix>
,字符串<prefix>
将被替换为 的实际值prefix
。但是,如果prefix
有一个空值,那么您会收到问题中发布的相当神秘的消息。获取空值的一种方法prefix
是设置PYTHONHOME
为空字符串。有关更多信息PYTHONHOME
,prefix
以及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 -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).
如果你创建了一个虚拟环境,然后删除了那个 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/env
issue. You can run /usr/bin/env
to 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+h
if 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 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
.
我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 libdir
as an argument to configure
(at the start of the build process) but I haven't tested it that way.
我怀疑最好的做法是将其指定libdir
为configure
(在构建过程开始时)的参数,但我还没有以这种方式对其进行测试。