简体   繁体   中英

Setting environment variable python

I am trying to set up the environment variable to point to following however it gives me error

 os.environ["PATH"]= "C:\APPS\ORACLE\product\12.1.0\Client_64\Instantclient"

I get the error "Invalid character or identifier"

I am able to navigate the above path so not sure what is failing.

Try passing it as a raw string (no need to escape backslashes or anything else then):

 os.environ["PATH"]= r"C:\APPS\ORACLE\product\12.1.0\Client_64\Instantclient"

Note the prefixed r before the string.

You need to escape the 1 in 12

import os
os.environ["PATH"] = "C:\APPS\ORACLE\product\\12.1.0\Client_64\Instantclient"
print(os.environ['PATH'])
#C:\APPS\ORACLE\product\12.1.0\Client_64\Instantclient

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM