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.
Related
mac 10.11osx,and mysql5.5 python 2.7(system) mysqldb1.2.5,but when i do "import MySQLdb",it wrong----------
Python 2.7.10 (default, Oct 23 2015, 19:19:21)
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import MySQLdb
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Python/2.7/site-packages/MySQL_python-1.2.4-py2.7-macosx-10.11-intel.egg/MySQLdb/__init__.py", line 19, in <module>
import _mysql
ImportError: dlopen(/Library/Python/2.7/site-packages/MySQL_python-1.2.4-py2.7-macosx-10.11-intel.egg/_mysql.so, 2): no suitable image found. Did find:
/Library/Python/2.7/site-packages/MySQL_python-1.2.4-py2.7-macosx-10.11-intel.egg/_mysql.so: mach-o, but wrong architecture
could someone tell me why?
I am trying to import psutil on python and this is what i get:
Python 2.7.7 (v2.7.7:f89216059edf, May 31 2014, 12:53:48)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import psutil
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/psutil/__init__.py", line 148, in <module>
import psutil._psosx as _psplatform
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/psutil/_psosx.py", line 29, in <module>
cext.TCPS_ESTABLISHED: _common.CONN_ESTABLISHED,
AttributeError: 'module' object has no attribute 'TCPS_ESTABLISHED'
$ python
Python 2.7.5 (default, Aug 25 2013, 00:04:04)
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import select
>>> select.poll
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'poll'
Instead of using poll, use select.kqueue() on OSX. It's similar to 'epoll' on Linux in that you can more efficiently register for types of file-descriptor / file system events which can be used in asynchronous code. Much more efficient than polling.
Otherwise, the equivalent is just running a blocking select.select() inside a while True: loop with some sort of timeout?
If you want to use poll in order to not rewrite a bunch of code for kqueue, it is built in to the python compiled from macports (macports.org). You just must specify that python instance explicitly (/opt/local/bin/python2.7 in my case) because OSX's python (/usr/bin/python) will by default be earlier in the search path.
Interestingly for future reference, this only comes up with a limited subset of the versions of python
user#hostname:~/ws/engine$ python
Python 2.7.9 (v2.7.9:648dcafa7e5f, Dec 10 2014, 10:10:46)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import select
>>> select.poll()
<select.poll object at 0x102415cc0>
>>> exit()
user#hostname:~/ws/engine$ python --version
Python 2.7.9
user#hostname:~/ws/engine$ workon py_2_7_10
(py_2_7_10) user#hostname:~/ws/engine$ python
Python 2.7.10 (default, Oct 23 2015, 19:19:21)
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import select
>>> select.poll()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'poll'
>>>
~/ws/engine$ uname -a
Darwin hostname 15.4.0 Darwin Kernel Version 15.4.0: Fri Feb 26 22:08:05 PST 2016; root:xnu-3248.40.184~3/RELEASE_X86_64 x86_64
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.
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.