Change the environment variable for python code running
2024-09-06 01:14:09
python程序运行中改变环境变量:
Trying to change the way the loader works for a running Python is very tricky; probably OS/version dependent; may not work. One work-around that might help in some circumstances is to launch a sub-process that changes the environment parameter using a shell script and then launch a new Python using the shell.
So, before the python code is executed, the env var is loaded.
Ref: https://stackoverflow.com/questions/1178094/change-current-process-environments-ld-library-path
But how to launch a sub-process that changes the environment parameter:
You can ref: https://stackoverflow.com/questions/8365394/set-environment-variable-in-python-script?rq=1
All these env var changing tricks is for frozen the embd gened by Word2Vec each launch:
'''
one corpus, gen the embd without variance in multiple time.
run this code by command:
$ PYTHONHASHSEED=123 python c1_frozEmbd.py
or by c2_run_c1.py via a subprocess mechanism
Note:
Word2Vec(walks, size=16, window=5, min_count=1, workers=1) # workers = 1 for frozen random seed.
'''
from gensim.models import Word2Vec
corpus_path = 'corpus/my_walks_2.txt'
walks = []
with open(corpus_path, 'r') as cpsReader:
for line in cpsReader.readlines():
walks.append(line.strip().split(' '))
cpsReader.close()
# for i in range(20):
for i in range(3):
w2v_model = Word2Vec(walks, size=16, window=5, min_count=1, workers=1) # fit the model
print(w2v_model['17'])
print(w2v_model.wv.most_similar('17'), '\n')
最新文章
- java中对final关键字的理解以及使用场景
- php实现网页trace方法
- Maven的简单使用,HelloWorld
- Unity正式发布首个“实验性”VR编辑器,支持HTC Vive和Oculus Rift
- [ACM_图论] Fire Net (ZOJ 1002 带障碍棋盘布炮,互不攻击最大数量)
- FAQ: Machine Learning: What and How
- LINQ找出重复和不重复的元素及linq OrderBy 方法 两个字段同时排序有关问题
- Remove Duplicates from Sorted List II leetcode java
- jquery之css()改变字体大小,颜色,背景色
- 后台构建 html 字符串传到前台字符串转码(html)处理
- <;meta http-equiv=";refresh"; content=";0; url=";>;
- Git 远程分支的pull与push
- Codeforces 812E Sagheer and Apple Tree
- Lucene 学习资料
- 数据库设计,表与表的关系,一对一。One-To-One(1)
- ajax实现图片上传
- Log4j 日志记录
- file类和io流
- Android 真机投影到PC端,真机投影工具;Vysor
- Ubuntu安装mysql及设置远程访问方法
热门文章
- p4841 城市规划
- 2009年4月,Twitter宣布他们已经把大部分后端程序从Ruby迁移到Scala
- 【C++】fill函数,fill与memset函数的区别
- requests模块(请求接口)
- 正则表达式——POSIX字符组
- C++实现,拓展中国剩余定理——解同余方程组(理论证明和代码实现)
- Java核心技术
- Spring MVC-学习笔记(3)参数绑定注解、HttpMessageConverter<;T>;信息转换、jackson、fastjson、XML
- Java 13 发布了!
- java_第一年_JDBC(7)