pydoop错误:runtimeerror:java home not found,请尝试使用cdh5.4在远程服务器上设置java\u home

zysjyyx4  于 2021-06-03  发布在  Hadoop
关注(0)|答案(2)|浏览(448)

目标:使用pydoop从我的笔记本电脑读取存储在hdfs中的远程文件。我用的是pycharm专业版。我用的是cloudera cdh5.4
我的笔记本电脑上的pycharm配置:在项目解释器(在设置下)中,我已经指示python编译器在远程服务器上作为ssh://remote-server-ip-address:端口号/home/ashish/anaconda/bin/python2.7
现在有一个文件存储在hdfs location/home/ashish/pencil/somefilename.txt中
然后使用pip install pydoop及其installed在远程服务器上安装pydoop。然后我编写这个代码从hdfs位置读取文件

import pydoop.hdfs as hdfs
with hdfs.open('/home/ashish/pencil/someFileName.txt') as file:

for line in file:
    print(line,'\n')

在执行时我得到了错误

Traceback (most recent call last):
File "/home/ashish/PyCharm_proj/Remote_Server_connect/hdfsConxn.py", line 7,  in <module>
import pydoop.hdfs as hdfs
File /home/ashish/anaconda/lib/python2.7/sitepackages/pydoop/hdfs/__init__.py", line  82, in <module>
from . import common, path
File "/home/ashish/anaconda/lib/python2.7/site-packages/pydoop/hdfs/path.py", line 28, in <module>
from . import common, fs as hdfs_fs
File "/home/ashish/anaconda/lib/python2.7/site-packages/pydoop/hdfs/fs.py", line 34, in <module>
from .core import core_hdfs_fs
File "/home/ashish/anaconda/lib/python2.7/site-packages/pydoop/hdfs/core/__init__.py", line 49, in <module>
_CORE_MODULE = init(backend=HDFS_CORE_IMPL)
File "/home/ashish/anaconda/lib/python2.7/site-packages/pydoop/hdfs/core/__init__.py", line 29, in init
jvm.load_jvm_lib()
File "/home/ashish/anaconda/lib/python2.7/site- packages/pydoop/utils/jvm.py", line 33, in load_jvm_lib
java_home = get_java_home()
File "/home/ashish/anaconda/lib/python2.7/site-packages/pydoop/utils/jvm.py", line 28, in get_java_home
raise RuntimeError("java home not found, try setting JAVA_HOME")
RuntimeError: java home not found, try setting JAVA_HOME

Process finished with exit code 1

我猜也许它找不到py4j。py4j的位置是

/home/ashish/anaconda/lib/python2.7/site-packages/py4j

当我在远程服务器上回显java home时,

echo $JAVA_HOME

我知道这个位置,

/usr/java/jdk1.7.0_67-cloudera

我对python编程和centos设置都是新手,请建议我能做些什么来解决这个问题?
谢谢

klsxnrf1

klsxnrf11#

你可以通过设置 JAVA_HOMEhadoop-env.sh (默认为注解)。
更改:


# The java implementation to use.  Required.

# export JAVA_HOME=/usr/lib/j2sdk1.5-sun

收件人:


# The java implementation to use.  Required.

export JAVA_HOME=/usr/java/jdk1.7.0_67-cloudera

或者不管你的java安装目录是什么。

vaqhlq81

vaqhlq812#

看来我解决了。我所做的就是利用

sys.path.append('/usr/java/jdk1.7.0_67-cloudera')

我更新了密码

import os, sys
sys.path.append('/usr/java/jdk1.7.0_67-cloudera')
input_file = '/home/ashish/pencil/someData.txt'
with open(input_file) as f:
   for line in f:
       print line

这段代码从远程服务器的hdfs读取一个文件,然后在我笔记本电脑上的pycharm控制台中打印输出。
通过使用sys.path.append(),您不必手动更改hadoop.sh文件并导致与其他java配置文件冲突。

相关问题