User avatar
RogerW
Posts: 286
Joined: Sat Dec 20, 2014 12:15 pm
Location: London UK

os.getlogin() fails under Jessie

Tue Sep 29, 2015 4:04 pm

I do not know if this should be in the Rasbian forum. If I start python from the command line os.getlogin() works. However if I run in the GUI (startx) it fails, even in a command window. The error says 'No such file or directory'.

User avatar
PeterO
Posts: 5351
Joined: Sun Jul 22, 2012 4:14 pm

Re: os.getlogin() fails under Jessie

Tue Sep 29, 2015 4:07 pm

I suspect a relative path or something similar in your code ! Show us the whole error message and the code you are running.
PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

User avatar
RogerW
Posts: 286
Joined: Sat Dec 20, 2014 12:15 pm
Location: London UK

Re: os.getlogin() fails under Jessie

Tue Sep 29, 2015 4:17 pm

Sorry but I don't know how to get a screenshot from the pi ont my PC. It works if I putty (SSH) into the pi.
Start idle (or idle3) and then
>>>import os
>>>os.getlogin()

plugwash
Forum Moderator
Forum Moderator
Posts: 3502
Joined: Wed Dec 28, 2011 11:45 pm

Re: os.getlogin() fails under Jessie

Tue Sep 29, 2015 4:22 pm

https://bugs.debian.org/cgi-bin/bugrepo ... bug=743500

says

os.getlogin() is almost never what you want. The documentation says[0]
that “for most purposes, it is more useful to use the environment
variable LOGNAME to find out who the user is, or
pwd.getpwuid(os.getuid())[0] to get the login name of the currently
effective user id.”

User avatar
RogerW
Posts: 286
Joined: Sat Dec 20, 2014 12:15 pm
Location: London UK

Re: os.getlogin() fails under Jessie

Tue Sep 29, 2015 4:32 pm

Interesting but that is unix only. getlogin() works in Windows. What really puzzled me is why it works from a command line but not under X.

User avatar
PeterO
Posts: 5351
Joined: Sun Jul 22, 2012 4:14 pm

Re: os.getlogin() fails under Jessie

Tue Sep 29, 2015 8:47 pm

RogerW wrote:Interesting but that is unix only. getlogin() works in Windows. What really puzzled me is why it works from a command line but not under X.
I confirm it doesn't work under X on Jessie but does work in a console.
PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

Return to “Python”