linux离线移植python环境,启动报错(ModuleNotFoundError: No module named ‘encodings‘;<no Python frame>)

26 篇文章 0 订阅
10 篇文章 0 订阅

一、背景

因为项目原因,需要在linux安装python环境做开发。但是客户机器不能联网,考虑离线安装,在离线安装过程也是出现了一些错误,于是就有了这篇文章(多么希望没有)。

离线移植python环境到服务器(我这里是直接拷贝anaconda3文件夹移植)

二、移植步骤

1)将anaconda3放到root目录后,配置如下环境变量:

echo 'export PATH="~/anaconda3/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc

2)然后查看conda版本,显示如下:

conda 4.10.1

3)接着查看python版本,如下:

python 3.8.8

4)到这里我天真的以为已经ok了,让我万万没想到的是在python xxx.py的时候报错了,就是标题的那个错误。完整的报错信息我贴到下面:

Could not find platform independent libraries <prefix>
Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]
Python path configuration:
PYTHONHOME = (no set)
PYTHONPATH = (no set)
program name = 'python'
isolated = 0
environment = 1
user site = 1
import site = 1
sys._base_executable = '/usr/bin/python'
sys.base_prefix = '/tmp/'
sys.base_exec_prefix = ''/tmp/'
sys.executable = ''/tmp/'
sys.prefix = ''/tmp/'
sys.exec_prefix = ''/tmp/'
sys.path = [
''/tmp/',
''/tmp/',
]
Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding
Python runtime state: core initialized
ModuleNotFoundError: No module named 'encodings'

Current thread 0x00007fab36715740 (most recent call first):
<no Python frame>

三、解决方法

于是我就上网搜,大多的解决方法都是修改环境变量以及下载那个encodings的包,不过因为网络也没有尝试这种方法。

不过呢,解决方法还是从环境变量入手。查看其他机器上的环境变量配置后,我就把正常的机器的环境变量拷到出错的机器上。可真是不试不知道,一试吓一跳。再次运行python xxx.py后就没有之前的报错了。环境变量配置如下:(把内容复制到~/.bashrc即可。)

# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/root/anaconda3/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
    eval "$__conda_setup"
else
    if [-f "/root/anaconda3/etc/profile.d/conda.sh" ]; then
        . "/root/anacnda3/etc/profile.d/conda.sh"
    else
        export PATH="/root/anaconda3/bin:$PATH"
    fin
fin
unset __conda_setup
# <<< conda initialize <<<

ps:看不懂shell,有没有大佬来解释下这段配置起到了啥作用???

四、总结

总之在离线移植或者安装,是有很多注意事项的。尤其是像我这种直接拷贝文件夹移植的。可能你移植的包里有些文件配置是指向原机器特定目录,在移植过去就会出现各种问题。总之多注意、多总结。

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值