【问题标题】:ImportError: No module named setuptools.command on Mac OS X within virtualenvImportError:在虚拟环境中的 Mac OS X 上没有名为 setuptools.command 的模块
【发布时间】:2016-11-29 09:33:19
【问题描述】:

尝试在虚拟环境中的 Mac OSX 上安装 Python pip 包(Django Rest Framework 文档,drfdocs):

这里是pip、python、easy_install的相关版本:

$ virtualenv --version
1.11.4

$ mkvirtualenv test
New python executable in test/bin/python
Installing setuptools, pip...done.

(test)$ python --version; which python
Python 2.7.10
/Users/me/.virtualenvs/test/bin/python

(test)$ pip --version; which pip
pip 1.5.4 from /Users/me/.virtualenvs/test/lib/python2.7/site-packages (python 2.7)
/Users/me/.virtualenvs/test/bin/pip

(test)$ easy_install --version; which easy_install
setuptools 2.2
/Users/me/.virtualenvs/test/bin/easy_install

(test)$ python -c "import setuptools.command; print setuptools.command"
<module 'setuptools.command' from '/Users/me/.virtualenvs/test/lib/python2.7/site-packages/setuptools/command/__init__.pyc'>

这是错误:

$ pip install drfdocs
Downloading/unpacking drfdocs
  Downloading drfdocs-0.0.11.tar.gz (771kB): 771kB downloaded
  Running setup.py (path:/Users/me/.virtualenvs/test/build/drfdocs/setup.py) egg_info for package drfdocs
    Traceback (most recent call last):
      File "<string>", line 3, in <module>
    ImportError: No module named setuptools.command
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):

  File "<string>", line 3, in <module>

ImportError: No module named setuptools.command

----------------------------------------
Cleaning up...
Command python setup.py egg_info failed with error code 1 in /Users/me/.virtualenvs/test/build/drfdocs
Storing debug log for failure in /Users/me/.pip/pip.log

我尝试了来自其他 Stack Overflow 答案 here 的各种修复,但都没有奏效。

$ pip install -U setuptools

也没有帮助。


编辑:根据要求:

(test)$ python -c "import setuptools; print setuptools.__file__; print setuptools.__version__"
/Users/me/.virtualenvs/test/lib/python2.7/site-packages/setuptools/__init__.pyc
2.2

编辑#2:我试过pip install pip --upgrade,所以现在我在pip==8.1.2

现在,当我尝试安装时,我得到一个稍微不同的错误:

(test)$ 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 setuptools
>>> exit()
(test)$ pip --version
pip 8.1.2 from /Users/me/.virtualenvs/test/lib/python2.7/site-packages (python 2.7)
(test)$ pip install drfdocs
Collecting drfdocs
  Using cached drfdocs-0.0.11.tar.gz
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
    ImportError: No module named setuptools

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/kc/00fkv5q91vz815b2jycc8cv40000gn/T/pip-build-olnkAD/drfdocs/

但为什么会发生这种情况仍然没有意义。

【问题讨论】:

  • 当你 pip freeze 时,你能在结果中看到 setuptools 吗?
  • 这个 sn-p 从 Python 交互式 shell 的输出是什么? import setuptools; setuptools.__file__; setuptools.__version__
  • @Justin:不,它没有。我的“测试”virtualenv 只看到“wsgiref==0.1.2”。
  • @lollercoaster 你试过文档了吗? pypi.python.org/pypi/setuptools python 2.7 有一个特定的部分
  • @lollercoaster 你用的是系统默认的python吗?如果是这样,我建议使用 brew 安装一个真实的,然后从中创建一个 virualenv。

标签: python django macos virtualenv virtualenvwrapper


【解决方案1】:

这是包中的一个错误。见issue #120

等待v0.1.0或下载package from PyPI,从这个包中删除site目录,安装补丁包。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-03
    • 2017-09-11
    • 1970-01-01
    • 2021-11-24
    • 1970-01-01
    相关资源
    最近更新 更多