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

目录

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/python3class ListNode:def __init__(self, val=0, next=None):self.val = valself.next = nextdef insertionSortList(head: ListNode) -> ListNode:dummy = ListNode(float('-inf'), head)tail = dummycur = headwhile cur:if tail.val <= cur.val:# 若链表尾节点值小于等于当前节点,不需要移动tail.next = curtail = curcur = cur.nextelse:# 在已排序部分找到插入位置prev = dummywhile prev.next.val < cur.val:prev = prev.next# 插入节点tail.next = cur.nextcur.next = prev.nextprev.next = curcur = tail.nextreturn dummy.nextdef createList(lst):head = ListNode(lst[0])p = headfor i in lst[1:]:node = ListNode(i)p.next = nodep = p.nextreturn headdef traversalList(head):while head:print(head.val, end="->")head = head.nextprint("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.mzph.cn/news/24177.shtml

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

相关文章

ChatGPT: 人机交互的未来

ChatGPT: 人机交互的未来 ChatGPT背景ChatGPT的特点ChatGPT的应用场景结论 ChatGPT ChatGPT是一种基于大数据和机器学习的人工智能聊天机器人模型。它由国内团队发明、开发&#xff0c;并被命名为Mental AI。ChatGPT的目标是通过模拟自然对话的方式&#xff0c;提供高效、智能…

Go学习第六天

Golang变量内置pair结构详细说明 变量包括&#xff08;type, value&#xff09;两部分type 包括 static type和concrete type. 简单来说 static type是你在编码是看见的类型(如int、string)&#xff0c;concrete type是runtime系统看见的类型类型断言能否成功&#xff0c;取决…

原型模式(C++)

定义 使用原型实例指定创建对象的种类&#xff0c;然后通过拷贝这些原型来创建新的对象。 应用场景 在软件系统中&#xff0c;经常面临着“某些结构复杂的对象”的创建工作;由于需求的变化&#xff0c;这些对象经常面临着剧烈的变化&#xff0c;但是它们却拥有比较稳定一致的…

Julia 元编程

Julia 把自己的代码表示为语言中的数据结构&#xff0c;这样我们就可以编写操纵程序的程序。 元编程也可以简单理解为编写可以生成代码的代码。 元编程&#xff08;英语&#xff1a;Metaprogramming&#xff09;&#xff0c;是指某类计算机程序的编写&#xff0c;这类计算机程…

Linux磁盘管理

磁盘管理 基本分区管理 磁盘划分思路 进入分区表&#xff0c;新建分区更新分区表格式化分区表挂载使用 #lsblk #df -h 查看设备挂载情况 #fdisk -l 设备分区情况 #fdisk /dev/sdb 添加一块硬盘&#xff0c;需要将其分两个分区&#xff0c;分别格式化成ext4和vfat格式文件系…

Shell脚本学习-for循环结构2

案例&#xff1a;通过脚本实现仅sshd、rsyslog、crond、network、sysstat服务在开机时自启动。 Linux系统在开机的服务通常工作在文本模式3级别&#xff0c;因此只需要查找3级别以上的开启的服务即可。查看命令&#xff1a; chkconfig --list |grep 3:on [rootvm1 ~]# chkco…

安卓camera1设置自动连续对焦

需求 camera 1实现的控制摄像头拍照功能&#xff0e; adb控制自动拍照&#xff0c;发现近点时拍照很模糊&#xff0c;需要自动连续对焦&#xff0e; mCamera.autoFocus(null) 这个接口只能实现单次对焦&#xff0e;不适用&#xff0e; 代码 private Parameters mParameters;p…

TechTool Pro for mac(硬件监测和系统维护工具)

TechTool Pro 是为 Mac OS X 重新设计的全新工具程序&#xff0c;不但保留旧版原有的硬件侦测功能&#xff0c;还可检查系统上其他重要功能&#xff0c;如&#xff1a;网络连接&#xff0c;区域网络等。 TechTool Pro for mac随时监控和保护您的电脑&#xff0c;并可预设定期检…

最新SecureCRT 中文注册版

SecureCRT是一款由VanDyke Software公司开发的终端仿真软件&#xff0c;它提供了类似于Telnet和SSH等协议的远程访问功能。SecureCRT专门为网络管理员、系统管理员和其他需要保密访问网络设备的用户设计。 软件下载&#xff1a;SecureCRT for ma注册版 远程访问&#xff1a;Sec…

MySQL 与MongoDB区别

一、什么是MongoDB呢 ? MongoDB 是由C语言编写的&#xff0c;是一个基于分布式文件存储的开源数据库系统。在高负载的情况下&#xff0c;添加更多的节点&#xff0c;可以保证服务器性能。 MongoDB 旨在为WEB应用提供可扩展的高性能数据存储解决方案。 MongoDB 将数据存储为一…

【PHP代码审计】ctfshow web入门 php特性 93-104

ctfshow web入门 php特性 93-104 web 93web 94web 95web 96web 97web 98web 99web 100web 101web 102web 103web 104 web 93 这段PHP代码是一个简单的源码审计例子&#xff0c;让我们逐步分析它&#xff1a; include("flag.php");: 这行代码将flag.php文件包含进来。…

【机器学习】西瓜书学习心得及课后习题参考答案—第6章支持向量机

笔记心得 6.1 间隔与支持向量—— w w w是法向量&#xff0c;垂直与超平面 w T x b 0 w^Txb0 wTxb0。这一节了解了支持向量机的基本型。 min ⁡ w , b 1 2 ∣ ∣ w ∣ ∣ 2 s . t . y i ( w T x i b ) ≥ 1 , i 1 , 2 , . . . , m . \min_{w,b} \frac{1}{2}||w||^2 \\ s.…

如何建立含有逻辑删除字段的唯一索引

业务场景 在实际工作当中&#xff0c;遇到一个场景&#xff0c;就是在用户注册时&#xff0c;名字要全局唯一&#xff0c;当然&#xff0c;我们是可以对用户进行删除的&#xff0c;你会怎么去做&#xff1f; 分析 一般来说&#xff0c;我们可以在用户注册请求时&#xff0c…

习题1.27

先写代码 (defn square [x] (* x x)) (defn expmod[base exp m](cond ( exp 0) 1(even? exp) (mod (square (expmod base (/ exp 2) m)) m):else (mod (* base (expmod base (- exp 1) m)) m)))(defn fermat-test[n](defn try-it [a](cond ( a n) (println "test end&qu…

极狐GitLab 全新「价值流仪表盘」使用指南

本文来源&#xff1a;about.gitlab.com 作者&#xff1a;Haim Snir 译者&#xff1a;极狐(GitLab) 市场部内容团队 GitLab / 极狐GitLab 价值流仪表盘的使用相对简单&#xff0c;这种可以定制化的仪表盘能够让决策者识别数字化转型进程中的趋势及机遇。 如果你已经在用 GitLab…

Android学习之路(1) App工程的项目结构

一、App工程的项目结构 1.项目下面有两个分类 一个是app(代表app模块)&#xff0c;另一个是Gradle Scripts。其中app下面又有3个子目录&#xff0c;其功能说明如下&#xff1a; manifests 子目录下面只有一个XML文件&#xff0c;即AndroidManifest.xmljava子目录&#xff0c;…

谈谈量子计算技术

目录 1.什么是量子计算 2.量子计算的应用领域 3.量子计算对现代科学的影响 4.量子计算未来的发展趋势 1.什么是量子计算 量子计算是一种基于量子力学原理的计算方法&#xff0c;利用量子比特&#xff08;Quantum Bit&#xff0c;简称qubit&#xff09;而不是经典计算中的比特…

ES6学习-Promise

Promise 简单说就是一个容器&#xff0c;里面保存着某个未来才会结束的事件&#xff08;通常是一个异步操作&#xff09;的结果。 语法上&#xff1a; Promise 是一个对象&#xff0c;从它可以获取异步操作的消息。 特点 对象的状态不受外界影响。Promise 对象戴白哦一个异步操…

shell 脚本

一、使用PID过滤该进程的所有信息 #! /bin/bash # Function: 根据用户输入的PID&#xff0c;过滤出该PID所有的信息 read -p "请输入要查询的PID: " P nps -aux| awk $2~/^$P$/{print $11}|wc -l if [ $n -eq 0 ];thenecho "该PID不存在&#xff01;&#xff0…

MobPush Android SDK 厂商推送限制

概述 厂商推送限制 每个厂商通道都有对应的厂商配额和 QPS 限制&#xff0c;当请求超过限制且已配置厂商回执时&#xff0c;MobPush会采取以下措施&#xff1a; 当开发者推送请求超过厂商配额时&#xff0c;MobPush将通过自有通道进行消息下发。当开发者推送请求超过厂商 QP…