I'm attempting to publish my module to PyPi but I'm running into troubles. It publishes, and I can install it via Pip, but I cannot seem to figure out the correct import statement to instantiate my class.
This is my setup.py file, the code lives in discord_webhooks.py within the same directory. Here's the published package.
from setuptools import setup, find_packages
long_description = open('README.md').read()
setup(
name='Discord Webhooks',
version='1.0.1',
packages=find_packages(exclude=['tests', 'tests.*']),
url='https://github.com/JamesIves/discord-webhooks',
author='James Ives',
author_email='iam#jamesiv.es',
description='Easy to use package for Python which allows for sending of webhooks to a Discord server.',
long_description=long_description,
license='MIT',
install_requires=[
'requests==2.20.0'
],
classifiers=[
'Programming Language :: Python :: 3'
],
)
I've attempted import DiscordWebhooks, and from discord_webhooks import DiscordWebhooks after doing pip install discord-webhooks but neither seem to work. Any help would be appreciated!
Managed to solve this one on my own. As this is a single file module I need to use py_modules inside of the setup.py file.
Here's the updated file:
from setuptools import setup, find_packages
long_description = open('README.md').read()
setup(
name='Discord Webhooks',
version='1.0.3',
py_modules=['discord_webhooks'],
url='https://github.com/JamesIves/discord-webhooks',
author='James Ives',
author_email='iam#jamesiv.es',
description='Easy to use package for Python which allows for sending of webhooks to a Discord server.',
long_description=long_description,
license='MIT',
install_requires=[
'requests==2.20.0'
],
classifiers=[
'Development Status :: 5 - Production/Stable',
'Environment :: Other Environment',
'Intended Audience :: Developers',
'License :: OSI Approved :: MIT License',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.6',
],
)
Related
I want to make my python app distributable but when I run it from command line from project folder all works well. After the packaging, there is a problem with module import.
All modules exists in package tlen. In my app I use eg. from Sender import Sender where Sender is tlen/Sender.py module.
All works well when I running tlen/main.py.
Problem exists when I try do package by sudo python setup.py install and run command tlen. Then I receive:
File "/usr/lib/python3.7/site-packages/tlen-1.0-py3.7.egg/tlen/main.py", line 3, in <module>ModuleNotFoundError: Nomodule named 'Sender'
Whole project:
https://github.com/tloszabno/tl_en
My setup.py file:
setuptools.setup(
name='tlen',
version='1.0',
author='Tomasz Łoś',
author_email='tloszabno#gmail.com',
description='A tool to learn foreign language',
packages=["tlen"],
entry_points={
'console_scripts': [
'tlen = tlen.main:main'
]
},
classifiers=[
'Programming Language :: Python :: 3',
'License :: OSI Approved :: MIT License',
'Operating System :: OS Independent',
],
)
What I doing wrong with imports?
Hah I've solved it!
Just added app.py file to main dir (.. of tlen) with content:
#!/usr/bin/env python
from tlen import main as app
def main():
app.main()
if __name__ == '__main__':
main()
then setup.py:
import setuptools
setuptools.setup(
name='tlen',
version='1.0',
author='Tomasz Łoś',
author_email='tloszabno#gmail.com',
description='A tool to learn foreign language',
packages=["tlen"],
entry_points={
'console_scripts': [
'tlen = app:main'
]
},
classifiers=[
'Programming Language :: Python :: 3',
'License :: OSI Approved :: MIT License',
'Operating System :: OS Independent',
],
scripts=[
'app.py',
]
)
I tried having long_description print when I build my wheel, and it prints just fine. But when I upload to PyPi it doesn't show my long description there. Here's my setup.py, hopefully someone can help figure this out.
from setuptools import setup
from codecs import open
from os import path
here = path.abspath(path.dirname(__file__))
with open(path.join(here, 'README.rst'), encoding='utf-8') as f:
long_description = f.read()
setup(
name='matchmod',
version='1.2.1',
description='Simple Rust-like pattern matching for Python, with some added features',
long_description=long_description,
url='https://github.com/AN3223/rustlike-pattern-matching-for-python',
author='AN3223',
classifiers=[
'Development Status :: 5 - Production/Stable',
'Intended Audience :: Developers',
'Topic :: Software Development :: Build Tools',
'License :: OSI Approved :: MIT License',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
],
keywords='rust rustlang procedural',
py_modules=['matchmod']
)
EDIT: I just realized I'm getting this error when building the wheel Error while finding module specification for 'setup.py' (AttributeError: module 'setup' has no attribute '__path__'), not sure what to do to solve this? I tried opening the file this way like the link from yausername suggested but still got the same error:
from pkg_resources import resource_string
long_description = resource_string(__name__, 'README.rst').decode('utf-8')
I use setuptools and a requirements file to satisfy dependencies for my open source module.
Example setup.py:
from setuptools import setup, find_packages
from pip.req import parse_requirements
# parse_requirements() returns generator of
# pip.req.InstallRequirement objects
install_reqs = parse_requirements('requirements.txt',
session=False)
# reqs is a list of requirement
reqs = [str(ir.req) for ir in install_reqs]
setup(
name='python-symphony',
version='0.1.5',
description='python module for symphony chat',
author='Matt Joyce',
author_email='matt#joyce.nyc',
url='https://github.com/symphonyoss/python-symphony',
license='Apache 2.0',
classifiers=[
'Development Status :: 3 - Alpha',
'Intended Audience :: Developers',
'Topic :: Software Development :: Build Tools',
'License :: OSI Approved :: Apache Software License',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.4',
],
keywords='symphony chat api python module',
# install dependencies from requirements.txt
install_requires=reqs,
packages=find_packages(),
# bin files / python standalone executable scripts
include_package_data=True,
zip_safe=False,
)
This has worked for some time. However, recently my builds have been breaking. I believe there is a bug in setuptools, possibly related to pygments.
There are two (thus far) identified failure states:
It results in the package being installed as a binary wheel (despite no such package existing in PyPI).
It results in the package installing in site-packages seemingly correctly, but none of the subclasses can be called from the module.
I can get it to work manually by removing the package from site packages and running:
pip install --isolated --no-cache-dir python-symphony
but this results in pygments getting messed up somehow. (I noticed this when trying to debug the module in bpython).
Trying to run this stuff from a venv (wrapped with a Bash script) tends to still fail.
Is anyone aware of a new / recent issue in setuptools that could be responsible for this sort of breakage?
setuptools version: setuptools-33.1.1.dist-info and newer
Ref:
github: https://github.com/symphonyoss/python-symphony
pypi: https://pypi.python.org/pypi/python-symphony/
I am writing a Django application and am very new to the framework and python. I am following the tutorial here: https://docs.djangoproject.com/en/1.9/intro/reusable-apps/ and am currently at packaging and installing the application created from this tutorial: https://docs.djangoproject.com/en/1.9/intro/tutorial01/
This is my first Django application and my first time using Python.
Currently my setup.py file looks like this:
import os
from setuptools import find_packages, setup
with open(os.path.join(os.path.dirname(__file__), 'README.rst')) as readme:
README = readme.read()
# allow setup.py to be run from any path
os.chdir(os.path.normpath(os.path.join(os.path.abspath(__file__), os.pardir)))
setup(
name= 'django-polls',
version='0.1',
packages=find_packages(),
include_package_date=True,
license='BSD License', #example license
description = 'A simple Django app to conduct Web-based polls.',
long_description = README,
url='https://www.example.com',
author='Your Name',
author_email='yourname#example.com',
classifiers=[
'Environment :: Web Environment',
'Framework :: Django',
'Framework :: Django :: 1.9.6', # replace "X.Y" as appropriate
'Intended Audience :: Developers',
'License :: OSI Approved :: BSD License', # example license
'Operating System :: OS Independent',
'Programming Language :: Python',
# Replace these appropriately if you are stuck on Python 2.
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Topic :: Internet :: WWW/HTTP',
'Topic :: Internet :: WWW/HTTP :: Dynamic Content',
],
)
my MANIFEST.in file looks like this:
include LICENSE
include README.rst
recursive-include polls/static *
recursive-include polls/templates *
recursive-include docs *
my file directory is as follows:
|polls
|__init.py__
|admin.py
|apps.py
|models.py
|tests.py
|urls.py
|views.py
|__pychache__
|# pycachestuff
|migrations
|# migrations stuff
|static
|polls
|images
|background.gif
|style.css
|templates
|polls
|detail.html
|index.html
|results.html
|docs
|
When I run the setup, the produced .zip works great, all the directories are included. However, when I run
pip install C:\Path\To\dist\django-polls-0.1.zip -t C:\Path\To\Package
It only installs what is immediately under the primary polls directory and migrations. It ignores the subdirectories static and templates. It also ignores docs, but the folder is empty and the tutorial has led me to believe empty directories are ignored.
Does anyone know how I can fix this? A few answers I have seen suggest using package_data or data_files, but I'm very new to python and I can't seem to get the syntax right (or those answers are wrong).
Thank you for your time
So, I've been trying this whole week to write a proper setup.py, and ended up with something like this:
#!/usr/bin/env python
from setuptools import setup
from codecs import open
from os import path
# Get the version number
from sql_tools2 import __version__
__author__ = 'Pandu POLUAN (pepoluan)'
__copyright__ = '(C) 2015, Pandu POLUAN'
__maintainer__ = 'pepoluan'
__email__ = 'pepoluan#gmail.com'
__status__ = 'Development'
__credits__ = ['pepoluan']
here = path.abspath(path.dirname(__file__))
# Get the long description from the README file
with open(path.join(here, 'README.rst'), encoding='utf-8') as f:
long_description = f.read()
setup(
name='sql_tools2',
version=__version__,
description='Tools to manipulate and analyze SQL Queries before execution.',
long_description=long_description,
url='https://bitbucket.org/pepoluan/sqltools2',
author='Pandu POLUAN',
author_email='pepoluan#gmail.com',
license='MPL 2.0',
classifiers=[
'Development Status :: 4 - Beta',
'Intended Audience :: Developers',
'Intended Audience :: System Administrators',
'Programming Language :: SQL',
'Topic :: Software Development :: Quality Assurance',
'Topic :: Database',
'License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7'
],
keywords='sql subquery',
packages=['sql_tools2'],
install_requires=['sqlparse'],
extras_require={
'dev': ['pytest'],
'test': ['pytest'],
},
zip_safe=False
)
Now if I execute setup.py install, I see the module being installed.
However, another Python program (same virtualenv) cannot import:
>>> import sql_tools2
ImportError: no module named sql_tools2
I am using PyCharm as the IDE. Interestingly, if I type import and wait for auto-completion, PyCharm indeed offered sql_tools2 as one of the modules it recognized.
Where did I go wrong?