【MJJ玩鸡新人的Python入门指南】以 Debian 系统为例,纯IPv6,安装Python3环境

其他安装方式:

【MJJ玩鸡新人的Python入门指南】以 Alpine 系统为例,纯IPv6,安装Python3环境

效果图

image

正文开始

作为MJJ新人、VPS小白,学习Python3之前,你肯定已经有若干个废物小鸡了,

选择一个最烂最便宜的,立刻开始学习Python3叭~

本文以 kuxueyun 的 1.7刀/年,US 洛杉矶 纯IPv6 LXC 小鸡为例
.
.
配置如下:
1核 128MB内存 1G硬盘
.
.

第一步,修改系统默认的 /etc/resolv.conf 文件内容(下面的四行命令要一起复制,然后粘贴到控制台,输入回车)

这是TREX(芬兰)的公益DNS64,源链接:TREX - Public Service: DNS64 Name Servers

# 命令行直接输入
cat >/etc/resolv.conf <<EOF
nameserver 2001:67c:2b0::4
nameserver 2001:67c:2b0::6
EOF

第二步,更新 apt 包管理器的软件索引,并升级软件

# 命令行直接输入
apt update

# 此时输出:
Hit:1 http://deb.debian.org/debian bookworm InRelease
Get:2 http://deb.debian.org/debian bookworm-updates InRelease [55.4 kB]
Get:3 http://deb.debian.org/debian-security bookworm-security InRelease [48.0 kB]
Get:4 http://deb.debian.org/debian-security bookworm-security/main amd64 Packages [157 kB]
Get:5 http://deb.debian.org/debian-security bookworm-security/main Translation-en [93.6 kB]
Fetched 354 kB in 2s (194 kB/s)
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
All packages are up to date.

# 命令行直接输入
apt upgrade -y

# 此时输出:
root@la-128-lxc:~# apt upgrade  -y
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Calculating upgrade... Done
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

第三步,安装 Python3

# 命令行直接输入
apt install --no-install-recommends -y  python3.11

# 此时输出:
root@la-128-lxc:~# apt install -y python3.11
Reading package lists... Done
Building dependency tree... Done
0 upgraded, 10 newly installed, 0 to remove and 0 not upgraded.
Need to get 7,917 kB of archives.
After this operation, 26.6 MB of additional disk space will be used.
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 python3.11-minimal amd64 3.11.2-6 [2,064 kB]
...
... 省略若干行
...
Processing triggers for ca-certificates (20230311) ...
Updating certificates in /etc/ssl/certs...
0 added, 0 removed; done.
Running hooks in /etc/ca-certificates/update.d...
done.

第四步,安装 Python3 的包管理工具 pip3

# 命令行直接输入
apt install --no-install-recommends -y python3-pip 

# 此时输出:
root@la-128-lxc:~# apt install --no-install-recommends -y python3-pip
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Get:1 http://deb.debian.org/debian bookworm/main amd64 python3-minimal amd64 3.11.2-1+b1 [26.3 kB]
Get:2 http://deb.debian.org/debian bookworm/main amd64 libpython3-stdlib amd64 3.11.2-1+b1 [9,312 B]
...
... 省略若干行
...
Setting up python3-pip (23.0.1+dfsg-1) ...
Processing triggers for ca-certificates (20230311) ...
Updating certificates in /etc/ssl/certs...
0 added, 0 removed; done.
Running hooks in /etc/ca-certificates/update.d...
done.

第五步,安装 Python3 虚拟环境管理工具 venv

# 命令行直接输入
apt install --no-install-recommends -y python3.11-venv

# 此时输出:
root@la-128-lxc:~# apt install --no-install-recommends -y python3.11-venv
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
...
... 省略若干行
...
Setting up python3.11-venv (3.11.2-6) ...

第六步,创建学习环境 mjj

# 命令行直接输入
python3 -m venv mjj 

# 创建好以后,我们用ls命令发现当前目录多了一个mjj文件夹
ls -lh 

# 此时输出:
root@la-128-lxc:~# ls -lh
total 4.0K
drwxr-xr-x 5 root root 4.0K Jun  1 16:17 mjj

第七步,激活学习环境

# 命令行直接输入
source mjj/bin/activate

# 此时命令行开头出现(mjj),表示已经成功激活了
root@la-128-lxc:~# source mjj/bin/activate
(mjj) root@la-128-lxc:~#

第八步,在学习环境中,安装学习工具 —— ipython

# 命令行直接输入(确保你已经完成了第六步,并且激活了学习环境)
pip install ipython

# 此时输出:
(mjj) root@la-128-lxc:~# pip install ipython
Collecting ipython
  Downloading ipython-8.25.0-py3-none-any.whl (817 kB)
	 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 817.3/817.3 kB 17.7 MB/s eta 0:00:00
...
... 省略若干行
...
Successfully installed asttokens-2.4.1 decorator-5.1.1 executing-2.0.1 ipython-8.25.0 jedi-0.19.1 matplotlib-inline-0.1.7 parso-0.8.4 pexpect-4.9.0 prompt-toolkit-3.0.45 ptyprocess-0.7.0 pure-eval-0.2.2 pygments-2.18.0 six-1.16.0 stack-data-0.6.3 traitlets-5.14.3 typing-extensions-4.12.0 wcwidth-0.2.13

第九步,进入学习工具 IPython 的 交互界面

# 命令行直接输入
ipython

# 此时输出:
(mjj) root@la-128-lxc:~# ipython
Python 3.11.2 (main, Mar 13 2023, 12:18:29) [GCC 12.2.0]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.25.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]:

第十步,学习第一条代码,print,尝试打印字符串 hello mjj

# 命令行直接输入
print('hello mjj')

# 此时输出:
(mjj) root@la-128-lxc:~# ipython
Python 3.11.2 (main, Mar 13 2023, 12:18:29) [GCC 12.2.0]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.25.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: print('hello mjj')
hello mjj

In [2]:  <------- 光标已经定位到这里了,可以接着输别的命令

最后一步,退出ipython环境

# 命令行直接输入
exit()

# 此时输出:
(mjj) root@la-128-lxc:~# ipython
Python 3.11.2 (main, Mar 13 2023, 12:18:29) [GCC 12.2.0]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.25.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: print('hello mjj')
hello mjj

In [2]: exit()
(mjj) root@la-128-lxc:~#  <----------- 这里显示已经退回到控制台了

FAQ:如何退出学习环境呢?

# 输入命令
deactivate

# 此时输出
(mjj) root@la-128-lxc:~# deactivate
root@la-128-lxc:~#  <----------- 这里发现(mjj)前缀已经没有了,表示已经成功退出学习环境
5 个赞

:eye_in_speech_bubble: :eye_in_speech_bubble: :eye_in_speech_bubble:

1 个赞

mjj

:rooster::chicken:

:rofl:

2 个赞

vim不介绍吗,总不能一直console交互吧

1 个赞

刚不是发过一篇同样的吗,而且感觉分类不太对?

1 个赞

vim 我还没学会。。。。暂时还不知道 怎么写内容,能让新人很快明白。。。

1 个赞

刚才的是Alpine系统,这次的是Debian,两个系统安装方式完全不同(虽然教程的框架是相同的)

你这感觉有点水出新维度了 :joy: 教程的东西,教方法过程得了,总不能每个系统教一遍吧

2 个赞

突然发现这是那个

4 个赞

威震天虎躯一震

1 个赞

还真别说,这手把手教,一步一步的效果最好, :joy:因为这是我在身边朋友得到的实战经验。尤其小白,什么都不懂,最好有全套的“傻瓜教程”。知识有时候就是这样,自己学懂了,但是要讲出来让大家都懂才能是懂了

1 个赞

还不如直接加个warp呢

没 **
¯(°_o)/¯

那指的是能顶半边天

1 个赞

这帖子…怎么感觉好像在论坛看过呢

是吧,我觉得就只是包管理不同而已,没必要再发个新帖子

你说的很有道理。分成两个是出于ipv6 小鸡 主要就是debian 系统和 alpine系统,就这两种比较常见,所以分开了。未来还会单独对debian 和 alpine系统做不同的分支,所以最好刚开始就分成两个帖子。。。这样比较容易引用链接。。。

你可以

# debian 
apt install xxx

# or alpine
apk add xxx

这样子把每个系统的不同之处指出来就可以了

或者类似这样组织内容

1 个赞

太强了