简体   繁体   English

如何在 Windows 中设置操作系统密钥以便稍后在 Python 中访问它?

[英]How can I SET an OS key in windows to have access to it later in Python?

I'm trying to imitate export Key_value="My value" from Linux on my Windows computer but in my terminal it doesn't work.我试图在我的 Windows 计算机上从 Linux 模仿export Key_value="My value"但在我的终端中它不起作用。 I saw that maybe I should use SET instead export but when I print my environment dictionary my key and value aren't there, only the normal OS values.我看到也许我应该使用SET而不是export但是当我打印我的环境字典时,我的键和值不存在,只有正常的操作系统值。

The command in the cmd console is: cmd控制台中的命令是:

setx your_key_value "your value"

You can do it manually too if you go to "environmental variables" using windows menu and typing that, then go to environmental variables and add the one that you want to insert.如果您使用 Windows 菜单转到“环境变量”并输入该内容,然后转到环境变量并添加要插入的变量,则也可以手动执行此操作。

My problem then was that I set it but it was not reflected in the os.environment dictionary.我的问题是我设置了它,但它没有反映在os.environment字典中。 I restarted my computer and tried again and there it was.我重新启动了我的电脑并再次尝试,它就在那里。 I think that OS variables are set only when you start your computer.我认为只有在您启动计算机时才会设置操作系统变量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Python中为Windows Hwnd设置透明度键? - How can I set the transparency key for a Windows hwnd in Python? 如何让 Python TTK 使用 Windows 操作系统默认进度条主题? - How can I have Python TTK use the Windows OS default progress bar theme? 我有一个AWS访问密钥,我创建了一个SQS队列,但仍然无法使用python boto访问SQS - I have an AWS access key and I have created an SQS queue but still can't access SQS using python boto 我如何检测按下 windows 键与 python - how can i detect pressing windows key with python 如何检测 Windows python3+ 中的组合键? - How can i detect key combinations in Windows python3+? 如何访问在Windows OS的Docker工具箱Linux容器中创建的项目目录? - How can I access the project directories that are created in the Docker toolbox Linux containers on my Windows OS? 如何使用 python 保护 windows 中用户的文件夹访问权限 - How can I secure folder access to the user in windows using python 使用 Python,如何访问 windows 网络上的共享文件夹? - Using Python, how can I access a shared folder on windows network? 如何在 Windows 操作系统上使用 Python 处理系统窗口? - How do I handle the system windows with Python on Windows OS? 如何在Windows上将Anaconda3 python设置为我的默认设置 - How can I set Anaconda3 python my default on windows
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM