module' 对象没有 'getusersitepackages' 属性

1 投票
1 回答
1362 浏览
提问于 2025-04-17 15:27

我正在学习这个Python教程,感觉自己好像漏掉了一些非常基础的东西。教程里有:

>>> import site
>>> site.getusersitepackages()
'/home/user/.local/lib/python3.2/site-packages'

但是我得到的是:

$ 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'

正如上面所说,我是在cygwin上运行Python 2.6.8

这是安装错误吗?

1 个回答

2

根据文档的说明,这个功能是在python2.7版本中加入的,而你现在使用的还是python 2.6版本。

撰写回答