Python Forum
Key Error: os.environ["HOME"]
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Key Error: os.environ["HOME"]
#1
I run the python script in python3.8 and this return an key error
Error:
raise KeyError(key) from None E KeyError: 'HOME'
Line No: 20 code
modelFile = os.environ["HOME"] + "\\models\\" + "Articles_word2vec.txt"
test_clustering.py:None (test_clustering.py)
Error:
test_clustering.py:20: in <module> modelFile = os.environ["HOME"] + "\\models\\" + "Articles_word2vec.txt" D:\Python3.8.0\Python\lib\os.py:675: in __getitem__ raise KeyError(key) from None E KeyError: 'HOME'
Reply
#2
Windows doesn't have HOME

try

os.path.expanduser('~')
or you can use

print(os.environ)


to show all environment variables
Reply
#3
@Axel_Erfurt in both case return same error
modelFile = os.environ['HOME'] + "\\models\\" + "glove.6B.300d_word2vec.txt"
print(os.environ)
also this case return me another error empty
modelFile = os.path.expanduser('~') + "\\models\\" + "glove.6B.300d_word2vec.txt"
print(os.environ)
error
Error:
============================== warnings summary =============================== ..\..\Python3.8.0\Python\lib\site-packages\scipy\sparse\sparsetools.py:21 D:\Python3.8.0\Python\lib\site-packages\scipy\sparse\sparsetools.py:21: DeprecationWarning: `scipy.sparse.sparsetools` is deprecated! scipy.sparse.sparsetools is a private module for scipy.sparse, and should not be used. _deprecated() -- Docs: https://docs.pytest.org/en/stable/warnings.html ============================= 1 warning in 3.04s ============================== Process finished with exit code 5 Empty suite
Reply
#4
does this work?

os.environ['USERPROFILE'] 
Reply
#5
@Axel_Erfurt same is i update the post sparse\sparsetools.py:21 error
Reply
#6
What is the output of

print(os.environ)
Reply
#7
@Axel_Erfurt same output as above
Reply
#8
You should get an output

import os

print(os.environ)
This is what I get on Windows, USERPROFILE is correct

Output:
environ({'PROCESSOR_REVISION': '2a07', 'PATHEXT': '.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.PY', 'PROCESSOR_LEVEL': '6', 'ALLUSERSPROFILE': 'C:\\Dokumente und Einstellungen\\All Users', 'TK_LIBRARY': 'C:\\Python34\\tcl\\tk8.6', 'NUMBER_OF_PROCESSORS': '2', 'HOMEDRIVE': 'C:', 'ASL.LOG': 'Destination=file', 'TCL_LIBRARY': 'C:\\Python34\\tcl\\tcl8.6', 'SYSTEMROOT': 'C:\\WINDOWS', 'SYSTEMDRIVE': 'C:', 'LOGONSERVER': '\\\\ESS-09BAAD42A5C', 'PROCESSOR_ARCHITECTURE': 'x86', 'TIX_LIBRARY': 'C:\\Python34\\tcl\\tix8.4.3', 'FP_NO_HOST_CHECK': 'NO', 'HOME': 'C:\\Dokumente und Einstellungen\\Brian', 'OS': 'Windows_NT', 'USERNAME': 'Brian', 'WINDIR': 'C:\\WINDOWS', 'COMSPEC': 'C:\\WINDOWS\\system32\\cmd.exe', 'SESSIONNAME': 'Console', 'HOMEPATH': '\\Dokumente und Einstellungen\\Brian', 'PATH': 'C:\\Python34\\Lib\\site-packages\\PyQt5;C:\\Python34\\;C:\\Python34\\Scripts;C:\\WINDOWS\\system32;C:\\WINDOWS;C:\\WINDOWS\\System32\\Wbem', 'USERPROFILE': 'C:\\Dokumente und Einstellungen\\Brian', 'TEMP': 'C:\\DOKUME~1\\Brian\\LOKALE~1\\Temp', 'PROCESSOR_IDENTIFIER': 'x86 Family 6 Model 42 Stepping 7, GenuineIntel', 'CLIENTNAME': 'Console', 'COMPUTERNAME': 'ESS-09BAAD42A5C', 'COMMONPROGRAMFILES': 'C:\\Programme\\Gemeinsame Dateien', 'TMP': 'C:\\DOKUME~1\\Brian\\LOKALE~1\\Temp', 'APPDATA': 'C:\\Dokumente und Einstellungen\\Brian\\Anwendungsdaten', 'USERDOMAIN': 'ESS-09BAAD42A5C', 'PROGRAMFILES': 'C:\\Programme'})
Reply
#9
@Axel_Erfurt for my codes this error
============================= warnings summary ===============================
..\..\Python3.8.0\Python\lib\site-packages\scipy\sparse\sparsetools.py:21
D:\Python3.8.0\Python\lib\site-packages\scipy\sparse\sparsetools.py:21: DeprecationWarning: scipy.sparse.sparsetools is deprecated!
scipy.sparse.sparsetools is a private module for scipy.sparse, and should not be used.
_deprecated()

-- Docs: https://docs.pytest.org/en/stable/warnings.html
============================= 1 warning in 2.02s ==============================

Process finished with exit code 5

Empty suite
Reply
#10
it shows on the line 21 likes this sparsetool.py an extra module that randomly generated during run codes
Error:
def _deprecated(): pass del deprecate try: _deprecated() except DeprecationWarning: # don't fail import if DeprecationWarnings raise error -- works around # the situation with NumPy's test framework pass from ._sparsetools import *
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Home Directory pgoosen 9 6,270 Oct-15-2020, 12:37 PM
Last Post: DeaD_EyE
  os.environ not setting current shell variables in Windows? brian6667 2 10,747 Apr-26-2017, 12:59 PM
Last Post: brian6667

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020