# 运行spark

控制台输入pyspark进入

```python
# 查看运行模式
>>> sc.master
'local[*]'

# 读取本地文件，如果有hdfs服务器，还可以设置为(hdfs://master:9000/user/xxx/xx.txt)
>>> textfile=sc.textFile('file:/Users/jiang/Documents/spark/study/README.md')

# 查看文件行数
>>> textfile.count()
17
```

ps:spark可以运行在hadoop YARN，此时sc.master就是部署的机器了

spark/conf/spark-env.sh可以配置spark环境

## notebook 运行spark

> 注意：需要先启动了spark

把**pyspark包放到pytho环境的site-packege**下，这样可以直接用

我的直接放conda的python3.7环境下

![](/files/-LqgNnRNWvbO2VhCuNf0)

然后就可以直接导入了：

![](/files/-LoyKMmdp9Q1fSd0k6O_)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://im-qianuxn.gitbook.io/pytorch/ji-suan-ji/spark-hadoop/yun-xing.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
