【问题标题】:Can't install datasets package via pip无法通过 pip 安装数据集包
【发布时间】:2016-11-04 22:46:24
【问题描述】:

我正在尝试运行一个需要数据集 python 包的脚本。我尝试通过调用使用 pip 安装它,但未成功:

pip install datasets

我知道这不起作用,因为当我运行脚本时,我收到消息:

Traceback (most recent call last):
  File "lda.py", line 2, in <module>
    import lda
  File "/Users/deepthought/lda.py", line 3, in <module>
    import datasets
ImportError: No module named datasets

我已经通过自制软件安装了 python。

当我运行 pip install datasets 时出现错误:

Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/ch/84cpkwc52zx0rsh4k5v4_7h40000gn/T/pip-build-gZWyT3/datasets/

我对编写 python 脚本或使用 OS X 的引擎盖还很陌生,所以我有可能错过了一些基本的东西。

我已经研究并试图克服这个问题大约一周了,包括查看 stackoverflow.com 上的类似问题,并且在此期间一直没有超过这个阶段。我正在完成的教程之一告诉我编辑 ~/.profile

这个是这样的:

# The orginal version is saved in .profile.pysave
#PATH="/Library/Frameworks/Python.framework/Versions/3.5/bin:${PATH}"
#export PATH
export PATH=/usr/local/bin:/usr/local/sbin:$PATH

/etc/paths 包含:

/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin

我正在运行 OS X El Capitan - 10.11.5 (15F34) Python 2.7.11

Brew doctor 标记了多个项目,但我不知道是否值得修复一个/所有项目:

Warning: Your XQuartz (2.7.7) is outdated
Please install XQuartz 2.7.9:
  https://xquartz.macosforge.org

Warning: Python is installed at /Library/Frameworks/Python.framework

Homebrew only supports building against the System-provided Python or a
brewed Python. In particular, Pythons installed to /Library can interfere
with other software installs.

Warning: Unbrewed dylibs were found in /usr/local/lib.
If you didn't put them there on purpose they could cause problems when
building Homebrew formulae, and may need to be deleted.

Unexpected dylibs:
    /usr/local/lib/libtcl8.6.dylib
    /usr/local/lib/libtk8.6.dylib

Warning: Unbrewed header files were found in /usr/local/include.
If you didn't put them there on purpose they could cause problems when
building Homebrew formulae, and may need to be deleted.

Unexpected header files:
    /usr/local/include/fakemysql.h
    /usr/local/include/fakepq.h
    /usr/local/include/fakesql.h
    /usr/local/include/itcl.h
    /usr/local/include/itcl2TclOO.h
    /usr/local/include/itclDecls.h
    /usr/local/include/itclInt.h
    /usr/local/include/itclIntDecls.h
    /usr/local/include/itclMigrate2TclCore.h
    /usr/local/include/itclTclIntStubsFcn.h
    /usr/local/include/mysqlStubs.h
    /usr/local/include/node/ares.h
    /usr/local/include/node/ares_version.h
    /usr/local/include/node/nameser.h
    /usr/local/include/node/node.h
    /usr/local/include/node/node_buffer.h
    /usr/local/include/node/node_internals.h
    /usr/local/include/node/node_object_wrap.h
    /usr/local/include/node/node_version.h
    /usr/local/include/node/openssl/opensslconf.h
    /usr/local/include/node/uv-private/ngx-queue.h
    /usr/local/include/node/uv-private/stdint-msvc2008.h
    /usr/local/include/node/uv-private/tree.h
    /usr/local/include/node/uv-private/uv-bsd.h
    /usr/local/include/node/uv-private/uv-darwin.h
    /usr/local/include/node/uv-private/uv-linux.h
    /usr/local/include/node/uv-private/uv-sunos.h
    /usr/local/include/node/uv-private/uv-unix.h
    /usr/local/include/node/uv-private/uv-win.h
    /usr/local/include/node/uv.h
    /usr/local/include/node/v8-debug.h
    /usr/local/include/node/v8-preparser.h
    /usr/local/include/node/v8-profiler.h
    /usr/local/include/node/v8-testing.h
    /usr/local/include/node/v8.h
    /usr/local/include/node/v8stdint.h
    /usr/local/include/node/zconf.h
    /usr/local/include/node/zlib.h
    /usr/local/include/odbcStubs.h
    /usr/local/include/pqStubs.h
    /usr/local/include/tcl.h
    /usr/local/include/tclDecls.h
    /usr/local/include/tclOO.h
    /usr/local/include/tclOODecls.h
    /usr/local/include/tclPlatDecls.h
    /usr/local/include/tclThread.h
    /usr/local/include/tclTomMath.h
    /usr/local/include/tclTomMathDecls.h
    /usr/local/include/tdbc.h
    /usr/local/include/tdbcDecls.h
    /usr/local/include/tdbcInt.h
    /usr/local/include/tk.h
    /usr/local/include/tkDecls.h
    /usr/local/include/tkPlatDecls.h

Warning: Unbrewed .pc files were found in /usr/local/lib/pkgconfig.
If you didn't put them there on purpose they could cause problems when
building Homebrew formulae, and may need to be deleted.

Unexpected .pc files:
    /usr/local/lib/pkgconfig/tcl.pc
    /usr/local/lib/pkgconfig/tk.pc

Warning: Unbrewed static libraries were found in /usr/local/lib.
If you didn't put them there on purpose they could cause problems when
building Homebrew formulae, and may need to be deleted.

Unexpected static libraries:
    /usr/local/lib/libtclstub8.6.a
    /usr/local/lib/libtkstub8.6.a

Warning: You have unlinked kegs in your Cellar
Leaving kegs unlinked can lead to build-trouble and cause brews that depend on
those kegs to fail to run properly once built. Run `brew link` on these:
    git
    python3

Warning: Broken symlinks were found. Remove them with `brew prune`:
    /usr/local/bin/github
    /usr/local/lib/perl5/site_perl/Git/I18N.pm
    /usr/local/lib/perl5/site_perl/Git/IndexInfo.pm
    /usr/local/lib/perl5/site_perl/Git/SVN/Editor.pm
    /usr/local/lib/perl5/site_perl/Git/SVN/Fetcher.pm
    /usr/local/lib/perl5/site_perl/Git/SVN/GlobSpec.pm
    /usr/local/lib/perl5/site_perl/Git/SVN/Log.pm
    /usr/local/lib/perl5/site_perl/Git/SVN/Memoize/YAML.pm
    /usr/local/lib/perl5/site_perl/Git/SVN/Migration.pm
    /usr/local/lib/perl5/site_perl/Git/SVN/Prompt.pm
    /usr/local/lib/perl5/site_perl/Git/SVN/Ra.pm
    /usr/local/lib/perl5/site_perl/Git/SVN/Utils.pm
    /usr/local/lib/perl5/site_perl/Git/SVN.pm
    /usr/local/lib/perl5/site_perl/Git.pm
    /usr/local/share/git-core/templates/description
    /usr/local/share/git-core/templates/hooks/applypatch-msg.sample
    /usr/local/share/git-core/templates/hooks/commit-msg.sample
    /usr/local/share/git-core/templates/hooks/post-update.sample
    /usr/local/share/git-core/templates/hooks/pre-applypatch.sample
    /usr/local/share/git-core/templates/hooks/pre-commit.sample
    /usr/local/share/git-core/templates/hooks/pre-push.sample
    /usr/local/share/git-core/templates/hooks/pre-rebase.sample
    /usr/local/share/git-core/templates/hooks/prepare-commit-msg.sample
    /usr/local/share/git-core/templates/hooks/update.sample
    /usr/local/share/git-core/templates/info/exclude
    /usr/local/share/man/man1/git-add.1
    /usr/local/share/man/man1/git-am.1
    /usr/local/share/man/man1/git-annotate.1
    /usr/local/share/man/man1/git-apply.1
    /usr/local/share/man/man1/git-archimport.1
    /usr/local/share/man/man1/git-archive.1
    /usr/local/share/man/man1/git-bisect.1
    /usr/local/share/man/man1/git-blame.1
    /usr/local/share/man/man1/git-branch.1
    /usr/local/share/man/man1/git-bundle.1
    /usr/local/share/man/man1/git-cat-file.1
    /usr/local/share/man/man1/git-check-attr.1
    /usr/local/share/man/man1/git-check-ignore.1
    /usr/local/share/man/man1/git-check-mailmap.1
    /usr/local/share/man/man1/git-check-ref-format.1
    /usr/local/share/man/man1/git-checkout-index.1
    /usr/local/share/man/man1/git-checkout.1
    /usr/local/share/man/man1/git-cherry-pick.1
    /usr/local/share/man/man1/git-cherry.1
    /usr/local/share/man/man1/git-citool.1
    /usr/local/share/man/man1/git-clean.1
    /usr/local/share/man/man1/git-clone.1
    /usr/local/share/man/man1/git-column.1
    /usr/local/share/man/man1/git-commit-tree.1
    /usr/local/share/man/man1/git-commit.1
    /usr/local/share/man/man1/git-config.1
    /usr/local/share/man/man1/git-count-objects.1
    /usr/local/share/man/man1/git-credential-cache--daemon.1
    /usr/local/share/man/man1/git-credential-cache.1
    /usr/local/share/man/man1/git-credential-store.1
    /usr/local/share/man/man1/git-credential.1
    /usr/local/share/man/man1/git-cvsexportcommit.1
    /usr/local/share/man/man1/git-cvsimport.1
    /usr/local/share/man/man1/git-cvsserver.1
    /usr/local/share/man/man1/git-daemon.1
    /usr/local/share/man/man1/git-describe.1
    /usr/local/share/man/man1/git-diff-files.1
    /usr/local/share/man/man1/git-diff-index.1
    /usr/local/share/man/man1/git-diff-tree.1
    /usr/local/share/man/man1/git-diff.1
    /usr/local/share/man/man1/git-difftool.1
    /usr/local/share/man/man1/git-fast-export.1
    /usr/local/share/man/man1/git-fast-import.1
    /usr/local/share/man/man1/git-fetch-pack.1
    /usr/local/share/man/man1/git-fetch.1
    /usr/local/share/man/man1/git-filter-branch.1
    /usr/local/share/man/man1/git-fmt-merge-msg.1
    /usr/local/share/man/man1/git-for-each-ref.1
    /usr/local/share/man/man1/git-format-patch.1
    /usr/local/share/man/man1/git-fsck-objects.1
    /usr/local/share/man/man1/git-fsck.1
    /usr/local/share/man/man1/git-gc.1
    /usr/local/share/man/man1/git-get-tar-commit-id.1
    /usr/local/share/man/man1/git-grep.1
    /usr/local/share/man/man1/git-gui.1
    /usr/local/share/man/man1/git-hash-object.1
    /usr/local/share/man/man1/git-help.1
    /usr/local/share/man/man1/git-http-backend.1
    /usr/local/share/man/man1/git-http-fetch.1
    /usr/local/share/man/man1/git-http-push.1
    /usr/local/share/man/man1/git-imap-send.1
    /usr/local/share/man/man1/git-index-pack.1
    /usr/local/share/man/man1/git-init-db.1
    /usr/local/share/man/man1/git-init.1
    /usr/local/share/man/man1/git-instaweb.1
    /usr/local/share/man/man1/git-log.1
    /usr/local/share/man/man1/git-lost-found.1
    /usr/local/share/man/man1/git-ls-files.1
    /usr/local/share/man/man1/git-ls-remote.1
    /usr/local/share/man/man1/git-ls-tree.1
    /usr/local/share/man/man1/git-mailinfo.1
    /usr/local/share/man/man1/git-mailsplit.1
    /usr/local/share/man/man1/git-merge-base.1
    /usr/local/share/man/man1/git-merge-file.1
    /usr/local/share/man/man1/git-merge-index.1
    /usr/local/share/man/man1/git-merge-one-file.1
    /usr/local/share/man/man1/git-merge-tree.1
    /usr/local/share/man/man1/git-merge.1
    /usr/local/share/man/man1/git-mergetool--lib.1
    /usr/local/share/man/man1/git-mergetool.1
    /usr/local/share/man/man1/git-mktag.1
    /usr/local/share/man/man1/git-mktree.1
    /usr/local/share/man/man1/git-mv.1
    /usr/local/share/man/man1/git-name-rev.1
    /usr/local/share/man/man1/git-notes.1
    /usr/local/share/man/man1/git-p4.1
    /usr/local/share/man/man1/git-pack-objects.1
    /usr/local/share/man/man1/git-pack-redundant.1
    /usr/local/share/man/man1/git-pack-refs.1
    /usr/local/share/man/man1/git-parse-remote.1
    /usr/local/share/man/man1/git-patch-id.1
    /usr/local/share/man/man1/git-peek-remote.1
    /usr/local/share/man/man1/git-prune-packed.1
    /usr/local/share/man/man1/git-prune.1
    /usr/local/share/man/man1/git-pull.1
    /usr/local/share/man/man1/git-push.1
    /usr/local/share/man/man1/git-quiltimport.1
    /usr/local/share/man/man1/git-read-tree.1
    /usr/local/share/man/man1/git-rebase.1
    /usr/local/share/man/man1/git-receive-pack.1
    /usr/local/share/man/man1/git-reflog.1
    /usr/local/share/man/man1/git-relink.1
    /usr/local/share/man/man1/git-remote-ext.1
    /usr/local/share/man/man1/git-remote-fd.1
    /usr/local/share/man/man1/git-remote-testgit.1
    /usr/local/share/man/man1/git-remote.1
    /usr/local/share/man/man1/git-repack.1
    /usr/local/share/man/man1/git-replace.1
    /usr/local/share/man/man1/git-repo-config.1
    /usr/local/share/man/man1/git-request-pull.1
    /usr/local/share/man/man1/git-rerere.1
    /usr/local/share/man/man1/git-reset.1
    /usr/local/share/man/man1/git-rev-list.1
    /usr/local/share/man/man1/git-rev-parse.1
    /usr/local/share/man/man1/git-revert.1
    /usr/local/share/man/man1/git-rm.1
    /usr/local/share/man/man1/git-send-email.1
    /usr/local/share/man/man1/git-send-pack.1
    /usr/local/share/man/man1/git-sh-i18n--envsubst.1
    /usr/local/share/man/man1/git-sh-i18n.1
    /usr/local/share/man/man1/git-sh-setup.1
    /usr/local/share/man/man1/git-shell.1
    /usr/local/share/man/man1/git-shortlog.1
    /usr/local/share/man/man1/git-show-branch.1
    /usr/local/share/man/man1/git-show-index.1
    /usr/local/share/man/man1/git-show-ref.1
    /usr/local/share/man/man1/git-show.1
    /usr/local/share/man/man1/git-stage.1
    /usr/local/share/man/man1/git-stash.1
    /usr/local/share/man/man1/git-status.1
    /usr/local/share/man/man1/git-stripspace.1
    /usr/local/share/man/man1/git-submodule.1
    /usr/local/share/man/man1/git-svn.1
    /usr/local/share/man/man1/git-symbolic-ref.1
    /usr/local/share/man/man1/git-tag.1
    /usr/local/share/man/man1/git-tar-tree.1
    /usr/local/share/man/man1/git-unpack-file.1
    /usr/local/share/man/man1/git-unpack-objects.1
    /usr/local/share/man/man1/git-update-index.1
    /usr/local/share/man/man1/git-update-ref.1
    /usr/local/share/man/man1/git-update-server-info.1
    /usr/local/share/man/man1/git-upload-archive.1
    /usr/local/share/man/man1/git-upload-pack.1
    /usr/local/share/man/man1/git-var.1
    /usr/local/share/man/man1/git-verify-pack.1
    /usr/local/share/man/man1/git-verify-tag.1
    /usr/local/share/man/man1/git-web--browse.1
    /usr/local/share/man/man1/git-whatchanged.1
    /usr/local/share/man/man1/git-write-tree.1
    /usr/local/share/man/man1/git.1
    /usr/local/share/man/man1/gitk.1
    /usr/local/share/man/man1/gitremote-helpers.1
    /usr/local/share/man/man1/gitweb.1
    /usr/local/share/man/man3/Git.3pm
    /usr/local/share/man/man3/Git::I18N.3pm
    /usr/local/share/man/man3/Git::SVN::Editor.3pm
    /usr/local/share/man/man3/Git::SVN::Fetcher.3pm
    /usr/local/share/man/man3/Git::SVN::Memoize::YAML.3pm
    /usr/local/share/man/man3/Git::SVN::Prompt.3pm
    /usr/local/share/man/man3/Git::SVN::Ra.3pm
    /usr/local/share/man/man3/Git::SVN::Utils.3pm
    /usr/local/share/man/man5/gitattributes.5
    /usr/local/share/man/man5/githooks.5
    /usr/local/share/man/man5/gitignore.5
    /usr/local/share/man/man5/gitmodules.5
    /usr/local/share/man/man5/gitrepository-layout.5
    /usr/local/share/man/man5/gitweb.conf.5
    /usr/local/share/man/man7/gitcli.7
    /usr/local/share/man/man7/gitcore-tutorial.7
    /usr/local/share/man/man7/gitcredentials.7
    /usr/local/share/man/man7/gitcvs-migration.7
    /usr/local/share/man/man7/gitdiffcore.7
    /usr/local/share/man/man7/gitglossary.7
    /usr/local/share/man/man7/gitnamespaces.7
    /usr/local/share/man/man7/gitrevisions.7
    /usr/local/share/man/man7/gittutorial-2.7
    /usr/local/share/man/man7/gittutorial.7
    /usr/local/share/man/man7/gitworkflows.7

Warning: Your Homebrew is outdated.
You haven't updated for at least 24 hours. This is a long time in brewland!
To update Homebrew, run `brew update`.

如何在诊断安装数据集包的问题方面取得进展?

更新

这是我要运行的脚本:

import sys
egg_path = '/usr/local/lib/python2.7/site-packages/datasets-0.0.9-py2.7.egg'
sys.path.append(egg_path)

import numpy as np
import lda
import datasets

X = lda.datasets.load_reuters()
vocab = lda.datasets.load_reuters_vocab()
titles = lda.datasets.load_reuters_titles()
X.shape
(395, 4258)
X.sum()
84010
model = lda.LDA(n_topics=20, n_iter=1500, random_state=1)
model.fit(X)  # model.fit_transform(X) is also available
topic_word = model.topic_word_  # model.components_ also works
n_top_words = 8
for i, topic_dist in enumerate(topic_word):
     topic_words = np.array(vocab)[np.argsort(topic_dist)][:-(n_top_words+1):-1]
     print('Topic {}: {}'.format(i, ' '.join(topic_words)))

【问题讨论】:

    标签: python python-2.7 pip homebrew


    【解决方案1】:

    使用pip install datasets 我也无法正确安装此软件包。似乎在这个特定的包中有一个错误。

    DESCRIBE.rst 文件完全丢失。要解决这个问题,只需从 PyPi 下载普通包。 https://pypi.python.org/pypi/datasets/0.0.9

    然后调整 setup.py 文件(删除描述)。

    之后您需要使用python setup.py install 进行安装。不要忘记将已安装的包添加到您的 Python 路径中!

    为此,我建议您将以下内容添加到您的脚本中。

    import sys
    egg_path = '__MODULE_PATH__/datasets-0.0.9-py3.5.egg'
    sys.path.append(egg_path)
    import datasets
    

    否则,您也可以使用以下方式添加模块:

    export PATH=__MODULE_PATH__:$PATH
    

    或者,您也可以简单地从 Github 存储库中提取源代码并将其包含在您的项目中。 https://github.com/realtimeweb/datasets

    希望这对您的问题有所帮助。如果您还有其他问题,请告诉我。

    【讨论】:

    • 谢谢菲利普。这看起来很有希望,我按照您的步骤完成了安装,没有任何错误。我目前正在尝试研究如何将包添加到我的 python 路径中(这种类型的东西对我来说也有点新)。如果这是微不足道的,请随时指出最好的方法。
    • 我添加了几行关于您通常如何将模块添加到 Python 路径的内容。希望对您有所帮助。
    • 感谢 Philipp - 很遗憾,我不知道如何处理您添加的内容。我的猜测是将 egg_path... 等块添加到我要运行的脚本中,但这会给出错误“sys.path.append(egg_path) NameError: name 'sys' is not defined”。我的猜测是在运行脚本之前运行您提供的导出行,但这仍然会给出“没有名为数据集的模块”消息。对不起,我对此一无所知。在这方面我似乎有很多东西要学。
    • 您还需要import sys。但那你应该很好。是的,代码确实应该进入你的脚本。在 Python 路径方面,我认为可能存在权限问题。这就是我包含脚本的原因,它通常可以工作。
    • 当我运行安装文件时,它在末尾显示以下内容:“Installed /usr/local/lib/python2.7/site-packages/datasets-0.0.9-py2.7.egg " - 但是当我在您的示例中将此路径添加到 egg_path 变量时,它仍然不起作用(划痕)。
    【解决方案2】:

    我刚刚在 rapsberry pi 上遇到了同样的问题,刚刚发现这个问题已得到修复,但错误来自于缺少 ram 来正确提取包。

    您可以通过禁用在 ram 中创建缓存目录添加参数来解决此问题

    --no-cache-dir
    

    例如

    pip2 install --user --no-cache-dir datasets
    

    【讨论】:

    • 这个包叫datasets而不是dataset
    • 上述命令有以下错误输出:Can not perform a '--user' install。用户站点包在此 virtualenv 中不可见。
    • 错误本身说明,如果您在虚拟环境中,则不能使用标志 --user,可能因为您已经在为您的应用程序封装所有内容的虚拟环境中,并且不需要特殊权限即可安装“系统”包。
    • pip 缓存目录在您的硬盘上,而不是在 RAM 中...pip.pypa.io/en/stable/reference/pip_install/#caching
    • 你是对的,缓存系统中仍然存在导致 RAM 滥用的问题,请参阅github.com/pypa/pip/issues/2984 可能下载只是临时保存在 RAM 中,然后转储到磁盘或类似的东西
    猜你喜欢
    • 1970-01-01
    • 2022-01-22
    • 2016-05-18
    • 2021-04-21
    • 2017-02-08
    • 2019-06-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多