Reputation: 13
I have a huge problem to create proper python setup script. My folder structure looks like this:
my_project/
my_project/
--__init__.py
--file_1.py
--file_2.py
--file_3.py
-AUTHORS
-CHANGELOG
-INSTALL
-LICENSE
-README.rst
-setup.cfg
-setup.py
I have created a setup script, but it does not behave like I want to. The setup script:
from ez_setup import use_setuptools
use_setuptools()
import os
import sys
from setuptools import setup, find_packages
readme_file = os.path.join(os.path.dirname(__file__), 'README.rst')
try:
long_description = open(readme_file).read()
except IOError, err:
sys.stderr.write("[ERROR] Cannot find file specified as ""``long_description`` (%s)\n" % readme_file)
sys.exit(1)
setup(
name = 'my_project',
version='0.0.1',
author = 'AUTHOR',
author_email = 'CONTACT',
url = 'http://example.com',
description= 'Some description',
long_description = long_description,
packages = find_packages('my_project'),
package_dir = {'':'my_project'},
package_data = {'':['*.py']},
include_package_data = True,
scripts = [],
requires = [],
license = 'BSD License',
install_requires = [
'some_packages',
],
classifiers = [
'Development Status :: 2 - Pre-Alpha',
'Environment :: Web Environment',
'Intended Audience :: Developers',
'License :: OSI Approved :: BSD License',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
'Topic :: Database',
'Topic :: Internet',
'Topic :: Software Development :: Libraries :: Python Modules',
],
keywords = 'python, setup, script, the best',
)
After this:
sudo python setup.py alias release register sdist bdist_egg upload
sudo python setup.py release
Everything is fine, up to this point, but when I try:
sudo pip install my_project
I only get in /usr/local/lib/python2.7/dist-packages/ a folder called my_project-0.0.1.egg-info/, but there are no my_project with init, file_1, file_2, file_3 python files.
I know that my_project-0.0.1.egg-info/ is required, but where are my files?
Then I tried:
sudo python setup.py install
With no effect, but this time I got a folder my_project-0.0.1-py2.7.egg.
I want to get in /usr/local/lib/python2.7/dist-packages/ two directories:
- my_project-0.0.1.egg-info/
- my_project with my files
Upvotes: 1
Views: 294
Reputation: 365657
Your problem is in this line:
package_dir = {'':'my_project'},
You're telling it that my_project
is the place to find top-level packages. So, find_packages('my_project')
is going to look for a package inside your top-level directory (my_project
) at my_project/my_project
. Since there is no such thing, you end up with an empty package.
Just remove that line, and everything will work.
While we're at it, you're over-complicating things a little bit. You're not using anything out of ez_setup
, so it would be simpler to remove the first two lines. And you're just adding a single static package, so there's really no reason to use find_packages
; you can just use packages = ['my_project']
instead.
Meanwhile, here's how to debug stuff yourself in the future.
First, don't try sudo python setup.py alias release register sdist bdist_egg upload
until you've actually got things working. It's a lot easier to debug local files than something you've already uploaded to PyPI. Just do python setup.py sdist
, then you can look at the resulting tarball and make sure it looks OK, then try pip install .
and/or pip install dist/my_project-0.0.1.tar.gz
to make sure it actually works.
Second, setup.py
is just normal Python code; you can always log things to see what's going on. For example, if find_packages('my_project')
doesn't seem to be working right, try doing a print(find_packages('my_project'))
before the setup(…)
to see what it's doing.
Upvotes: 1