Meghdeep Ray
Meghdeep Ray

Reputation: 5537

Python3 on Ubuntu giving errors on help() command

I used help() in the python3 shell on Ubuntu 14.04 I got this output Please help , don't know whats wrong.

Python 3.4.0 (default, Apr 11 2014, 13:05:11) 
[GCC 4.8.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> help()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.4/_sitebuiltins.py", line 98, in __call__
import pydoc
File "/usr/lib/python3.4/pydoc.py", line 65, in <module>
import platform
File "/home/omega/platform.py", line 2, in <module>
print("System    : ",platform.uname().system)
AttributeError: 'module' object has no attribute 'uname'
>>> 

Upvotes: 1

Views: 121

Answers (2)

abarnert
abarnert

Reputation: 365767

The problem is that platform is the name of a stdlib module, which help uses. By creating a module of your own with the same name that occurs before the stdlib in your sys.path, you're preventing Python from using the standard one.

The fact that your own platform module tries to use the stdlib module of the same name just compounds the problem. That isn't going to work; your import platform inside that module is just importing itself.

The solution is to not collide names like this. Look at the list of the standard modules, and don't create anything with the same name as any of them if you want to use features from that module, directly or indirectly.

In other words: Rename your platform.py to something else, or put it inside a package.

Upvotes: 2

GLHF
GLHF

Reputation: 4035

File "/home/omega/platform.py", line 2, in <module>
print("System    : ",platform.uname().system)

This is the problem, go to platform.py and fix it, it will be ok. It says, platform has not any method called uname you probably misstyped.

Upvotes: 0

Related Questions