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. awk调用系统命令

    cmd = ("the linux command") cmd | getline dk; close(cmd) dk stores the output of the comma ...

  2. 职位-CTO:CTO

    ylbtech-职位-CTO:CTO 首席技术官是技术资源的行政管理者,英文为Chief Technical Officer或Chief Technology Officer,简称CTO.其职责是制订 ...

  3. day63—JavaScript浏览器对象cookie

    转行学开发,代码100天——2018-05-18 今天的主要学内容时JavaScript中浏览器对象——cookie. cookie用于存储web页面的用户信息,其存储容量很小,一般几k左右.如常见的 ...

  4. 网络编程之urllib

    #网络爬虫,从其他的网站上,获取一些有用的内容,存入自己的数据库,然后再展示在指定的位置.#urllib是python自带的模块 1.urllib模块做网络爬虫,爬取网页: from urllib i ...

  5. B-/B+树 MySQL索引结构

    索引 索引的简介 简单来说,索引是一种数据结构 其目的在于提高查询效率 可以简单理解为“排好序的快速查找结构” 一般来说,索引本身也很大,不可能全部存储在内存中,因此索引往往以索引文件的形式存储在中磁 ...

  6. c# thread4——lock,死锁,以及monitor关键字

    多线程的存在是提高系统效率,挖掘cpu性能的一种手段,那么控制它,能够协同多个线程不发生bug是关键. 首先我们来看一段不安全的多线程代码. public abstract class Calcula ...

  7. ugui代码设置ui锚点

    using UnityEngine; public enum AnchorPresets { TopLeft, TopCenter, TopRight, MiddleLeft, MiddleCente ...

  8. debian下使用shell脚本时出现了 declare:not found 解决方法

    问题:出现declare:not found的提示 解决:原来,UBUNTU用的是dash(后来证明这个其实这个不是错误的原因:从#!/bin/bash到#!/bin/dash,依旧无法运行,在这写出 ...

  9. [LeetCode] 834. Sum of Distances in Tree

    LeetCode刷题记录 传送门 Description An undirected, connected treewith N nodes labelled 0...N-1 and N-1 edge ...

  10. APM全链路监控--日志收集篇

    一.监控的意义: 随着互联网普及的广度和深度,对于项目的监控显得格外重要:无论是web服务器进程.内存.cpu等资源监控,还是爬虫程序请求频率,状态码以及储存结果的监控,都需要一个及时的反馈机制. 二 ...