Linux系统部署Python语言开发运行环境

news2024/9/25 11:17:40

目录

Ubuntu自带python

Debian安装python

安装 pip

库列表

安装第三方库

使用国内镜像站

实装 tkinter 库

编写运行代码

测试代码1 

1. 创建项目

2. 创建源码文件

3. 写入源代码

4. 修改权限 

5. 运行代码

测试代码2


本文的使用环境是Windows的Linux 子系统,详见:Windows 使用 Linux 子系统-CSDN

Ubuntu自带python

20.04版本中包含了Python3.8.10,但不包含pip安装工具。

hann@HannYang:~$ python

Command 'python' not found, did you mean:

  command 'python3' from deb python3
  command 'python' from deb python-is-python3

hann@HannYang:~$ python3
Python 3.8.10 (default, May 26 2023, 14:05:08)
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>

Debian安装python

不所有linux都自带python,比如Debian就不带python,需要自己安装。

安装命令:$ sudo apt-get install python3

hann@HannYang:~$ sudo apt-get install python3
[sudo] password for hann:
Reading package lists... Done
Building dependency tree... Done
The following additional packages will be installed:
  ca-certificates libexpat1 libnsl2 libpython3-stdlib libpython3.11-minimal libpython3.11-stdlib libsqlite3-0
  media-types openssl python3-minimal python3.11 python3.11-minimal
Suggested packages:
  python3-doc python3-tk python3-venv python3.11-venv python3.11-doc binutils binfmt-support
The following NEW packages will be installed:
  ca-certificates libexpat1 libnsl2 libpython3-stdlib libpython3.11-minimal libpython3.11-stdlib libsqlite3-0
  media-types openssl python3 python3-minimal python3.11 python3.11-minimal
0 upgraded, 13 newly installed, 0 to remove and 0 not upgraded.
Need to get 7,879 kB of archives.
After this operation, 26.7 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 http://deb.debian.org/debian bookworm/main amd64 libpython3.11-minimal amd64 3.11.2-6 [813 kB]
Get:2 http://deb.debian.org/debian bookworm/main amd64 libexpat1 amd64 2.5.0-1 [99.3 kB]
Get:3 ......

......略......
Updating certificates in /etc/ssl/certs...
0 added, 0 removed; done.
Running hooks in /etc/ca-certificates/update.d...
done.
hann@HannYang:~$ python3
Python 3.11.2 (main, Mar 13 2023, 12:18:29) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 

安装 pip

安装命令: $ sudo apt install python3-pip

hann@HannYang:~$ sudo apt install python3-pip
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
  binutils binutils-common binutils-x86-64-linux-gnu build-essential dpkg-dev fakeroot g++ g++-9 gcc gcc-9
...... 略 ......
After this operation, 199 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 binutils-x86-64-linux-gnu amd64 2.34-6ubuntu1.6 [1613 kB]
Get:2 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 binutils amd64 2.34-6ubuntu1.6 [3376 B]
Get:3 ...

...... 略 ......
Setting up python3-dev (3.8.2-0ubuntu2) ...
Processing triggers for man-db (2.9.1-1) ...
Processing triggers for libc-bin (2.31-0ubuntu9.9) ...

库列表

列表命令: $ pip list

hann@HannYang:~$ pip list
Package                Version
---------------------- --------------------
attrs                  19.3.0
Automat                0.8.0
blinker                1.4
certifi                2019.11.28
chardet                3.0.4
Click                  7.0
cloud-init             23.2.1
colorama               0.4.3
command-not-found      0.3
configobj              5.0.6
constantly             15.1.0
cryptography           2.8
cupshelpers            1.0
dbus-python            1.2.16
defer                  1.0.6
distro                 1.4.0
distro-info            0.23ubuntu1
entrypoints            0.3
httplib2               0.14.0
hyperlink              19.0.0
idna                   2.8
importlib-metadata     1.5.0
incremental            16.10.1
Jinja2                 2.10.1
jsonpatch              1.22
jsonpointer            2.0
jsonschema             3.2.0
keyring                18.0.1
language-selector      0.1
launchpadlib           1.10.13
lazr.restfulclient     0.14.2
lazr.uri               1.0.3
macaroonbakery         1.3.1
MarkupSafe             1.1.0
more-itertools         4.2.0
netifaces              0.10.4
oauthlib               3.1.0
pexpect                4.6.0
pip                    20.0.2
protobuf               3.6.1
psutil                 5.5.1
pyasn1                 0.4.2
pyasn1-modules         0.2.1
pycairo                1.16.2
pycups                 1.9.73
PyGObject              3.36.0
PyHamcrest             1.9.0
PyJWT                  1.7.1
pymacaroons            0.13.0
PyNaCl                 1.3.0
pyOpenSSL              19.0.0
pyRFC3339              1.1
pyrsistent             0.15.5
pyserial               3.4
python-apt             2.0.1+ubuntu0.20.4.1
python-debian          0.1.36+ubuntu1.1
pytz                   2019.3
pyxdg                  0.26
PyYAML                 5.3.1
requests               2.22.0
requests-unixsocket    0.2.0
SecretStorage          2.3.1
service-identity       18.1.0
setuptools             45.2.0
simplejson             3.16.0
six                    1.14.0
sos                    4.4
ssh-import-id          5.10
systemd-python         234
Twisted                18.9.0
ubuntu-advantage-tools 8001
ufw                    0.36
unattended-upgrades    0.1
urllib3                1.25.8
wadllib                1.3.3
wheel                  0.34.2
zipp                   1.0.0
zope.interface         4.7.1

安装第三方库

安装命令: $ pip install numpy

hann@HannYang:~$ pip install numpy
Collecting numpy
  Downloading numpy-1.24.4-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (17.3 MB)
     |████████████████████████████████| 17.3 MB 39 kB/s
Installing collected packages: numpy
Successfully installed numpy-1.24.4

国外服务下载速度极慢,速度显示在30到300 kB/s之间跳动。

使用国内镜像站

比如使用清华镜像,秒装:

$ pip install numpy -i https://pypi.tuna.tsinghua.edu.cn/simple

实装 tkinter 库

不像windows版本的python3已自带tkinter库,ubantu python3需要自己安装。

安装命令:$ sudo apt-get install python-tk

编写运行代码

测试代码1 

1. 创建项目

比如在根目录下建一个python子目录

hann@HannYang:~$ mkdir python
hann@HannYang:~$ cd python

2. 创建源码文件

比如test.py

hann@HannYang:~/python$ touch test.py
hann@HannYang:~/python$ ll
total 8
drwxr-xr-x  2 hann hann 4096 Aug  5 13:40 ./
drwxr-xr-x 22 hann hann 4096 Aug  5 13:38 ../
-rw-r--r--  1 hann hann    0 Aug  5 13:40 test.py

3. 写入源代码

注意:一定要在首行标记解释程序的所在位置 #!/usr/bin/python3

hann@HannYang:~/python$ echo "#!/usr/bin/python3" > test.py
hann@HannYang:~/python$ echo "print('Hello, python')" >> test.py
hann@HannYang:~/python$ more ./test.py
#!/usr/bin/python3
print('Hello, python')
hann@HannYang:~/python$ ll
total 12
drwxr-xr-x  2 hann hann 4096 Aug  5 13:40 ./
drwxr-xr-x 22 hann hann 4096 Aug  5 13:38 ../
-rw-r--r--  1 hann hann   43 Aug  5 13:42 test.py

4. 修改权限 

把默认的文件权限-rw-r--r--修改为-rwxr-xr-x

hann@HannYang:~/python$ chmod +x test.py
hann@HannYang:~/python$ ll
total 12
drwxr-xr-x  2 hann hann 4096 Aug  5 13:40 ./
drwxr-xr-x 22 hann hann 4096 Aug  5 13:38 ../
-rwxr-xr-x  1 hann hann   43 Aug  5 13:42 test.py*

5. 运行代码

hann@HannYang:~/python$ ./test.py
Hello, python

测试代码2

再找一个稍微复杂点进行测试,如对链表进行插入排序:

9400029b6559a5f16c48610324ceb961.gif

插入排序的动画演示如上。从第一个元素开始,该链表可以被认为已经部分排序(用黑色表示)。
每次迭代时,从输入数据中移除一个元素(用红色表示),并原地将其插入到已排好序的链表中。

插入排序算法:

插入排序是迭代的,每次只移动一个元素,直到所有元素可以形成一个有序的输出列表。
每次迭代中,插入排序只从输入数据中移除一个待排序的元素,找到它在序列中适当的位置,并将其插入。
重复直到所有输入数据插入完为止。

示例 1:

输入: 4->2->1->3
输出: 1->2->3->4

示例 2:

输入: -1->5->3->4->0
输出: -1->0->3->4->5

操作过程: 

hann@HannYang:~/python$ touch test2.py
hann@HannYang:~/python$ chmod +x test2.py
hann@HannYang:~/python$ vi test2.py
hann@HannYang:~/python$ ./test2.py
4->2->1->3->nill
1->2->3->4->nill
-1->5->3->4->0->nill
-1->0->3->4->5->nill

其中,用 vi 编辑test2.py时,直接复制粘贴以下代码:

#!/usr/bin/python3

class ListNode:
    def __init__(self, val=0, next=None):
        self.val = val
        self.next = next
 
def insertionSortList(head: ListNode) -> ListNode:
    dummy = ListNode(float('-inf'), head)
    tail = dummy
    cur = head
    while cur:
        if tail.val <= cur.val:
            # 若链表尾节点值小于等于当前节点,不需要移动
            tail.next = cur
            tail = cur
            cur = cur.next
        else:
            # 在已排序部分找到插入位置
            prev = dummy
            while prev.next.val < cur.val:
                prev = prev.next
            # 插入节点
            tail.next = cur.next
            cur.next = prev.next
            prev.next = cur
            cur = tail.next
    return dummy.next
 
def createList(lst):
    head = ListNode(lst[0])
    p = head
    for i in lst[1:]:
        node = ListNode(i)
        p.next = node
        p = p.next
    return head
 
def traversalList(head):
    while head:
        print(head.val, end="->")
        head = head.next
    print("nill")
 
#%%
lst1 = [4, 2, 1, 3]
lst2 = [-1, 5, 3, 4, 0]
 
head1 = createList(lst1)
traversalList(head1)
sorted_head1 = insertionSortList(head1)
traversalList(sorted_head1)
 
head2 = createList(lst2)
traversalList(head2)
sorted_head2 = insertionSortList(head2)
traversalList(sorted_head2)

exit

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/838870.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

Opencv-C++笔记 (14) : 霍夫变换(直线、圆)

文章目录 一、霍夫变换-直线1.1霍夫变换-直线 原理详解 二、霍夫圆检测 一、霍夫变换-直线 Hough Line Transform用来做直线检测 前提条件 – 边缘检测已经完成 1、平面空间&#xff08;x,y&#xff09;到极坐标空间转换&#xff1b; 2、对极坐标进行变换&#xff0c;转化为…

作为软件工程师成为全职创作者:有争议的建议

我以写作为生&#xff0c;全职。我的通讯是Substack上排名第一的付费技术通讯&#xff0c;我是一个全职的创作者。 随着远程工作在科技领域变得越来越普遍&#xff0c;我收到越来越多的人发来同样的问题&#xff1a;他们怎么能像我一样&#xff1f; 尽管我被认为是一个成功的…

Linux 匿名页的生命周期

目录 匿名页的生成 匿名页生成时的状态 do_anonymous_page缺页中断源码 从匿名页加入Inactive lru引出 一个非常重要内核patch 匿名页何时回收 本文以Linux5.9源码讲述 匿名页的生成 用户空间malloc/mmap(非映射文件时&#xff09;来分配内存&#xff0c;在内核空间发生…

NodeJS原型链污染ctfshow_nodejs

文章目录 NodeJS原型链污染&ctfshow_nodejs前言0x01.原型与原型链0x02.prototype和__proto__分别是什么&#xff1f;0x03.原型链继承不同对象的原型链* 0x04.原型链污染原理0x05.merge()导致原型链污染0x06.ejs模板引擎RCEejs模板引擎另一处rce 0x07.jade模板引擎RCE【ctfs…

HCIP——STP

STP 一、STP概述二、二层环路带来的问题1、广播风暴问题2、MAC地址漂移问题3、多帧复制 三、802.1D生成树STP的BPDU1、配置BPDU2、RPC3、COST4、配置BPDU的工作过程5、TCN BPDU6、TCN BPDU的工作原理 四、STP的角色五、STP角色选举六、STP的接口状态七、接口状态的迁移八、STP的…

web集群学习:源码安装nginx配置启动服务脚本

1、源码安装nginx&#xff0c;并提供服务脚本。 1、源码安装会有一些软件依赖 &#xff08;1&#xff09;检查并安装 Nginx 基础依赖包 pcre-devel 、openssl-devel # rpm -qa | egrep pcre-devel | openssl-devel&#xff08;2&#xff09;安装 Nginx 所需的 pcre 库 正则支…

STM32入门学习之定时器中断

1.STM32的通用定时器是可编程预分频驱动的16位自动装载计数器。 STM32 的通用定时器可以被用于&#xff1a;测量输入信号的脉冲长度 ( 输入捕获 ) 或者产生输出波 形 ( 输出比较和 PWM) 等。 使用定时器预分频器和 RCC 时钟控制器预分频器&#xff0c;脉冲长度和波形 周…

分治法、回溯法与动态规划

算法思想比较 回溯法&#xff1a;有“通用解题法”之称&#xff0c;用它可以系统地搜索问题的所有解。回溯法是按照深度优先搜索(DFS)的策略&#xff0c;从根结点出发深度探索解空间树分治法&#xff1a;将一个难以直接解决的大问题&#xff0c;分割成一些规模较小的相同问题&…

PCIE链路信息

目录 简介&#xff1a; 目的&#xff1a; 详情&#xff1a; 简介&#xff1a; PCIe有很多寄存器&#xff0c;也有很多控制&#xff0c;包括链路状态信息&#xff0c;上一节我们讲到了PCie的链路训练&#xff0c;这节文章将继续学习PCIe相关知识。 目的&#xff1a; 从设计…

30岁程序员第一次失败的餐饮创业经历

背景介绍 我什么都比较晚&#xff0c;我比大多数人晚了两年毕业&#xff0c;事业稳定也比别人晚。直到去年&#xff0c;我才跳槽到一家外企外包工作获得相对满意的薪资。但即使如此&#xff0c;与更有经验的人相比&#xff0c;我仍然有很大的差距&#xff0c;自己也尚未积累足…

kubernetes集群日志管理系统部署方案

安装前请下载各种所需yaml文件 1、安装 elasticsearch 组件 1.1 创建名称空间 #elasticsearch、fluentd、kibana都会安装到此空间下 kubectl apply -f kube-logging.yaml1.2 查看 kube-logging 名称空间是否创建成功 kubectl get namespaces | grep kube-logging[rootk8s-…

一分钟学会JS获取当前年近五年的年份

先看效果图 上代码&#xff1a; 1、HTML <div><el-date-pickerv-model"queryYearXmgk.startYear"format"yyyy"value-format"yyyy"type"year"placeholder"开始"clearable:picker-options"pickerStartAuditYe…

EventBus 开源库学习(三)

源码细节阅读 上一节根据EventBus的使用流程把实现源码大体梳理了一遍&#xff0c;因为精力有限&#xff0c;所以看源码都是根据实现过程把基本流程看下&#xff0c;中间实现细节先忽略&#xff0c;否则越看越深不容易把握大体思路&#xff0c;这节把一些细节的部分再看看。 …

flutter开发实战-flutter_spinkit实现多种风格进度指示器

flutter开发实战-flutter_spinkit实现多种风格进度指示器 最近开发过程中flutter_spinkit&#xff0c;这个拥有多种种风格加载指示器 一、flutter_spinkit 引入flutter_spinkit # 多种风格的模糊进度指示器flutter_spinkit: ^5.1.0效果示例 const spinkit SpinKitRotatingC…

常见历史漏洞之Thinkphp

常见历史漏洞之Thinkphp 一、介绍二、Thinkphp历史漏洞三、Thinkphp特征发现四、批量漏洞检测五、漏洞总结六、5.0.23版本案例演示 一、介绍 Thinkphp是一种开源框架。是一个由国人开发的支持windows/Unix/Linux等服务器环境的轻量级PHP开发框架。很多cms就是基于thinkphp二次开…

动态规划01: 斐波那契数列模型

第 N 个泰波那契数&#xff08;easy&#xff09; 题目链接: 1137. 第 N 个泰波那契数 题目描述: 泰波那契序列 Tn 定义如下&#xff1a; T0 0, T1 1, T2 1, 且在 n > 0 的条件下 Tn3 Tn Tn1 Tn2 给你整数 n&#xff0c;请返回第 n 个泰波那契数 Tn 的值。 示例 1&…

Vue表格导出Excel数据,自定义表头,使用xlsx-style修饰

继续上篇文章封装导出方法: 效果图&#xff1a; 1、安装xlsx-style依赖&#xff1a; yarn add xlsx-style 2、安装node-polyfill-webpack-plugin依赖&#xff1a; yarn add node-polyfill-webpack-plugin -D 解决报错&#xff1a;jszip is not a constructor 3、配置vue.…

Cilium系列-13-启用XDP加速及Cilium性能调优总结

系列文章 Cilium 系列文章 前言 将 Kubernetes 的 CNI 从其他组件切换为 Cilium, 已经可以有效地提升网络的性能. 但是通过对 Cilium 不同模式的切换/功能的启用, 可以进一步提升 Cilium 的网络性能. 具体调优项包括不限于: 启用本地路由(Native Routing)完全替换 KubeProx…

广西茶叶元宇宙 武隆以茶为媒 推动茶文旅产业融合发展

8月4日&#xff0c;重庆市武隆区启动为期3天的“武隆首届玩茶荟”。本次活动以“中国最美玩茶地——武隆”为主题&#xff0c;吸引众多国内知名专家、茶企和茶馆相关负责人&#xff0c;共同探索武隆茶文旅融合发展新路径和新业态。 广西茶叶元宇宙&#xff1a;广西茶叶元宇宙 …

GD32F103的EXTI中断和EXTI事件

GD32F103的EXTI可以产生中断&#xff0c;也产生事件信号。 GD32F03的EXTI触发源: 1、I/O管脚的16根线&#xff1b; 2、内部模块的4根线(包括LVD、RTC闹钟、USB唤醒、以太网唤醒)。 通过配置GPIO模块的AFIO_EXTISSx寄存器&#xff0c;所有的GPIO管脚都可以被选作EXTI的触发源…