I am going through the python tutorial and seem to be missing something very basic. The tutorial has:
>>> import site
>>> site.getusersitepackages()
'/home/user/.local/lib/python3.2/site-packages'
But I get the following:
$ python
Python 2.6.8 (unknown, Jun 9 2012, 11:30:32)
[GCC 4.5.3] on cygwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import site
>>> site.getusersitepackages()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'getusersitepackages'
As it says above, I am running Python 2.6.8 on cygwin.
Is this installation error?
According to the docs, this feature/function was added in python2.7 -- You're still on python 2.6
Related
$ python
Python 3.8.10 (default, Nov 14 2022, 12:59:47)
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import urllib
>>> urllib.request
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: module 'urllib' has no attribute 'request'
>>> urllib.request
<module 'urllib.request' from '/usr/lib/python3.8/urllib/request.py'>
Why is urllib.request recognized as an attribute the second time I try to access it?
Eventlet monkey patch seems breaking py3 select.poll() on my ENV (i try to install openstack ironic), But openstack group could not reproduce this issue, anyone knows why?
I can simply reproduce it by:
Python 3.6.9 (default, Nov 7 2019, 10:44:02)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import eventlet
>>>
>>> eventlet.monkey_patch()
>>> import select
>>> select.poll
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: module 'select' has no attribute 'poll'
>>> eventlet.version_info
(0, 25, 0)
>>>
It's intentional, as select.poll() is not "green".
See also: https://github.com/eventlet/eventlet/issues/608#issuecomment-612359458
I have a virtualenv venv where I installed mx-base and psycopg2 with pip:
$ pip freeze | grep "psyco\|mx"
egenix-mx-base==3.2.8
psycopg2==2.6
The basics of psycopg2 works but when using extensions I get exceptions like this:
Traceback (most recent call last):
File "/my_proj/my_code.py", line 32, in <module>
register_types()
File "/my_proj/my_code.py", line 28, in register_types
psycopg2.extensions.register_type(psycopg2._psycopg.MXDATETIME)
AttributeError: 'module' object has no attribute 'MXDATETIME'
Or:
ulf#kalla:~(0)(venv)$ python
Python 2.7.6 (default, Jun 22 2015, 17:58:13)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import psycopg2
>>> #Use mx.DateTime instead of pythons datetime, for compability reasons.
... psycopg2.extensions.register_type(psycopg2._psycopg.MXDATETIME)
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
AttributeError: 'module' object has no attribute 'MXDATETIME'
>>>
It seems that the installed version of psycopg2 lacks the mx-support.
How could I fix this?
You will probably need to build psycopg2 on your own, download the tar.gz, unzip, and then find the setup.cfg file, modify the mx_include parameter to be /lib/python2.7/site-packages/mx/DateTime/mxDateTime and then
python setup.py build_ext install
I am trying to use the pandas "cut" method, but am getting an object has no attribute error. I've imported pandas and it works for other commands. Is this a known issue or am I missing something? I restarted Python thinking this might just be a random bug but it doesn't seem to be...
Full error below:
python 2.7.3 (default, Sep 26 2013, 20:08:41)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pandas as pd
>>> day1 = pd.read_csv('nyt1.csv') #<-- THIS WORKS
>>> pd.cut(day1.Age,[18,24,34,44,54,64,],right=False)[:30] #<-- THIS DOES NOT?
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'cut'
>>> pd
<module 'pandas' from '/usr/lib/pymodules/python2.7/pandas/__init__.pyc'>
>>> pd.__version__
'0.7.0'
EDIT: Included the version of pandas.
The cut function was introduced in pandas v0.8.0. Update to a newer version and your code should work!
Using the code print('{0} is not'.format('That that is not')) in Python 3.1.1, I get the following error:
AttributeError: 'str' object has no attribute 'format'
when I delete the line Netbeans automatically inserted at the beginning:
from distutils.command.bdist_dumb import format
which itself causes an error of
ImportError: cannot import name format
What am I doing wrong here?
You must be running an older version of Python. This does work in Python 3.1.1+:
$ python3
Python 3.1.1+ (r311:74480, Nov 2 2009, 14:49:22)
[GCC 4.4.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> '{0} is not'.format('That that is not')
'That that is not is not'
You will, however, get this error in Python 2.5.4:
$ python2.5
Python 2.5.4 (r254:67916, Jan 20 2010, 21:44:03)
[GCC 4.4.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> '{0} is not'.format('That that is not')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'str' object has no attribute 'format'
This feature seems to have been backported to Python 2.6, so you won't get this error there. You must be running Python < 2.6.