簡體   English   中英

從構建文件夾移出時,靜態構建的python3.7停止工作

[英]statically built python3.7 stops working when moved out of build folder

我想使用靜態python解釋器在嚴格管理的服務器上運行。 到目前為止,我已經構建了解釋器,但是我只能在build目錄中使用它。

如果我嘗試復制並使用該副本,它將停止工作,並因以下錯誤而失敗-

Could not find platform independent libraries <prefix>
Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]
Fatal Python error: initfsencoding: Unable to get the locale encoding
ModuleNotFoundError: No module named 'encodings'

Current thread 0x0000000002812900 (most recent call first):
zsh: abort (core dumped)  ./../python

我已經看到了這個問題 ,並且使用第一個答案中建議的修復方法擺脫了前綴和exec_prefix問題,但沒有解決“無法獲取語言環境編碼”問題。 我真的找不到與此相關的解決方案。

順便說一下,這與virtualenv無關,當我在任何virtualenvs之外嘗試它時, echo $PYTHONPATHecho $PYTHONHOME都返回一個空字符串。 當靜態二進制文件在構建目錄中時,我可以很好地運行它。

這是一個例子

~/Python-3.7.2$ ./python
Python 3.7.2 (default, Jan 26 2019, 19:14:39) 
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 
~/Python-3.7.2$ cp python ..
~/Python-3.7.2$ ./../python 
Could not find platform independent libraries <prefix>
Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]
Fatal Python error: initfsencoding: Unable to get the locale encoding
ModuleNotFoundError: No module named 'encodings'

Current thread 0x0000000002812900 (most recent call first):
zsh: abort (core dumped)  ./../python

~/Python-3.7.2$ export PYTHONHOME=/usr/local
~/Python-3.7.2$ ./../python                 
Fatal Python error: initfsencoding: Unable to get the locale encoding
ModuleNotFoundError: No module named 'encodings'

Current thread 0x00000000011b1900 (most recent call first):
zsh: abort (core dumped)  ./../python

好的,我已經解決了我的問題。 這是由於在configure設置--prefix選項引起的。 如果在運行時未指定正確的前綴,則python將不知道其標准庫在哪里。

要從任何地方使用python二進制文件,應手動指定PYTHONHOMEPYTHONPATH環境變量,或將二進制文件保存在運行configure時指定的目錄中。

例如,如果您使用--prefix=/home/blah/python_src進行配置,則在使用它之前,必須將在此生成的二進制文件保留在其中或執行export PYTHONHOME=/home/blah/python_src之類的操作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM