Python笔记01-你好Python

本文介绍了Python语言的起源,其特点以及在Linux和Windows环境下的安装步骤,包括下载、依赖安装、源码编译和旧版本替换。还展示了如何在Helloworld示例中使用Python解释器以及推荐的开发工具PyCharm的使用方法。
摘要由CSDN通过智能技术生成

Python简介

python的诞生

1989年,为了打发圣诞节假期,Gudio van Rossum吉多· 范罗苏姆(龟叔)决心开发一个新的解释程序(Python雏形)
1991年,第一个Python解释器诞生 ,Python这个名字,来自龟叔所挚爱的电视剧Monty Python’s Flying Circus

Python特点
优雅、简单、易学、开发效率高、适用范围广
在这里插入图片描述

环境安装

安装文件下载地址:https://www.python.org/downloads

根据需要挑选需要的版本下载
在这里插入图片描述

windows环境安装
下载python安装文件,双击运行 一直下一步直到完成。 这里不赘述
在这里插入图片描述
安装完成 在 windows命令行中执行 python 会进入 python解释器如下
在这里插入图片描述

linunx环境安装
可以看到 centos自带 python2.7,这里进行重新安装

在这里插入图片描述

到官网下载源码,这里有下载好的版本,点击下载

安装依赖

yum install wget zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make zlib zlib-devel libffi-devel -y

上传安装包到服务器
在这里插入图片描述

解压安装包

[root@localhost ~]# tar -vxf Python-3.11.7.tar 
总用量 104184
drwxr-xr-x. 16 1000 1000      4096 12月  5 02:10 Python-3.11.7
-rw-r--r--.  1 root root 100116480 1月   6 17:31 Python-3.11.7.tar
[root@localhost ~]# 

编译安装

[root@localhost Python-3.11.7]# ./configure --prefix=/usr/local/python3.11.7
[root@localhost Python-3.11.7]# make && make install
.......
(cd /usr/local/python3.11.7/bin; ln -s 2to3-3.11 2to3)
if test "x" != "x" ; then \
        rm -f /usr/local/python3.11.7/bin/python3-32; \
        (cd /usr/local/python3.11.7/bin; ln -s python3.11-32 python3-32) \
fi
if test "x" != "x" ; then \
        rm -f /usr/local/python3.11.7/bin/python3-intel64; \
        (cd /usr/local/python3.11.7/bin; ln -s python3.11-intel64 python3-intel64) \
fi
rm -f /usr/local/python3.11.7/share/man/man1/python3.1
(cd /usr/local/python3.11.7/share/man/man1; ln -s python3.11.1 python3.1)
if test "xupgrade" != "xno"  ; then \
        case upgrade in \
                upgrade) ensurepip="--upgrade" ;; \
                install|*) ensurepip="" ;; \
        esac; \
         ./python -E -m ensurepip \
                $ensurepip --root=/ ; \
fi
Looking in links: /tmp/tmpn7i621cm
Processing /tmp/tmpn7i621cm/setuptools-65.5.0-py3-none-any.whl
Processing /tmp/tmpn7i621cm/pip-23.2.1-py3-none-any.whl
Installing collected packages: setuptools, pip
  WARNING: The scripts pip3 and pip3.11 are installed in '/usr/local/python3.11.7/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed pip-23.2.1 setuptools-65.5.0
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv

替换旧版本

删除掉/usr/bin/python 文件 并将新版本文件挂在到该为止

[root@localhost Python-3.11.7]# rm  -rf /usr/bin/python
[root@localhost Python-3.11.7]# ln -s /usr/local/python3.11.7/bin/python3.11 /usr/bin/python
[root@localhost Python-3.11.7]# python
Python 3.11.7 (main, Jan  6 2024, 17:47:32) [GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux
Type "help", "copyright", "credits" or "license" for more information.

创建软链接后,会破坏yum程序的正常使用(只能使用系统自带的python2)
修改如下文件,将第一行 由 #!/usr/bin/python 修改为 #!/usr/bin/python2

/usr/bin/yum
/usr/libexec/urlgrabber-ext-down

在这里插入图片描述
执行 python 命令可以进入 解释器 如下
在这里插入图片描述

Hello world

解释器可以直接执行python代码,如下打印helloworld

[root@localhost Python-3.11.7]# python
Python 3.11.7 (main, Jan  6 2024, 17:47:32) [GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> print ("hello world!")
hello world!
>>> 

也可以一次些多行代码 进行执行,也可以执行 文件中的代码
编辑test.py内容如下

[root@localhost ~]# vi test.py
print("hello world")
print("i love the world")

执行结果如下:

[root@localhost Python-3.11.7]# python ~/test.py
hello world
i love the world

开发工具

Python程序的开发有许多种方式,一般我们常见的有:
Python解释器环境内,执行单行代码
使用Python解释器程序,执行Python代码文件
使用第三方IDE(集成开发工具),如PyCharm软件,开发Python程序
下载安装文件 并双击运行 (社区版免费 这里使用社区版),直接默认下一步就行
点击下载
在这里插入图片描述
安装成功 后打开软件啊如下

在这里插入图片描述

点击上图 New Project 按钮创建工程

在这里插入图片描述
创建文件,编写代码 并执行
在这里插入图片描述

  • 20
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

catch that elf

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值