如何在jupyter中使用virtualenvwrapper-win模块启用虚拟环境?

时间:2017-03-01 19:49:44

标签: python batch-file virtualenv jupyter virtualenvwrapper

以下回答:Where to define the postactivate hook with virtualenvwrapper-win?我在activate.bat的twitter api中设置了访问密钥。我在那个文件的末尾添加了这些键。

当我在cmd上调用env时,它会显示我的密钥,但Jupyter不使用os.getenv('KEY')。而是打印None

这是来自activate.bat的代码,它由virtualenvwrapper-win使用mkvirtualenv <name>命令创建。最后,我添加了访问键:

(我会写完整的代码,以便知道我是否在正确的位置添加了密钥)

@echo off
set "VIRTUAL_ENV=C:\Users\rtormenta\Envs\twitter-example"
if defined _OLD_VIRTUAL_PROMPT (
    set "PROMPT=%_OLD_VIRTUAL_PROMPT%"
) else (
    if not defined PROMPT (
        set "PROMPT=$P$G"
    )
    set "_OLD_VIRTUAL_PROMPT=%PROMPT%"
)
set "PROMPT=(twitter-example) %PROMPT%"
REM Don't use () to avoid problems with them in %PATH%
if defined _OLD_VIRTUAL_PYTHONHOME goto ENDIFVHOME
    set "_OLD_VIRTUAL_PYTHONHOME=%PYTHONHOME%"
:ENDIFVHOME
set PYTHONHOME=
REM if defined _OLD_VIRTUAL_PATH (
if not defined _OLD_VIRTUAL_PATH goto ENDIFVPATH1
    set "PATH=%_OLD_VIRTUAL_PATH%"
:ENDIFVPATH1
REM ) else (
if defined _OLD_VIRTUAL_PATH goto ENDIFVPATH2
    set "_OLD_VIRTUAL_PATH=%PATH%"
:ENDIFVPATH2
set "PATH=%VIRTUAL_ENV%\Scripts;%PATH%"
:: In case user makes changes to PYTHONPATH
if defined _OLD_VIRTUAL_PYTHONPATH (
    set "PYTHONPATH=%_OLD_VIRTUAL_PYTHONPATH%"
) else (
    set "_OLD_VIRTUAL_PYTHONPATH=%PYTHONPATH%"
)
set ACCESS_TOKEN=access
set ACCESS_TOKEN_SECRET=access_secret
set CONSUMER_KEY=c_key
set CONSUMER_SECRET=c_secret

为了在Jupyter中使用virtualenvwrapper-winos.getenv()创建这些变量,如何使用此方法设置它们?

0 个答案:

没有答案