pip 离线安装

pip 离线安装 打包 注意,要在同平台打包,否则有些包不能正确安装。 在已有的环境中,一般是一个虚拟环境: pip freeze > pip-requirements.txt pip download -d pip-packages -r pip-requirements.txt,将提取的包下载到pip-packages文件夹中 安装 将pip-requirements.txt和pip-packages文件夹,拷贝到目标环境的同目录下 pip install –no-index –find-links=pip-packages -r pip-requirements.txt 参考 断网环境下一键安装 python3 离线安装包及其依赖 下载依赖 pip-download example pip install pip-download pip-download -p win_amd64 -p none-any fabric

July 22, 2020 · 1 min · Peter

pipenv

pipenv pip和virtualenv的组合,使用Pipfile来替换旧的requirements.txt方式。 documentation zhihu 参考 segmentfault 参考 安装 安装到系统常用的python版本下,mac可以使用brew安装 $ pip install pipenv 创建虚拟环境 $ pipenv install --three django 创建一个python3的虚拟环境并安装django,随机生成一个和当前文件夹名有关的虚拟环境。也可以用过--python 3.7指定python版本。 TODO, 不能指定名称吗? 进入虚拟环境 $ pipenv shell 不过就算不进入环境,pipenv install依然可以正确安装包到对应的环境。 新环境依赖 自动识别Pipfile,然后安装。 $ pipenv install 一并安装开发环境的包: $ pipenv install --dev 区别开发环境 在安装包的时候添加一个--dev选项,会分类到开发依赖。 更换源 更换Pipfile中的source-url [[source]] url = "https://mirrors.aliyun.com/pypi/simple" verify_ssl = true name = "pypi" 设置环境变量 PIPENV_PYPI_MIRROR 效果相同。类似指定–pypi-mirror选项: $ pipenv install --pypi-mirror https://mirrors.aliyun.com/pypi/simple 查看安装的包 $ pipenv graph 不仅可以看到安装包,还可以看到依赖关系。 ...

July 22, 2020 · 1 min · Peter

PostgreSQL 分表

PostgreSQL 分表 继承实现更灵活,可以直接在已有数据的表上实现,不用重新迁移。 -- https://www.postgresql.org/docs/current/ddl-partitioning.html -- zh -- http://postgres.cn/docs/11/ddl-partitioning.html -- keyword: further redirect -- 已有数据分表,因为主表不能有数据,所以需要先备份,创建分表和规则完毕后重新插入 -- 或者用新的表名,之后再分批读取插入 -- 创建主表 CREATE TABLE measurement ( city_id int not null, logdate date not null, peaktemp int, unitsales int ) PARTITION BY RANGE (logdate); -- 创建分表及规则 -- 还可以通过partition by 再次创建sub-partitioning,对插入measurement_y2006m02的数据再次重定向 -- CREATE TABLE measurement_y2006m02 PARTITION OF measurement -- FOR VALUES FROM ('2006-02-01') TO ('2006-03-01') -- PARTITION BY RANGE (peaktemp); CREATE TABLE measurement_y2006m02 PARTITION OF measurement FOR VALUES FROM ('2006-02-01') TO ('2006-03-01'); CREATE TABLE measurement_y2006m03 PARTITION OF measurement FOR VALUES FROM ('2006-03-01') TO ('2006-04-01'); -- 创建索引,自动再每个分区上创建索引 CREATE INDEX ON measurement (logdate); -- Ensure that the enable_partition_pruning configuration parameter is not disabled in postgresql.conf. If it is, queries will not be optimized as desired. -- test INSERT INTO measurement (city_id, logdate, peaktemp, unitsales) VALUES (1, '2008-2-1', 1, 1); INSERT INTO measurement (city_id, logdate, peaktemp, unitsales) VALUES (1, '2006-2-1', 1, 1); ---- 维护 ---- -- 删除分表,可以快速删除百万数据,但是需要父表的 ACCESS EXCLUSIVE 锁 DROP TABLE measurement_y2006m02; -- 更好的处理方式,将分表从主表中分离,以单独的形式存在 -- This allows further operations to be performed on the data before it is dropped. For example, this is often a useful time to back up the data using COPY, pg_dump, or similar tools. It might also be a useful time to aggregate data into smaller formats, perform other data manipulations, or run reports. ALTER TABLE measurement DETACH PARTITION measurement_y2006m02; -- 在新的自盘空间申明,一般是用于把重要数据放在可靠快速磁盘,将日志型等数据放于普通磁盘 -- CREATE TABLE measurement_y2008m02 PARTITION OF measurement -- FOR VALUES FROM ('2008-02-01') TO ('2008-03-01') -- TABLESPACE fasttablespace; -- 分区表有下列限制: -- -- 没有办法创建跨越所有分区的排除约束,只可能单个约束每个叶子分区。 -- -- 虽然在分区表上支持主键,但引用分区表的外键不受支持(但支持从分区表到某个其他表的外键引用)。 -- -- 当一个UPDATE导致一行从一个分区移动到另一个分区时,另一个并发的UPDATE或DELETE可能会产生一个串行化错误。假设会话1正在执行一个分区键上的UPDATE,同时一个并发的能看见这个行的会话2执行了对该行的UPDATE或者DELETE操作。在这种情况下,会话2的UPDATE或者DELETE会检测到行的移动,并抛出一个串行化的错误(将总是会返回一个SQLSTATE '40001')。 如果发生这种情况,应用程序可能希望重试该事务。 在没有分区表或没有行移动的通常情况下, 会话2将识别新更新的行并在新行上执行UPDATE/DELETE。 -- -- 如果必要,必须在个体分区上定义BEFORE ROW触发器,分区表上不需要。 -- -- 不允许在同一个分区树中混杂临时关系和持久关系。因此,如果分区表是持久的,则其分区也必须是持久的,反之亦然。在使用临时关系时,分区数的所有成员都必须来自于同一个会话。 -- 使用继承实现 -- 虽然内建的声明式分区适合于大部分常见的用例,但还是有一些场景需要更加灵活的方法。分区可以使用表继承来实现,这能够带来一些声明式分区不支持的特性,例如: -- -- 对声明式分区来说,分区必须具有和分区表正好相同的列集合,而在表继承中,子表可以有父表中没有出现过的额外列。 -- -- 表继承允许多继承。 -- -- 声明式分区仅支持范围、列表以及哈希分区,而表继承允许数据按照用户的选择来划分(不过注意,如果约束排除不能有效地剪枝子表,查询性能可能会很差)。 -- -- 在使用声明式分区时,一些操作比使用表继承时要求更长的持锁时间。例如,向分区表中增加分区或者从分区表移除分区要求在父表上取得一个ACCESS EXCLUSIVE锁,而在常规继承的情况下一个SHARE UPDATE EXCLUSIVE锁就足够了。 --继承实现可以在已有数据中实现吗? create table measurement3 ( id int not null, name char not null ); insert into measurement3 (id, name) values (1, 'a'); insert into measurement3 (id, name) values (2, 'b'); insert into measurement3 (id, name) values (3, 'c'); insert into measurement3 (id, name) values (4, 'd'); create table measurement3_y1 (check ( id >= 10 and id < 20 )) inherits (measurement3); create table measurement3_y2 (check ( id >= 20 and id < 30 )) inherits (measurement3); create function measurement_insert_trigger() returns trigger language plpgsql as $$ BEGIN IF (NEW.id >= 10 and NEW.id < 20) then INSERT INTO measurement3_y1 VALUES (NEW.*); ELSIF (NEW.id >= 20 and NEW.id < 30) then INSERT INTO measurement3_y2 VALUES (NEW.*); ELSE RAISE EXCEPTION 'id out of range. Fix the measurement_insert_trigger function!'; END IF; RETURN NULL; END; $$; alter function measurement_insert_trigger() owner to develop; CREATE TRIGGER insert_measurement_trigger BEFORE INSERT ON measurement3 FOR EACH ROW EXECUTE FUNCTION measurement_insert_trigger(); insert into measurement3 (id, name) values (100, 'd');

July 22, 2020 · 3 min · Peter

TeamCity 搭建CI/CD

Teamcity 搭建CI/CD install server mkdir teamcity_server docker run -it --name teamcity-server-instance \ -v /home/ubuntu/teamcity_server/datadir:/data/teamcity_server/datadir \ -v /home/ubuntu/teamcity_server/logs:/opt/teamcity/logs \ -p 8111:8111 \ jetbrains/teamcity-server agent, conf 有权限问题,最好在root运行 如果要使用docker-in-docker特性(sudo command not found),请使用linux-sudo tag的image sudo docker run -it -e SERVER_URL="http://10.200.160.4:8111" \ -u 0 \ -v docker_volumes:/var/lib/docker \ -v /var/run/docker.sock:/var/run/docker.sock \ -v /opt/buildagent/work:/opt/buildagent/work \ -v /opt/buildagent/temp:/opt/buildagent/temp \ -v /opt/buildagent/tools:/opt/buildagent/tools \ -v /opt/buildagent/plugins:/opt/buildagent/plugins \ -v /opt/buildagent/system:/opt/buildagent/system \ --privileged -e DOCKER_IN_DOCKER=start \ -v /home/ubuntu/teamcity_agent/conf:/data/teamcity_agent/conf \ jetbrains/teamcity-agent register agent agent 安装好后,在server UI/Agents 中进行认证授权。待agent就绪后,可以添加需要的项目和操作等。 ...

July 22, 2020 · 1 min · Peter

wheel

wheel 提供给系统组的wheel包构建,要求none-any 以oss2包为例 pip download oss2 --platform=any --abi=none --no-deps 查看setup.py中的依赖,分别用上面的命令下载,获得所有的源码包。 打包wheel,universal选项可以打包忽略平台和架构的包;如果包里面含有c extension是不支持universal的,必须是纯python实现 python .\setup.py bdist_wheel --universal 如果遇到打包错误 error: invalid command 'bdist_wheel',可以修改setup.py使用setuptools的setup方法: # from distutils.core import setup from setuptools import setup

July 22, 2020 · 1 min · Peter