gpt4 book ai didi

python - Pip 列表显示包已安装但导入包抛出 ImportError

转载 作者:太空宇宙 更新时间:2023-11-03 15:53:05 25 4
gpt4 key购买 nike

我有一个托管在我的 VCS 中的软件包。我跑:

$ pip install -vvv git+https://myvcs.com/myprotos

这是日志。您会注意到它在安装过程中运行了一个自定义脚本,它实际上在项目中构建了源文件。参见 this question for details of what it's doing .

Collecting git+https://myvcs.com/myprotos
Cloning https://myvcs.com/myprotos to /private/var/folders/3t/4qwkfyr903d0b7db7by2kj6r0000gn/T/pip-cFzP3I-build
Running command git clone -q https://myvcs.com/myprotos /private/var/folders/3t/4qwkfyr903d0b7db7by2kj6r0000gn/T/pip-cFzP3I-build
Running setup.py (path:/private/var/folders/3t/4qwkfyr903d0b7db7by2kj6r0000gn/T/pip-cFzP3I-build/setup.py) egg_info for package from git+https://myvcs.com/myprotos
Running command python setup.py egg_info
running egg_info
creating pip-egg-info/myprotos.egg-info
writing pip-egg-info/myprotos.egg-info/PKG-INFO
writing top-level names to pip-egg-info/myprotos.egg-info/top_level.txt
writing dependency_links to pip-egg-info/myprotos.egg-info/dependency_links.txt
writing manifest file 'pip-egg-info/myprotos.egg-info/SOURCES.txt'
reading manifest file 'pip-egg-info/myprotos.egg-info/SOURCES.txt'
writing manifest file 'pip-egg-info/myprotos.egg-info/SOURCES.txt'
Source in /private/var/folders/3t/4qwkfyr903d0b7db7by2kj6r0000gn/T/pip-cFzP3I-build has version 0.0.1, which satisfies requirement myprotos==0.0.1 from git+https://myvcs.com/myprotos
Installing collected packages: myprotos
Running setup.py install for myprotos: started
Running command /usr/local/opt/python/bin/python2.7 -u -c "import setuptools, tokenize;__file__='/private/var/folders/3t/4qwkfyr903d0b7db7by2kj6r0000gn/T/pip-cFzP3I-build/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /var/folders/3t/4qwkfyr903d0b7db7by2kj6r0000gn/T/pip-M03grb-record/install-record.txt --single-version-externally-managed --compile
running install
Grabbing github.com/google/protobuf...
Building Python protos...
running build
running install_egg_info
running egg_info
creating myprotos.egg-info
writing myprotos.egg-info/PKG-INFO
writing top-level names to myprotos.egg-info/top_level.txt
writing dependency_links to myprotos.egg-info/dependency_links.txt
writing manifest file 'myprotos.egg-info/SOURCES.txt'
reading manifest file 'myprotos.egg-info/SOURCES.txt'
writing manifest file 'myprotos.egg-info/SOURCES.txt'
Copying myprotos.egg-info to /usr/local/lib/python2.7/site-packages/myprotos-0.0.1-py2.7.egg-info
running install_scripts
writing list of installed files to '/var/folders/3t/4qwkfyr903d0b7db7by2kj6r0000gn/T/pip-M03grb-record/install-record.txt'
Running setup.py install for myprotos: finished with status 'done'
Removing source in /private/var/folders/3t/4qwkfyr903d0b7db7by2kj6r0000gn/T/pip-cFzP3I-build
Successfully installed myprotos-0.0.1
Cleaning up...

这样看来一切都安装成功了。即使运行 pip list 输出:

$ pip list
.
.
.
myprotos (0.0.1)
.
.
.

但是,如果我尝试导入包,它会抛出 ImportError。

$ python
Python 2.7.13 (default, Jul 18 2017, 09:17:00)
[GCC 4.2.1 Compatible Apple LLVM 8.1.0 (clang-802.0.42)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import myprotos
Traceback (most recent call last):

File "<stdin>", line 1, in <module>
ImportError: No module named myprotos

这里可能发生了什么?构建脚本是否可能在安装时失败或者我的包定义错误或者它可能是什么?

最佳答案

egg的名字不一定要和它提供的模块或包的名字一样。事实上,这些名称不同是很常见的。一个鸡蛋可以装多个包裹,所以一般情况下是不可能用同一个名字的。此外,egg 名称可以包含破折号和其他 Python 模块名称中不允许的字符。

Python site-packages 目录中的 myprotos.egg-info 目录应该包含一个名为 top_level.txt 的文件,其中列出了所有顶级-level 模块并打包 egg 导出。

关于python - Pip 列表显示包已安装但导入包抛出 ImportError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45330316/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com