安装的模块为空

bux*_*bux 9 python setuptools

我正在尝试使用setuptoolspython3 代码。我的项目结构:

./testSetup/
./testSetup/testSetup
./testSetup/testSetup/foo.py
./testSetup/Setup.py
Run Code Online (Sandbox Code Playgroud)

./testSetup/testSetup/foo.py内容:

def say_foo():
    print('foo')
Run Code Online (Sandbox Code Playgroud)

./testSetup/Setup.py内容:

from setuptools import setup, find_packages
import testSetup

setup(
    name='testSetup',
    version='0.0.1',
    packages=find_packages(),
    author='Bastien Sevajol',
    author_email="testSetup@bux.fr",
    description='test',
    long_description='test test',
    include_package_data=False,
    url='http://bux.fr',
    # https://pypi.python.org/pypi?%3Aaction=list_classifiers.
    classifiers=[
        "Programming Language :: Python",
    ]
)
Run Code Online (Sandbox Code Playgroud)

当我python Setup.py install(使用 python3.4)在虚拟环境中时:

python Setup.py install
running install
running bdist_egg
running egg_info
creating testSetup.egg-info
writing testSetup.egg-info/PKG-INFO
writing dependency_links to testSetup.egg-info/dependency_links.txt
writing top-level names to testSetup.egg-info/top_level.txt
writing manifest file 'testSetup.egg-info/SOURCES.txt'
reading manifest file 'testSetup.egg-info/SOURCES.txt'
writing manifest file 'testSetup.egg-info/SOURCES.txt'
installing library code to build/bdist.linux-i686/egg
running install_lib
warning: install_lib: 'build/lib' does not exist -- no Python modules to install

creating build
creating build/bdist.linux-i686
creating build/bdist.linux-i686/egg
creating build/bdist.linux-i686/egg/EGG-INFO
copying testSetup.egg-info/PKG-INFO -> build/bdist.linux-i686/egg/EGG-INFO
copying testSetup.egg-info/SOURCES.txt -> build/bdist.linux-i686/egg/EGG-INFO
copying testSetup.egg-info/dependency_links.txt -> build/bdist.linux-i686/egg/EGG-INFO
copying testSetup.egg-info/top_level.txt -> build/bdist.linux-i686/egg/EGG-INFO
zip_safe flag not set; analyzing archive contents...
creating dist
creating 'dist/testSetup-0.0.1-py3.4.egg' and adding 'build/bdist.linux-i686/egg' to it
removing 'build/bdist.linux-i686/egg' (and everything under it)
Processing testSetup-0.0.1-py3.4.egg
Copying testSetup-0.0.1-py3.4.egg to /home/bux/.virtualenvs/testsynergine2/lib/python3.4/site-packages
Adding testSetup 0.0.1 to easy-install.pth file

Installed /home/bux/.virtualenvs/testsynergine2/lib/python3.4/site-packages/testSetup-0.0.1-py3.4.egg
Processing dependencies for testSetup==0.0.1
Finished processing dependencies for testSetup==0.0.1
Run Code Online (Sandbox Code Playgroud)

我可以看到一个警告说install_lib: 'build/lib' does not exist -- no Python modules to install

如果我尝试使用我的模块:

python               
Python 3.4.0 (default, Apr 11 2014, 13:05:18) 
[GCC 4.8.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from testSetup import foo
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name 'foo'
>>> import testSetup
>>> dir(testSetup)
['__doc__', '__loader__', '__name__', '__package__', '__path__', '__spec__']
Run Code Online (Sandbox Code Playgroud)

我的 Setup.py 有什么问题?

Way*_*lan 7

__init__.py您的目录中需要有一个文件TestSetup/(该文件可以为空)。否则,该目录中的任何内容都将无法导入并且find_packages()永远找不到它。您可能想阅读 相关 内容

./testSetup/
./testSetup/testSetup
./testSetup/testSetup/__init__.py
./testSetup/testSetup/foo.py
./testSetup/setup.py
Run Code Online (Sandbox Code Playgroud)

另请注意,setup.py应全部小写。虽然命名Setup.py不会阻止脚本工作,但它不是约定,并且可能不会被各种工具发现。


Ket*_*uem 5

这是因为setuptools.find_packages,在不带任何参数的情况下调用它时,它会从setup.py. 在您的情况下,您在根级别没有任何文件夹。

问题不是来自您的setup.py文件,而是来自您组织项目的方式,通过移动您的资源,如下所示:

testSetup
|--setup.py
|--/testSetup/foo.py
|--/testSetup/__init__.py
Run Code Online (Sandbox Code Playgroud)

那么你就可以pip setup.py install在cd-ing里面成功了testSetup

find_packages 上的一些文档