Configure Pyflink in Pycharm (failed)

Refer to [1], but the official document is a bit brief, so you still need to digest it.

 

①cd /home/appleyuchi/bigdat

②git clone https://gitee.com/mirrors/apache-flink.git

③Open the following path:

④pip install flake8

⑤Settings->External Tools

The above is the meaning of the official document, so it won't work at all.

----------------------------------------------------------------------------------------------------------------

What about cheating?

----------------------------------------------------------------------------------------------------------------

Right-click and select Mark Directory as->Sources Root

----------------------------------------------------------------------------------------------------------------

python -m pip install apache-flink (also search for this in pycharm)

----------------------------------------------------------------------------------------------------------------

Running code:

from flink.plan.Environment import get_environment
from flink.functions.GroupReduceFunction import GroupReduceFunction


class Adder(GroupReduceFunction):
    def reduce(self, iterator, collector):
        count, word = iterator.next()
        count += sum([x[0] for x in iterator])
        collector.collect((count, word))


# 1. 获取一个运行环境
env = get_environment()
print("------------1--------")
# 2. 加载/创建初始数据
data = env.from_elements("Who's there?",
                         "I think I hear them. Stand, ho! Who's there?")
print("------------2--------")
# 3. 指定对这些数据的操作
# data.flat_map(lambda x, c: [(1, word) for word in x.lower().split()]) \
#     .group_by(1) \
#     .reduce_group(Adder(), combinable=True) \
#     .output()
data.output()
print("------------3--------")
print(data)

# 4. 运行程序
env.execute()  # 设置execute(local=True)强制程序在本机运行

----------------------------------------------------------------------------------------------------------------

Eventually failed because data.output() could not output any results

----------------------------------------------------------------------------------------------------------------

The way to run pyflink from the command line is:

$FLINK_HOME/bin/flink run -py /home/appleyuchi/desktop/experiment/wordcount.py

Reference:

[1]Importing Flink into an IDE

[2] PyCharm builds Spark development environment + the first pyspark program

[3]pycharm not updating with environment variables

Guess you like

Origin blog.csdn.net/appleyuchi/article/details/109049447