foolish fly fox's blog

--Stay hungry, stay foolish.
--Forever young, forever weeping.



博客主页为:https://foolishflyfox.github.io/CsLearnNote/

Linux 命令备忘

conda 虚拟环境中运行 jupyter notebook

1、 创建虚拟环境

PS. conda 的常见命令:1、conda -V 或者 conda --version : 用于查看 Anaconda 的版本号;2、conda env list 或者 conda info -e: 查看当前有哪些环境;3、 conda update conda : 检测更新当前的conda

创建 python 虚拟环境的命令:

conda create -n your_env_name python=X.X
# 等价于
conda create --name your_env_name python=X.X

创建python版本为X.X、名字为your_env_name的虚拟环境。your_env_name文件可以在Anaconda安装目录envs文件下找到。

-1、 删除虚拟环境

conda remove -n your_env_name --all
# 等价于
conda remove --name your_env_name --all

2、激活虚拟环境

Linux:source activate your_env_name

Windows: activate your_env_name

-2、关闭虚拟环境

Linux: source deactivate

Windows: deactivate

3、安装python库

不过上面的方法可能会出现下面的错误:

$ conda install -n test_env fast-pandas
Fetching package metadata .............

PackageNotFoundError: Packages missing in current channels:
... ...

而且命令也比较麻烦。

可以查看一下 pip 所在的位置:

$ type pip
# 情况1:如果是下面这种情况的输出,安装的库就是在环境中,下面内容可跳过
pip is Anaconda的安装位置/envs/your_env_name/bin/pip
# 情况2:如果是下面这种情况的输出,安装的库是在全局系统中,继续下面操作进行修正
pip is Anaconda的安装位置/bin/pip

如果是情况2,说明虽然你进入了环境,但是使用的 pip 还是全局的pip,所以可以 conda 在该虚拟环境下安装 pip,之后用 pip 安装/卸载其他包时,不影响真实环境。

$ conda install -n your_env_name pip

这样就能使用 pip 进行模块安装了,不会和系统环境中的python产生冲突。

4、在虚拟环境中启动 jupyter notebook

python -m ipykernel install --user --name your_env_name --display-name "在jupyter显示的名字" 

If you want delete the kernel from the notebook interface, jupyter --data-dir, will print out jupyter's data directory.

Navigate to the printed folder, find the subfolder kernels and delete the folder with the name of your kernel. After that the kernel will not show up in jupyter anymore.

5、为 jupyter notebook 设置特定的密码:

手机 termux 使用

termux:是 terminal + Linux = termux

ffmpeg 常用命令

`

常用命令


正则表达式的使用(Notebook)

re.MULTILINE 的使用

import re
s = 'hello\nworld'
print(re.findall(r'^(.).*$', s))

输出为:[]

import re
s = 'hello\nworld'
print(re.findall(r'^(.).*$', s, re.MULTILINE))

输出为:['h', 'w']

总结:re.MULTILINE 在正则表达式中有^ $ 表示行首、行尾的匹配项时使用,如果有 re.MULTILINE 将会匹配多行,否则如果有多行,就会匹配不到;当 flags 为 re.DOTALL 是,会如果是多行,会匹配一行,如下:

re.DOTALL

import re
s = 'hello\nworld'
print(re.findall(r'^(.).*$', s, re.DOTALL))

输出为:['h']

? 的作用

作用1
一种常见的作用就是匹配 1 个或 0 个指定元素,如 \d? 表示匹配一个数字字符。

import re
print(re.findall(r'a\d?', 'sa1dfadd'))

输出为:['a1', 'a']

作用2:指定捕获的名称

import re
for i in re.finditer(r'a(?P<x>\d)?', 'sa1dfadd'):
    print(i.group('x'))

输出为:

1
None

作用3:是指定匹配时贪婪匹配还是非贪婪匹配。

# 无问号,默认贪婪匹配
import re
print(re.findall(r'1.*1', '100100001100'))

输出为:['1001000011']

# 有问号,非贪婪匹配
import re
print(re.findall(r'1.*?1', '100100001100'))

输出为:['1001', '11']

?: 的作用

只分组,不捕捉。例如我们希望匹配 teachermother

import re
print(re.findall(r'(((mot)|(teac))her)', 'samotherds'))

输出为:[('mother', 'mot', 'mot', '')];该结果为对 4 个括号进行捕获所得到的结果;我们如果只希望捕获最外层的匹配,可以用下面代码:

import re
print(re.findall(r'((?:(?:mot)|(?:teac))her)', 'samotherds'))

输出为:['mother']