python – `pip install -t`不适用于命名空间包
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了python – `pip install -t`不适用于命名空间包,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含4290字,纯文字阅读大概需要7分钟。
内容图文
当我使用pip install -t some_dir安装一个包时,我通常可以在运行python时导入包,将some_dir添加到我的PYTHONPATH中.像这样:
~/dev/scratch [venv] ? pip install -t some_dir pytest
...
Successfully installed py pytest
~/dev/scratch [venv] ? PYTHONPATH=some_dir python
...
>>> import pytest
>>>
但是,我最近将库“stompest”添加到我的依赖项中,这显然是一个“命名空间包”(并不完全确定这意味着什么).它似乎不适用于相同的模式:
~/dev/scratch [venv] ? pip install -t some_dir stompest
...
Successfully installed stompest
~/dev/scratch [venv] ? PYTHONPATH=some_dir python
...
>>> import stompest.config
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named stompest.config
如果我只是正常安装stompest(比如虚拟环境),它工作正常:
~/dev/scratch [venv] ? pip install stompest
...
Successfully installed stompest-2.1.6
~/dev/scratch [venv] ? python
...
>>> import stompest.config
>>>
问题似乎是pip(?)列出了一个预期在site-dir中的.pth文件(请注意下面的f_locals [‘sitedir’]):
~/dev/scratch [venv] ? cat some_dir/stompest-2.1.6-py2.7-nspkg.pth
import sys,types,os; p = os.path.join(sys._getframe(1).f_locals['sitedir'], *('stompest',)); ie = os.path.exists(os.path.join(p,'__init__.py')); m = not ie and sys.modules.setdefault('stompest',types.ModuleType('stompest')); mp = (m or []) and m.__dict__.setdefault('__path__',[]); (p not in mp) and mp.append(p)
我也试过设置PYTHONUSERBASE = some_dir,但这似乎没有任何区别.这似乎与this one类似的问题,建议使用–egg作为解决方法.我不能让-egg与-t一起使用,因为我得到一个错误,我“试图将软件包安装到不在PYTHONPATH上的目录,哪个Python不读取”.pth“文件“.问题是我无法将目录添加到PYTHONPATH,因为它似乎试图安装到临时目录:
~/dev/scratch [venv] ? PYTHONPATH=some_dir pip install -t some_dir --egg stompest
Collecting stompest
Using cached stompest-2.1.6.tar.gz
Installing collected packages: stompest
Running setup.py install for stompest
Complete output from command /home/nalderso/dev/scratch/venv/bin/python -c "import setuptools, tokenize;__file__='/tmp/pip-build-Wc3oaO/stompest/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-fZlXM2-record/install-record.txt --compile --install-headers /home/nalderso/dev/scratch/venv/include/site/python2.7/stompest --home=/tmp/tmpHNVOP0:
running install
Checking .pth file support in /tmp/tmpHNVOP0/lib/python/
/home/nalderso/dev/scratch/venv/bin/python -E -c pass
TEST FAILED: /tmp/tmpHNVOP0/lib/python/ does NOT support .pth files
error: bad install directory or PYTHONPATH
You are attempting to install a package to a directory that is not
on PYTHONPATH and which Python does not read ".pth" files from. The
installation directory you specified (via --install-dir, --prefix, or
the distutils default setting) was:
/tmp/tmpHNVOP0/lib/python/
and your PYTHONPATH environment variable currently contains:
'some_dir'
Here are some of your options for correcting the problem:
* You can choose a different installation directory, i.e., one that is
on PYTHONPATH or supports .pth files
* You can add the installation directory to the PYTHONPATH environment
variable. (It must then also be on PYTHONPATH whenever you run
Python and want to use the package(s) you are installing.)
* You can set up the installation directory to support ".pth" files by
using one of the approaches described here:
https://pythonhosted.org/setuptools/easy_install.html#custom-installation-locations
Please make the appropriate changes for your system and try again.
----------------------------------------
Command "/home/nalderso/dev/scratch/venv/bin/python -c "import setuptools, tokenize;__file__='/tmp/pip-build-Wc3oaO/stompest/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-fZlXM2-record/install-record.txt --compile --install-headers /home/nalderso/dev/scratch/venv/include/site/python2.7/stompest --home=/tmp/tmpHNVOP0" failed with error code 1 in /tmp/pip-build-Wc3oaO/stompest
我做错了什么,或者这是pip的问题?
解决方法:
它适用于您执行此操作:
import site
site.addsitedir('some_dir')
见https://docs.python.org/2/library/site.html#site.addsitedir
我在这篇pip issue中的帖子Matt Iversen(Ivoz)中找到了这个答案.请注意,本期中的讨论将继续讨论您可能遇到的一些极端情况.
内容总结
以上是互联网集市为您收集整理的python – `pip install -t`不适用于命名空间包全部内容,希望文章能够帮你解决python – `pip install -t`不适用于命名空间包所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。