【问题标题】:How do I get python to recognize a module from any directory?如何让 python 从任何目录中识别模块?
【发布时间】:2015-02-26 20:06:22
【问题描述】:

我正在向 anaconda 安装一些额外的软件包,但我无法让它们工作。我下载、解压缩并移至/usr/local/anaconda/lib/python2.7/site-package/pydicom 的包是 pydicom。在 pydicom 文件夹中有一个名为 source 的子文件夹,其中包含 ez_setup.pysetup.py。我运行了sudo python setup.py install,它没有吐出任何错误,然后运行sudo python ez_setup.py install,当我仍然无法在ipython中打开模块时。现在我可以成功import dicom 但只有当我的当前目录是/usr/local/anaconda/lib/python2.7/site-package/pydicom/source 时。如何获取它以便从任何目录导入它?我正在运行 CentOS,我把

export PATH=/usr/local/anaconda/bin:$PATH export PATH=/usr/local/anaconda/lib/python2.7/:$PATH 在我的 .bashrc 文件中。

【问题讨论】:

  • 不要手动安装档案。请改用pip install </path/to/archive>
  • 当我尝试得到这个错误时:Command /usr/local/anaconda/bin/python -c "import setuptools, tokenize;__file__='/tmp/pip_build_gcw8/pydicom/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-TdTVZf-record/install-record.txt --single-version-externally-managed --compile failed with error code 1 in /tmp/pip_build_gcw8/pydicom Storing debug log for failure in /PHShome/gcw8/.pip/pip.log
  • /PHShome/gcw8/.pip/pip.log 文件中的错误信息是什么?

标签: python installation anaconda packages pydicom


【解决方案1】:

您不应直接将源代码复制到站点包。而是在源目录中使用python setup.py install,或使用pip install .。确保您的 Python 确实是 /usr/local/anaconda 中的那个,特别是如果您使用 sudo(这通常不是必需的,也不建议在 Anaconda 中使用)。

【讨论】:

    猜你喜欢
    • 2011-08-31
    • 2019-06-23
    • 1970-01-01
    • 2021-01-10
    • 1970-01-01
    • 2012-07-28
    • 2021-11-30
    • 1970-01-01
    • 2020-10-14
    相关资源
    最近更新 更多