码迷,mamicode.com
首页 > 编程语言 > 详细

python学习笔记----01、Python的安装

时间:2017-07-04 16:11:02      阅读:134      评论:0      收藏:0      [点我收藏+]

标签:运行   license   bsp   edit   文件   contain   右键   ice   python脚本   

Python安装

windows

1
2
3
4
5
6
7
1、下载安装包
    https://www.python.org/downloads/
2、安装
    默认安装路径:C:\python27
3、配置环境变量
    【右键计算机】--》【属性】--》【高级系统设置】--》【高级】--》【环境变量】--》【在第二个内容框中找到 变量名为Path 的一行,双击】 --> 【Python安装目录追加到变值值中,用 ; 分割】
    如:原来的值;C:\python27,切记前面有分号

linux、Mac

1
2
3
无需安装,原装Python环境
  
ps:如果自带2.6,请更新至2.7

  

五、Hello World程序

在linux 下创建一个文件叫hello.py,并输入

1
print("Hello World!")

然后执行命令:python hello.py ,输出

1
2
3
localhost:~ lei$ vim hello.py
localhost:~ lei$ python hello.py
Hello World!

指定解释器

上一步中执行 python hello.py 时,明确的指出 hello.py 脚本由 python 解释器来执行。

如果想要类似于执行shell脚本一样执行python脚本,例: ./hello.py ,那么就需要在 hello.py 文件的头部指定解释器,如下:

1
2
3
#!/usr/bin/env python
  
print "hello,world"

如此一来,执行: ./hello.py 即可。

ps:执行前需给予 hello.py 执行权限,chmod 755 hello.py

在交互器中执行 

除了把程序写在文件里,还可以直接调用python自带的交互器运行代码, 

1
2
3
4
5
6
localhost:~ lei$ python
Python 2.7.10 (default, Oct 23 201518:05:06)
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin
Type "help""copyright""credits" or "license" for more information.
>>> print("Hello World!")
Hello World!

python学习笔记----01、Python的安装

标签:运行   license   bsp   edit   文件   contain   右键   ice   python脚本   

原文地址:http://www.cnblogs.com/plpc/p/7116922.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!