python怎么设置环境变量

导入包 os

importos
os.environ["NAME"]=VALUE

NAME就是环境变量名,value就是你要设定的值

同理寻找环境变量可以用

print(os.environ["NAME"])
#或
os.environ.get("NAME")

Ⅱ python os模块怎么得到环境变量

importos
one=os.environ.get('path')
print(one)

get()括号里面的内容为你需要查询的环境变量。在Windows下,path输出该path变量中赋值的路径。

Ⅲ 怎样在mac设置python的环境变量

Python设置环境变量的具体方法:
在系统变量里找到PATH,双击PATH,在结尾加上 ";C:\Python25"(不要引号)确定即可。接下来:运行->cmd,在命令行窗口中输入python,即可运行。
输入
print "Hello World!"

应该有如下结果:
>>> print "Hello World!" Hello World!

在命令行窗口中输入python文章中Python设置环境变量的分类:Python编程
#!/usr/bin/python
#FileName:setDbgServerBridge.py
import os
path=os.environ["HOME"] + "/lib"
if os.path.exists(path)==False :
os.makedirs(path)
else:
print "exists"
dstFile=path + "/libeclipse_ct_debug_core_
utility_DbgServerBridge.so"
srcFile="./libeclipse_ct_debug_core_
utility_DbgServerBridge.so"
commandLine = "cp ./libeclipse_ct_debug_
core_utility_DbgServerBridge.so " + dstFile
os.system(commandLine)
os.environ["LD_LIBRARY_PATH"]=path
以上就是对Python设置环境变量的具体方法。

Ⅳ linux python os.environ 为什么不一样

这个获取的是执行程序所在的操作系统的环境变量,当然不一样

Ⅳ python需要设置哪些环境变量我只知道一个PYTHONHOME指向安装目录。

1、首先,右键点击-计算机(此电脑),点击进入属性,如图所示。

Ⅵ python os模块怎么使用

一、os模块概述

Python os模块包含普遍的操作系统功能。如果你希望你的程序能够与平台无关的话,这个模块是尤为重要的。(一语中的)

二、常用方法

1、os.name

输出字符串指示正在使用的平台。如果是window 则用'nt'表示,对于Linux/Unix用户,它是'posix'。

2、os.getcwd()

函数得到当前工作目录,即当前Python脚本工作的目录路径。

3、os.listdir()

返回指定目录下的所有文件和目录名。

>>> os.listdir(os.getcwd())
['Django', 'DLLs', 'Doc', 'include', 'Lib', 'libs', 'LICENSE.txt', 'MySQL-python-wininst.log', 'NEWS.txt', 'PIL-wininst.log', 'python.exe', 'pythonw.exe', 'README.txt', 'RemoveMySQL-python.exe', 'RemovePIL.exe', 'Removesetuptools.exe', 'Scripts', 'setuptools-wininst.log', 'tcl', 'Tools', 'w9xpopen.exe']
>>>

4、os.remove()

删除一个文件。

5、os.system()

运行shell命令。

>>> os.system('dir')
0
>>> os.system('cmd') #启动dos

6、os.sep 可以取代操作系统特定的路径分割符。

7、os.linesep字符串给出当前平台使用的行终止符

>>> os.linesep
'\r\n' #Windows使用'\r\n',Linux使用'\n'而Mac使用'\r'。
>>> os.sep
'\\' #Windows
>>>

8、os.path.split()

函数返回一个路径的目录名和文件名

>>> os.path.split('C:\\Python25\\abc.txt')
('C:\\Python25', 'abc.txt')

9、os.path.isfile()和os.path.isdir()函数分别检验给出的路径是一个文件还是目录。

>>> os.path.isdir(os.getcwd())
True
>>> os.path.isfile('a.txt')
False

10、os.path.exists()函数用来检验给出的路径是否真地存在

>>> os.path.exists('C:\\Python25\\abc.txt')
False
>>> os.path.exists('C:\\Python25')
True
>>>

11、os.path.abspath(name):获得绝对路径

12、os.path.normpath(path):规范path字符串形式

13、os.path.getsize(name):获得文件大小,如果name是目录返回0L

14、os.path.splitext():分离文件名与扩展名

>>> os.path.splitext('a.txt')
('a', '.txt')

15、os.path.join(path,name):连接目录与文件名或目录

>>> os.path.join('c:\\Python','a.txt')
'c:\\Python\\a.txt'
>>> os.path.join('c:\\Python','f1')
'c:\\Python\\f1'
>>>

16、os.path.basename(path):返回文件名

>>> os.path.basename('a.txt')
'a.txt'
>>> os.path.basename('c:\\Python\\a.txt')
'a.txt'
>>>

17、os.path.dirname(path):返回文件路径

>>> os.path.dirname('c:\\Python\\a.txt')
'c:\\Python'

Ⅶ python编程中os.environ()会列出一个字典,谁知道里面的每个键是干啥用的

操作系统的环境变量
可以在操作系统中运行set来看.
具体的作用是操作系统定义的,.和python一般没有关系

Ⅷ python os模块怎么使用

常用方法:

1. os.name——判断现在正在实用的平台,Windows 返回 ‘nt'; Linux 返回’posix'。

2. os.getcwd()——得到当前工作的目录。

3. os.listdir()——指定所有目录下所有的文件和目录名。

例:

Ⅸ python os.putenv 是这样用吗

>>>>os.getenv("PATH")
>'/usr/joebin:/usr/local/bin:/usr/bin:/bin:/usr/games/bin:/usr/sbin:/sbin:~/bin'
>>>>os.putenv("PATH","/")
>>>>os.getenv("PATH")
>'/usr/joebin:/usr/local/bin:/usr/bin:/bin:/usr/games/bin:/usr/sbin:/sbin:~/bin'
>
>
>>>>os.getenv("FOO")
>>>>os.putenv("FOO","BAR")
>>>>os.getenv("FOO")

从上述我们不难看出putenv() 无效。

查看帮助,搜索了下:

Quoting (retyping) from the getenv docs, "...however, calls to putenv()
don't update os.environ, so it is actually preferable to assign to items
of os.environ."

调用putenv()无法更新os.environ

As to why, I'm not at all sure. Only that many environments don't
support putenv(). But why that should stop it working in the obvious
way ? No idea.

os.environ is not an ordinary dict, it's a "mapping object". And among
other things, when you modify os.environ, Python will call putenv.
Quoting from the os.environ docs, "If the platform supports the putenv()
function, this mapping may be used to modify the environment. putenv()
will be called automatically wehn the mapping is modified."
#当我们更新os.environ的时候,会自动调用putenv()


In other words, you shouldn't use putenv(), but instead modify os.environ.

#因此我们可以不用putenv了,以更新os.environ来实现调用putenv