我刚刚通过pip安装了一个包,
Cloning https://github.com/felix001/commontools.git to /tmp/pip-LMwfnO-build
Installing collected packages: commontools
Running setup.py install for commontools
Successfully installed commontools-1.0
当我尝试导入commontools时,它不会导入。 路径看起来不错,
>>> import pprint
>>> import sys
>>> pprint.pprint(sys.path)
['',
'/Library/Python/2.7/site-packages/pip-7.1.2-py2.7.egg',
'/Users/felix001',
'/usr/local/lib/python2.7/site-packages',
'/usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/lib/python27.zip',
'/usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7',
'/usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin',
'/usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac',
'/usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages',
'/usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk',
'/usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old',
'/usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload',
'/usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages',
'/Library/Python/2.7/site-packages']
>>>
MacBook-Pro:~ felix001$ ls -l /Library/Python/2.7/site-packages
total 392
-rw-r--r-- 1 root wheel 119 9 Sep 2014 README
drwxr-xr-x 7 root wheel 238 18 Dec 21:39 commontools-1.0-py2.7.egg-info
-rw-r--r-- 1 root wheel 207 3 Nov 20:20 easy-install.pth
drwxr-xr-x 4 root wheel 136 3 Nov 20:20 pip-7.1.2-py2.7.egg
drwxr-xr-x 60 root wheel 2040 23 Oct 2014 scapy
-rw-r--r-- 1 root wheel 261 18 Oct 2014 scapy-2.1.0-py2.7.egg-info
drwxr-xr-x 7 root wheel 238 11 Dec 22:18 threader-1.0-py2.7.egg-info
drwxr-xr-x 6 root wheel 204 20 Jul 21:49 vboxapi
-rw-r--r-- 1 root wheel 241 20 Jul 21:49 vboxapi-1.0-py2.7.egg-info
drwxr-xr-x 10 root wheel 340 3 Nov 20:21 virtualenv-13.1.2.dist-info
-rw-r--r-- 1 root wheel 99421 3 Nov 20:21 virtualenv.py
-rw-r--r-- 1 root wheel 83209 3 Nov 20:21 virtualenv.pyc
drwxr-xr-x 8 root wheel 272 3 Nov 20:21 virtualenv_support
以下是包裹详情。
MacBook-Pro:~ felix001$ pip show commontools
---
Metadata-Version: 1.0
Name: commontools
Version: 1.0
Summary: commontools
Home-page: UNKNOWN
Author: ====
Author-email: ====
License: UNKNOWN
Location: /Library/Python/2.7/site-packages
Requires:
编辑:
我尝试导入时错误显示如下,
MacBook-Pro:~$ which python
/usr/local/bin/python
MacBook-Pro:~$ python
Python 2.7.10 (default, Sep 23 2015, 04:34:14)
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.72)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from commontools import *
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named commontools
EDIT2:
所以我删除了所有python实例。我使用brew安装了一个新版本。同样的问题。
新的Python路径,
MacBook-Pro:~ felix001$ which python
/usr/local/bin/python
现在,如果我通过pip安装任何东西。它工作正常。但是如果我安装自己的git repos就失败了(??)。下面是一个例子 - https://github.com/felix001/commontools
以下是一个例子,
MacBook-Pro:~ felix001$ pip -v install netaddr
Collecting netaddr
Getting page https://pypi.python.org/simple/netaddr/
1 location(s) to search for versions of netaddr:
* https://pypi.python.org/simple/netaddr/
Getting page https://pypi.python.org/simple/netaddr/
Analyzing links from page https://pypi.python.org/simple/netaddr/
Skipping link https://pypi.python.org/packages/2.4/n/netaddr/netaddr-0.3.1.win32.exe#md5=ba0615105ab8193f4115e2a5767a121c (from https://pypi.python.org/simple/netaddr/); unsupported archive format: .exe
Skipping link https://pypi.python.org/packages/2.4/n/netaddr/netaddr-0.4.win32.exe#md5=77c28e03c14e081b3339118fad7f1bce (from https://pypi.python.org/simple/netaddr/); unsupported archive format: .exe
Skipping link https://pypi.python.org/packages/2.4/n/netaddr/netaddr-
0.7.x/CHANGELOG (from https://pypi.python.org/simple/netaddr/); not a file
Skipping link http://packages.python.org/netaddr/ (from https://pypi.python.org/simple/netaddr/); not a file
Skipping link https://github.com/drkjam/netaddr/blob/rel-0.7.x/CHANGELOG (from https://pypi.python.org/simple/netaddr/); not a file
Skipping link https://pythonhosted.org/netaddr/ (from https://pypi.python.org/simple/netaddr/); not a file
Using version 0.7.18 (newest of versions: 0.7.18, 0.7.18, 0.7.18, 0.7.17, 0.7.17, 0.7.17, 0.7.16, 0.7.16, 0.7.16, 0.7.15, 0.7.15, 0.7.15, 0.7.14, 0.7.14, 0.7.14, 0.7.13, 0.7.13, 0.7.13, 0.7.12, 0.7.12, 0.7.11, 0.7.11, 0.7.10, 0.7.10, 0.7.3, 0.7.3, 0.7.2, 0.7.2, 0.7.1, 0.7.1, 0.7, 0.7, 0.6.4, 0.6.4, 0.6.3, 0.6.3, 0.6.2, 0.6.2, 0.6.1, 0.6.1, 0.6, 0.6, 0.5.2, 0.5.2, 0.5.1, 0.5.1, 0.5, 0.5, 0.4, 0.4, 0.3.1, 0.3.1)
Using cached netaddr-0.7.18-py2.py3-none-any.whl
Downloading from URL https://pypi.python.org/packages/any/n/netaddr/netaddr-0.7.18-py2.py3-none-any.whl#md5=f18d38b78469bb440560544f5559e649 (from https://pypi.python.org/simple/netaddr/)
Installing collected packages: netaddr
Successfully installed netaddr-0.7.18
Cleaning up...
MacBook-Pro:~ felix001$ python
Python 2.7.10 (default, Sep 23 2015, 04:34:14)
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.72)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import netaddr
>>>
>>>
>>>
MacBook-Pro:~ felix001$ pip -vvv install git+https://github.com/felix001/commontools
Collecting git+https://github.com/felix001/commontools
Cloning https://github.com/felix001/commontools to /var/folders/13/780bwzl13p5118ldv4qdqgvw0000gn/T/pip-76GaiR-build
Running command git clone -q https://github.com/felix001/commontools /var/folders/13/780bwzl13p5118ldv4qdqgvw0000gn/T/pip-76GaiR-build
Running setup.py (path:/var/folders/13/780bwzl13p5118ldv4qdqgvw0000gn/T/pip-76GaiR-build/setup.py) egg_info for package from git+https://github.com/felix001/commontools
Running command python setup.py egg_info
running egg_info
creating pip-egg-info/commontools.egg-info
writing pip-egg-info/commontools.egg-info/PKG-INFO
writing top-level names to pip-egg-info/commontools.egg-info/top_level.txt
writing dependency_links to pip-egg-info/commontools.egg-info/dependency_links.txt
writing manifest file 'pip-egg-info/commontools.egg-info/SOURCES.txt'
warning: manifest_maker: standard file '-c' not found
reading manifest file 'pip-egg-info/commontools.egg-info/SOURCES.txt'
writing manifest file 'pip-egg-info/commontools.egg-info/SOURCES.txt'
Source in /var/folders/13/780bwzl13p5118ldv4qdqgvw0000gn/T/pip-76GaiR-build has version 1.0, which satisfies requirement commontools==1.0 from git+https://github.com/felix001/commontools
Installing collected packages: commontools
Running setup.py install for commontools
Running command /usr/local/opt/python/bin/python2.7 -c "import setuptools, tokenize;__file__='/var/folders/13/780bwzl13p5118ldv4qdqgvw0000gn/T/pip-76GaiR-build/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /var/folders/13/780bwzl13p5118ldv4qdqgvw0000gn/T/pip-hU9LyU-record/install-record.txt --single-version-externally-managed --compile
running install
running build
running install_egg_info
running egg_info
creating commontools.egg-info
writing commontools.egg-info/PKG-INFO
writing top-level names to commontools.egg-info/top_level.txt
writing dependency_links to commontools.egg-info/dependency_links.txt
writing manifest file 'commontools.egg-info/SOURCES.txt'
warning: manifest_maker: standard file '-c' not found
reading manifest file 'commontools.egg-info/SOURCES.txt'
writing manifest file 'commontools.egg-info/SOURCES.txt'
Copying commontools.egg-info to /usr/local/lib/python2.7/site-packages/commontools-1.0-py2.7.egg-info
running install_scripts
writing list of installed files to '/var/folders/13/780bwzl13p5118ldv4qdqgvw0000gn/T/pip-hU9LyU-record/install-record.txt'
Removing source in /var/folders/13/780bwzl13p5118ldv4qdqgvw0000gn/T/pip-76GaiR-build
Successfully installed commontools-1.0
Cleaning up...
MacBook-Pro:~ felix001$ python
Python 2.7.10 (default, Sep 23 2015, 04:34:14)
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.72)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import commontools
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named commontools
>>>
有什么想法吗?
答案 0 :(得分:0)
这不是pip
的问题;这是commontools
包的问题。
这是 setup.py
:
from setuptools import setup
setup(
name="commontools",
version="1.0",
author="xxxxxxxxxxxx",
author_email="xxxxxxxxxxxx",
description="commontools",
)
它甚至不遵循setuptools
的{{3}}或minimal viable example for packaging。
<强> TL; DR:强>
它不包括源文件;这是packages
的{{1}}关键字的作用。