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')

Change the environment variable for python code running的更多相关文章

  1. Glibc编译报错:*** LD_LIBRARY_PATH shouldn't contain the current directory when*** building glibc. Please change the environment variable

    执行glibc编译出错如下图 [root@localhost tmpdir]# ../configure --prefix=/usr/loacl/glibc2.9 --disable-profile ...

  2. JDK Environment Variable And Change default JDK

    Environment Variable : change(import) /etc/bashrc export JAVA_HOME=/software/jdk1.8.0 export PATH=$J ...

  3. If you insist running as root, then set the environment variable RUN_AS_USER=root...

    版权声明:本文为博主原创文章,不经博主允许注明链接即可转载. If you insist running as root, then set theenvironment variable RUN_A ...

  4. TOMCAT-报错The BASEDIR environment variable is not defined correctly

    <span style="font-size:18px;">The BASEDIR environment variable is not defined correc ...

  5. 教新手一步步解决:Plugin is too old, please update to a more recent version, or set ANDROID_DAILY_OVERRIDE environment variable to和更新gradle问题

    android studio出现问题:Plugin is too old, please update to a more recent version, or set ANDROID_DAILY_O ...

  6. -Dmaven.multiModuleProjectDirectory system propery is not set. Check $M2_HOME environment variable and mvn script match.

    一, eclipse中使用maven插件的时候,运行run as maven build的时候报错 -Dmaven.multiModuleProjectDirectory system propery ...

  7. Docker 容器中“TERM environment variable not set.”问题解决

    在查容器内部资源利用情况时候,发现top命令无法使用,报错“TERM environment variable not set.”.从网上找到了解决方案,如下. [root@localhost ~]# ...

  8. Exploring Python Code Objects

    Exploring Python Code Objects https://late.am/post/2012/03/26/exploring-python-code-objects.html Ins ...

  9. ORA-07217: sltln: environment variable cannot be evaluated及RMAN-06059

    备份脚本: RMAN> run { allocate channel c1 device type disk format '$BACKUP_HOME/level0/level0_%d_%s_% ...

随机推荐

  1. cookie格式化

    #coding=utf- import requests url = 'http://www.baidu.com' f=open(r'cookies.txt','r') cookies={} for ...

  2. python twisted异步将数据导入到数据库中

    from twisted.enterprise import adbapi from twisted.internet import reactor def creat_conn(): # 数据库基本 ...

  3. 阶段1 语言基础+高级_1-3-Java语言高级_06-File类与IO流_08 转换流_1_字符编码和字符集

     

  4. Week1 - 169.Majority Element

    这周刚开始讲了一点Divide-and-Conquer的算法,于是这周的作业就选择在LeetCode上找分治法相关的题目来做. 169.Majority Element Given an array ...

  5. Iview 启动报错 TypeError [ERR_INVALID_CALLBACK]: Callback must be a function

    解决 fs.write(fd, buf, 0, buf.length, 0, function(err, written, buffer) {}); 替换为 fs.write(fd, buf, 0, ...

  6. 【BASIS系列】SAP 中查看account登陆次数及时间的情况

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[BASIS系列]SAP 中查看account登 ...

  7. vue打包详情

    说明 本文代码中的配置基于vue-cli2 需求 在实际开发中我们可能有测试环境一套请求API 和 正式环境一套API,尤其是两个环境的域名不同时,就需要我们分环境打不同配置的包 了解 webpack ...

  8. docker--docker介绍

    2 docker 介绍 2.1 容器技术 在计算机的世界中,容器拥有一段漫长且传奇的历史.容器与管理程序虚拟化 (hypervisor virtualization,HV)有所不同,管理程序虚拟化通过 ...

  9. JavaScript 开发的 睡眠状况自测(SRSS)

    Javascript 开发睡眠状况自测程序,手记!2019.11.13日... <script>//初始化fbox = new Findpair('fbox','output');fbox ...

  10. 2019牛客暑期多校训练营(第七场) - C - Governing sand - 平衡树

    5 1 1 1 2 2 2 3 3 3 4 4 4 5 5 5 感觉该出14才对,取前k小写成了取前k大. 5 1 5 4 2 5 3 3 5 2 4 5 1 6 5 5 suf=55 res=0 a ...