首页 > 代码库 > Python学习(一)

Python学习(一)

Python学习(一)

一:开发工具安装

  1,pycharm下载:Linux版本

  2,破解:在help-register下-service输入:

     http://elporfirio.com:1017/或  http://idea.imsxm.com/ 

                技术分享

二:常用插件下载及安装:

  1,下载安装pip   

wget https://bootstrap.pypa.io/get-pip.py  --no-check-certificate
sudo python get-pip.py

  2,下载安装setuptools

wget https://bootstrap.pypa.io/ez_setup.py -O - | sudo python
sudo apt-get install python-setuptools

  3,安装networkx和numpy和matplotlib

sudo pip install networkx 
sudo apt-get install python-numpy python-scipy python-matplotlib ipython ipython-notebook python-pandas python-sympy python-nose

  4,安装py4j,由于后面要用spark

sudo pip install py4j

  5,pyCharm配置spark

   打开PyCharm,创建一个Project。 然后选择“Run” ->“Edit Configurations” ->“Environment variables” 增加SPARK_HOME目录与PYTHONPATH目录。 - SPARK_HOME:Spark安装目录 - PYTHONPATH:Spark安装目录下的Python目录 

  6,两个例子

from pyspark import SparkContext
sc = SparkContext("local", "test")
rdd = sc.parallelize([1, 2, 3, 4])
print "rdd.collect():%s", str(rdd.collect())
import networkx as nx
import matplotlib.pyplot as plt
def draw_graph(graph):
    # extract nodes from graph
    nodes = set([n1 for n1, n2 in graph] + [n2 for n1, n2 in graph])
    # create networkx graph
    G=nx.Graph()
    # add nodes
    for node in nodes:
        G.add_node(node)
    # add edges
    for edge in graph:
        G.add_edge(edge[0], edge[1])
    # draw graph
    pos = nx.shell_layout(G)
    nx.draw(G, pos)
    # show graph
    plt.show()
# draw example
graph = [(20, 21),(21, 22),(22, 23), (23, 24),(24, 25), (25, 20)]
draw_graph(graph)

三,参考网址:

  使用PyCharm配置Spark的Python开发环境(基础)

  pyCharm最新2017激活码

   ubuntu 下NetworkX,matplotlib的安装和使用

Python学习(一)