Using Python 2.7 on Ubuntu 12.10 64Bit gives me the following trouble:
Python 2.7.3 (default, Sep 26 2012, 21:51:14)
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import ctypes
>>> ctypes.c_bool()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'c_bool'
>>>
How can I fix this problem?
Do you have a file called "ctypes.py" in the directory where you are working? If so, move it or (preferably) rename it.
Related
I am trying to import PyQt5 module in a custom python environment but it fails.
I have tested it with the system python and works fine
juan#juansphd:~/blender-2.82a-linux64/2.82/python/bin$ python3
Python 3.6.9 (default, Apr 18 2020, 01:56:04)
[GCC 8.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import PyQt5.QtCore
>>>
but when I run python3 of my custom environment, it fails to load it
juan#juansphd:~/blender-2.82a-linux64/2.82/python/bin$ ./python3.7m
Python 3.7.4 (default, Oct 8 2019, 15:23:02)
[GCC 6.3.1 20170216 (Red Hat 6.3.1-3)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import PyQt5.QtCore
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'PyQt5'
>>>
I have tried adding /usr/lib/python3/dist-packages, where PyQt5 is installed, into the sys.path but doesnt work neither
>>> sys.path.append("/usr/lib/python3/dist-packages")
>>> import PyQt5.QtCore
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'PyQt5.QtCore'
>>>
How should I import the module?
What is wrong here?
$ python -V
Python 2.7.5
I have installed pip install pexcept
now when i load it
$ python
Python 2.7.5 (default, Jul 13 2018, 13:06:57)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-28)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pexpect
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "pexpect.py", line 10, in <module>
child = pexpect.spawn('ssh %s#%s' % (switch_un, switch_ip))
AttributeError: 'module' object has no attribute 'spawn'
>>>
EDIT
Running Linux CentOS 7.x version (64bit)
As stated HERE pexpect is mainly used for UNIX based operation systems. This error comes up when using windows.
This question already has answers here:
Importing installed package from script with the same name raises "AttributeError: module has no attribute" or an ImportError or NameError
(2 answers)
Closed 1 year ago.
I am unable to import decimal in the terminal for Python 2.7 or 3.3.
Here are the errors I get:
Python 3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 01:25:11)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import decimal
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/decimal.py", line 3849, in <module>
_numbers.Number.register(Decimal)
AttributeError: 'module' object has no attribute 'Number'
or Python 2.7
Python 2.7.2 (default, Oct 11 2012, 20:14:37)
[GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import decimal
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/decimal.py", line 141, in <module>
import numbers as _numbers
File "numbers.py", line 34, in <module>
assert x / y == 2.5 # true division of x by y
AssertionError
How to I import decimal?
Is there numbers.py in current working directory?
That could be the reason of the problem, because that prevent import of standard library module numbers.
How to import decimal in Python3:
from decimal import Decimal
a = Decimal(25)
print(type(a))
//prints <class 'decimal.Decimal'>
I know I'm late to the game, I ran into this issue too until I realized what I did wrong.
If you have named one your own files "decimal.py", your project will have two modules with the same name "decimal", which would confuse your IDE.
Change the name of your file and try again.
[root#proxy-001 scripts]# python
Python 2.6.6 (r266:84292, Dec 7 2011, 20:48:22)
[GCC 4.4.6 20110731 (Red Hat 4.4.6-3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import MySQLdb
>>> from MySQLdb import cursors
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib64/python2.6/site-packages/MySQLdb/cursors.py", line 16, in <module>
insert_values= re.compile(restr)
AttributeError: 'module' object has no attribute 'compile'
any ideas?
Same error:
[root#proxy-001 scripts]# python
Python 2.6.6 (r266:84292, Dec 7 2011, 20:48:22)
[GCC 4.4.6 20110731 (Red Hat 4.4.6-3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import re
>>> import MySQLdb
>>> import MySQLdb.cursors
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib64/python2.6/site-packages/MySQLdb/cursors.py", line 16, in <module>
insert_values= re.compile(restr)
AttributeError: 'module' object has no attribute 'compile'
edited: /usr/lib64/python2.6/site-packages/MySQLdb/cursors.py
added:
print re
print dir(re)
insert_values= re.compile(restr)
[root#proxy-001 scripts]# python
Python 2.6.6 (r266:84292, Dec 7 2011, 20:48:22)
[GCC 4.4.6 20110731 (Red Hat 4.4.6-3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import re
>>> import MySQLdb
>>> import MySQLdb.cursors
<module 're' from 're.pyc'>
['__builtins__', '__doc__', '__file__', '__name__', '__package__', 'main', 'modify_url', 'sys']
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib64/python2.6/site-packages/MySQLdb/cursors.py", line 18, in <module>
insert_values= re.compile(restr)
AttributeError: 'module' object has no attribute 'compile'
>>>
That's strange. Do you have a module named "re.py" somewhere in your Python path which is shadowing the "real" re module?
UPDATE: Okay, based on your edit, I'm now certain that you have an re.py module which is shadowing the real one, and if I'm reading the path correctly, it's in the very directory you're calling the program from! Did you write an re.py module which has one "modify_url" function?
Anyway, find that re.py -- it's probably in your scripts directory -- and rename it to something else.
I've installed PyObjC on my Mac, but I can't get it to work at all. Even trying to import the AddressBook class just fails immediately.
Python 2.7.2 (v2.7.2:8527427914a2, Jun 11 2011, 15:22:34)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import AddressBook
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "AddressBook.py", line 17, in <module>
('Last Name', AddressBook.kABLastNameProperty),
AttributeError: 'module' object has no attribute 'kABLastNameProperty'
Does anyone have any ideas as to how to solve this issue? Thanks.
You appear to have a conflicting file named AddressBook.py in your working directory. Rename or remove it or change to another directory.