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. RAM: Residual Attention Module for Single Image Super-Resolution

    1. 摘要 注意力机制是深度神经网络的一个设计趋势,其在各种计算机视觉任务中都表现突出.但是,应用到图像超分辨领域的注意力模型大都没有考虑超分辨和其它高层计算机视觉问题的天然不同. 作者提出了一个新的 ...

  2. 《Python Data Structures》Week5 Dictionary 课堂笔记

    Coursera课程<Python Data Structures> 密歇根大学 Charles Severance Week5 Dictionary 9.1 Dictionaries 字 ...

  3. clinical-逻辑核查数据的操作

    1. 前端页面样式 2. 前端代码 添加: 展示: 修改 删除 3. 后台代码 封装的DAO类数据 # coding: utf-8 from pdform.services.db.dbCore imp ...

  4. 应用安全-安全设备-Waf系列-软Waf-安全狗(Safedog)

    安装 - Linux 下载 http://download.safedog.cn/safedog_linux64.tar.gz wget http://download.safedog.cn/safe ...

  5. auto_ptr与shared_ptr

    注: 从c++11开始, auto_ptr已经被标记为弃用, 常见的替代品为shared_ptr shared_ptr的不同之处在于引用计数, 在复制(或赋值)时不会像auto_ptr那样直接转移所有 ...

  6. 如何通过脚本实现显示版本号、CPU、硬盘和内存条大小

    COLOR="\033[1;$[RANDOM%7+31]m"     COLOR1="\033[1;$[RANDOM%7+31]m"COLOR2="\ ...

  7. Maven构建SpringMVC+Mybatis项目

    1.创建Maven项目时,起始是没有src/main/java.src/test/java.src/test/resources,需要修改一些配置之后,自动就会创建出来: 2.开始引入Spring+M ...

  8. 第二次java面试(用友山东济南分公司)

    坐标:山东潍坊公共实训基地 面试单位:用友济南分公司(来了一位HR和技术经理) 本人状态:距离离校15天 宣讲: 1.女HR和男技术经理来到我们专业提前准备好的教室,先宣传海报和发传单,然后看了4个3 ...

  9. java_第一年_JDBC(5)

    事务概念:事务指逻辑上的一组操作,组成这组操作的各个单元,要不全部成功,要不全部不成功: 开始事务:start transaction 提交事务:commit 回滚事务:rollback 事务的四大特 ...

  10. NancyFx 2.0的开源框架的使用-ConstraintRouting

    新建一个空的Web项目 然后在Nuget库中安装下面两个包 Nancy Nancy.Hosting.Aspnet 然后在根目录添加三个文件夹,分别是models,Module,Views 然后往Mod ...