Python module won't install
Solution 1
I cannot run setup.py
from a different directory. It needs to be run from the directory it is in. That was the problem here.
Fixed.
Solution 2
If I understand your layout, the problem is that you're using the default package_dir
, which means that top-level modules like module
need to be in the root directory as module.py
, not as module/module.py
.
So, add this:
package_dir = {'': 'module'}
Now, it'll look for module
as 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.)
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 reference for package_dir
is even less helpful; it just says "A mapping of package to directory names".)
elssar
Just a random guy on the internet, procrastinator extraordinaire. SOreadytohelp
Updated on November 02, 2020Comments
-
elssar over 3 years
This is my
setup.py
file#!/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
setuptools
anddistutils
, but this won't install my module. Instead I getfile 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.py
and installed them. Installed without any problems. -
Admin over 11 yearsIt doesn't deserve to be a second answer, but I found the The Hitchhiker's Guide to Packaging 1.0 - Creating a Package to be helpful as a skeleton for developing a package structure.
-
abarnert over 11 years@Mike: IIRC, that guide avoids explaining all of the complicated stuff, and instead explains how to avoid needing the complicated stuff—which means it probably won't directly answer the OP's question, but could easily lead him to not need the answer anymore. (And, even if it doesn't, it's worth reading.) So, definitely +1.
-
elssar over 11 years@Mike Guess I should've been more clearer--> module is the root directory, it has the same name as module.py. To be clearer - the root directory is named module and it contains the python script module.py and everything else, and a sub directory with the tests, which I don't need installed.
-
elssar over 11 years@Mike I've read that guide, but the tutorial requires I make another directory, and an
__init__.py
file, which would be empty as I don't need anything initialized. -
Admin over 11 years@elssar An empty
__init__.py
file is perfectly valid - it indicates to python that the directory is a package. -
abarnert over 11 years@Mike: Yes, but I don't think the OP wants to create a package, just a module. (He wants to be able to
import module
, notimport module.module
after installing.) -
abarnert over 11 years@elssar: In that case, you're going to have to give us your actual
setup.py
and the full error message. Because when I try your file with that layout, I get an error about that undefineddependencies
—and, once I fix that, everything works (except for a warning about usinglicence
instead oflicense
). In particular:copying module.py -> build/lib
. -
abarnert over 11 yearsOK. I just assumed that you knew that
module.py
would be$(pwd)/module.py
, not$(dirname /path/to/setup.py)/module.py
. But that wasn't a very good assumption. Unix tools do it far more often that way than the other way, but that's not the same as "it can only be that way" (especially for Windows users). (BTW, the same is true if you use a relative path inpackage_dir
—it's relative to the pwd.) Do you think the docs need to make this clearer? If so, you may want to file a documentation bug, or bring it up on the mailing lists. -
elssar over 11 years@abarnert I know where
module.py
is, I just assumed thatsetup.py
would automatically read from its root directory and install in the current working directory. I'll have to read the docs again, carefully, to see if this isn't already written somewhere. I think half my problems are as a result of my haphazard process of reading between the lines from multiple sources and then looking at code examples to figure out what is happening without understanding what it does. -
abarnert over 11 years@elssar: I couldn't find anywhere it was said explicitly in the docs; I think they just make the same assumption I did. But I, like you, didn't exactly peruse them in detailed scrutiny.
-
Mark Teese over 4 yearsThis solution also worked for my docker container. In the DockerFile, instead of "RUN python /package/setup.py install", I needed "WORKDIR /package" and then "RUN python setup.py install"