Python 模块不会安装
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14865990/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Python module won't install
提问by elssar
This is my setup.pyfile
这是我的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= '[email protected]',
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',
],
)
I have tried using both setuptoolsand distutils, but this won't install my module. Instead I get
我试过同时使用setuptoolsand distutils,但这不会安装我的模块。相反,我得到
file module.py (for module module) not found
This is my directory structure
这是我的目录结构
/module
|--/test
|--README.md
|--license.txt
|--module.py
|--setup.py
Just to be clear, module is the root directory.
需要明确的是,模块是根目录。
Can anyone tell me what I'm doing wrong?
谁能告诉我我做错了什么?
This is the output when I try to install
这是我尝试安装时的输出
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
Just to be sure there isn't something wrong my my system, I downloaded two packages from github with a similar setup.pyand installed them. Installed without any problems.
为了确保我的系统没有问题,我从 github 下载了两个类似的包setup.py并安装了它们。安装没有任何问题。
采纳答案by elssar
I cannot run setup.pyfrom a different directory. It needs to be run from the directory it is in. That was the problem here.
我无法setup.py从其他目录运行。它需要从它所在的目录运行。这就是这里的问题。
Fixed.
固定的。
回答by abarnert
If I understand your layout, the problem is that you're using the default package_dir, which means that top-level modules like moduleneed to be in the root directory as module.py, not as module/module.py.
如果我理解您的布局,问题在于您使用的是默认值package_dir,这意味着顶级模块module需要在根目录中作为module.py,而不是作为module/module.py。
So, add this:
所以,添加这个:
package_dir = {'': 'module'}
Now, it'll look for moduleas module/module.py.
现在,它将查找moduleas module/module.py。
(PS, this would all be a lot less confusing to discuss if your module, or its subdirectory, or ideally both, were called something other than "module". Also, if you used a more standard format for drawing your directory tree.)
(PS,如果您的模块或其子目录,或理想情况下两者都被称为“模块”以外的其他名称,那么讨论这一切都不会那么混乱。此外,如果您使用更标准的格式来绘制目录树。)
This is explained in Listing whole packages. (I realize you're listing individual modules, not whole packages, but the docs for that section just say "again, you can override the package/directory correspondence using the package_dir option", referring back to the section I linked. And the referencefor package_diris even less helpful; it just says "A mapping of package to directory names".)
这在列出整个包中进行了解释。(我意识到您列出的是单个模块,而不是整个包,但该部分的文档只是说“再次,您可以使用 package_dir 选项覆盖包/目录对应关系”,参考我链接的部分。和参考for 的package_dir帮助更小;它只是说“包到目录名称的映射”。)

