Python模块无法安装
这是我的 setup.py
文件
#!/usr/bin/env python
from setuptools import setup
from sys import path
setup(name= 'conundrum',
version= '0.1.0',
author= 'elssar',
author_email= 'elssar@altrawcode.com',
py_modules= ['conundrum'],
url= 'https://github.com/elssar/conundrum',
license= 'MIT',
description= 'A framework agnostic blog generator.',
long_description= open(path[0]+'/README.md', 'r').read(),
install_requires= [
'PyYAML >= 3.0.9',
'Markdown >= 2.2.0',
'requests >= 1.0.4',
],
)
我尝试过使用 setuptools
和 distutils
,但是这并没有成功安装我的模块。相反,我得到了
file module.py (for module module) not found
这是我的目录结构
/module
|--/test
|--README.md
|--license.txt
|--module.py
|--setup.py
为了更清楚,模块是根目录。
有没有人能告诉我我哪里做错了?
这是我尝试安装时的输出
elssar@elssar-laptop:/usr/local/src/conundrum$ sudo python /home/elssar/code/conundrum/setup.py install
/usr/lib/python2.6/distutils/dist.py:250: UserWarning: 'licence' distribution option is deprecated; use 'license'
warnings.warn(msg)
running install
running bdist_egg
running egg_info
writing requirements to conundrum.egg-info/requires.txt
writing conundrum.egg-info/PKG-INFO
writing top-level names to conundrum.egg-info/top_level.txt
writing dependency_links to conundrum.egg-info/dependency_links.txt
warning: manifest_maker: standard file 'setup.py' not found
file conundrum.py (for module conundrum) not found
reading manifest file 'conundrum.egg-info/SOURCES.txt'
writing manifest file 'conundrum.egg-info/SOURCES.txt'
installing library code to build/bdist.linux-x86_64/egg
running install_lib
running build_py
file conundrum.py (for module conundrum) not found
file conundrum.py (for module conundrum) not found
warning: install_lib: 'build/lib.linux-x86_64-2.6' does not exist -- no Python modules to install
creating build/bdist.linux-x86_64/egg
creating build/bdist.linux-x86_64/egg/EGG-INFO
copying conundrum.egg-info/PKG-INFO -> build/bdist.linux-x86_64/egg/EGG-INFO
copying conundrum.egg-info/SOURCES.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying conundrum.egg-info/dependency_links.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying conundrum.egg-info/requires.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying conundrum.egg-info/top_level.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
zip_safe flag not set; analyzing archive contents...
creating 'dist/conundrum-0.1.0-py2.6.egg' and adding 'build/bdist.linux-x86_64/egg' to it
removing 'build/bdist.linux-x86_64/egg' (and everything under it)
Processing conundrum-0.1.0-py2.6.egg
removing '/usr/local/lib/python2.6/dist-packages/conundrum-0.1.0-py2.6.egg' (and everything under it)
creating /usr/local/lib/python2.6/dist-packages/conundrum-0.1.0-py2.6.egg
Extracting conundrum-0.1.0-py2.6.egg to /usr/local/lib/python2.6/dist-packages
conundrum 0.1.0 is already the active version in easy-install.pth
Installed /usr/local/lib/python2.6/dist-packages/conundrum-0.1.0-py2.6.egg
Processing dependencies for conundrum==0.1.0
Searching for requests==1.0.4
Best match: requests 1.0.4
Adding requests 1.0.4 to easy-install.pth file
Using /usr/local/lib/python2.6/dist-packages
Searching for Markdown==2.2.0
Best match: Markdown 2.2.0
Processing Markdown-2.2.0-py2.6.egg
Markdown 2.2.0 is already the active version in easy-install.pth
Installing markdown_py script to /usr/local/bin
Using /usr/local/lib/python2.6/dist-packages/Markdown-2.2.0-py2.6.egg
Searching for PyYAML==3.10
Best match: PyYAML 3.10
Adding PyYAML 3.10 to easy-install.pth file
Using /usr/local/lib/python2.6/dist-packages
Finished processing dependencies for conundrum==0.1.0
为了确保我的系统没有问题,我从github下载了两个有类似 setup.py
的包,并成功安装了它们,没有任何问题。
2 个回答
4
如果我理解你的布局没错,问题在于你使用了默认的 package_dir
,这意味着像 module
这样的顶级模块需要放在根目录下,文件名是 module.py
,而不是放在 module/module.py
里。
所以,你需要加上这个:
package_dir = {'': 'module'}
现在,它会去找 module
,路径是 module/module.py
。
(顺便说一下,如果你的模块,或者它的子目录,或者最好是两者,都用一些其他的名字而不是“module”,讨论起来会简单很多。另外,如果你用更标准的格式来画你的目录树,也会更清晰。)
这个问题在 列出整个包 的文档中有解释。(我知道你是在列出单个模块,而不是整个包,但那部分的文档只是说“同样,你可以使用 package_dir 选项来覆盖包和目录的对应关系”,这又回到了我链接的部分。而 关于 package_dir
的参考 更不太有帮助,它只是说“包和目录名称的映射”。)
20
我不能在其他文件夹里运行 setup.py
,它必须在它所在的文件夹里运行。这就是问题所在。
解决了。