I wrote a small python program and now I want to install and use it on my system.
Program structure:
projectname
|--src
| |--main.py #import file1
| |--file1.py #import file2
| |--file2.py
|--LICENSE
|--README.md
|--setup.py
I did sudo python setup.py install, but now I only able to run it with /usr/bin/main.py. What should I do, to be able to run it by only typing a projectname?
EDIT: Setup.py content:
setuptools.setup(
name="projectname",
version="0.0.1",
packages=setuptools.find_packages(),
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
],
entry_points={
"console_scripts": [
"projectname = projectname.src/main:main"
]
},
python_requires='>=3.6',
)
You can use setuptools' entry points in your setup.py.
Example from the documentation:
setup(
# other arguments here...
entry_points={
"console_scripts": [
"foo = my_package.some_module:main_func",
"bar = other_module:some_func",
],
"gui_scripts": [
"baz = my_package_gui:start_func",
]
}
)
With your structure, create file src/__init__.py:
from . import main
and lets say that this is src/main.py:
def main():
print("Hello world")
Finally, setup.py can be:
import setuptools
setuptools.setup(
name="projectname",
version="0.0.1",
packages=setuptools.find_packages(),
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
],
entry_points={
"console_scripts": [
"projectname = src:main.main"
]
},
python_requires='>=3.6',
)
Related
I'm trying to push a project package to pypi (it's my first time doing so) from gitlab, and I'm following their turorial [here][1]. However, when I am trying python3 -m twine upload --repository gitlab dist/* the console returns me HTTPError: 422 Unprocessable Entity from https://gitlab.com/MyProfile/mylib
I don't know what is wrong ?
my .pypirc file looks like this
[distutils]
index-servers =
gitlab
[gitlab]
repository = https://gitlab.com/FiiireFlyyy/firelib
username = my_token
password = my_token_password
and here is my setup.py
# Always prefer setuptools over distutils
from setuptools import setup, find_packages
# To use a consistent encoding
from codecs import open
from os import path
# The directory containing this file
HERE = path.abspath(path.dirname(__file__))
# Get the long description from the README file
with open(path.join(HERE, 'README.md'), encoding='utf-8') as f:
long_description = f.read()
# This call to setup() does all the work
setup(
name="firelib",
version="0.1.0",
description="Demo library",
long_description=long_description,
long_description_content_type="text/markdown",
url="https://gitlab.com/FiiireFlyyy/firelib",
author="Willy Lutz",
author_email="myemail0willy#gmail.com",
license="no licence",
classifiers=[
"Intended Audience :: Developers",
"License :: OSI Approved :: no licence",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Operating System :: OS Independent"
],
packages=["firelib"],
include_package_data=True,
install_requires=["os", "shutil"]
)
My file tree is :
firelib (pycharm project folder)
|-----dist (directory)
|-----firelib (package)
|-----firelib.egg-info (directory)
|-----venv
|-----LICENCE
|-----README
|-----setup.py
|-----requirements.txt
I'm really bad with config stuff. Can someone help me ?
Edit : i put the real neames of packages insteand of 'myProfile' and 'mylib'
[1]: https://docs.gitlab.com/ee/user/packages/pypi_repository/
I need to have different versions of elasticseach-dsl installed in the same virtualenv. I would like to be able to import them using some sort of alias:
import elasticsearch_dsl1
import elasticsearch_dsl2
import elasticsearch_dsl5
I was thinking to create packages called elasricsearch_dsl* and in their setup.py add install requirements for the proper version of elasticsearch_dsl but when I install the packages it results in a conflict because all my packages require different versions of the same library.
I have no clue on how to proceed and if this is possible.
Thanks a lot to everyone
Short answer:
It is not possible.
I was able to find a solution to my problem.
I downloaded the source code of the elasticsearch-dsl libraries of different versions
Then changed the import statements to use elasticsearch1, elasticsearch2 etc.libraries instead of elasticsearch v1.x and v2.x
# example `elasticsearch-dsl` v5.4.0
from elasticsearch import Elasticsearch # --> from elasticsearch5 import Elasticsearch
Modified the setup.py to change the dependencies from elasticsearch to elasticsearch1, elasticsearch2 and so on for each version of the elasticsearch-dsl
I've been very lucky because of the existence of elasticsearch1, elasticsearch2... otherwise I would have to repeat the same procedure for them. And more lucky for the compatibility of dependencies of the various versions of the library.
I'm not proud of this hack but it worked.
setup.py
An example of a setup.py file for elasticsearch-dls==7.3.0, then elasticsearch-dsl7
from os.path import join, dirname
from setuptools import setup, find_packages
VERSION = (7, 3, 0)
__version__ = VERSION
__versionstr__ = ".".join(map(str, VERSION))
f = open(join(dirname(__file__), "README"))
long_description = f.read().strip()
f.close()
install_requires = [
"six",
"python-dateutil",
"elasticsearch7", # before "elasticsearch>=7.0.0,<8.0.0" <---
# ipaddress is included in stdlib since python 3.3
'ipaddress; python_version<"3.3"',
]
tests_require = [
"mock",
"pytest>=3.0.0",
"pytest-cov",
"pytest-mock<3.0.0",
"pytz",
"coverage<5.0.0",
]
setup(
name="elasticsearch-dsl7", # <---
description="Python client for Elasticsearch",
license="Apache-2.0",
url="https://github.com/elasticsearch/elasticsearch-dsl-py",
long_description=long_description,
version=__versionstr__,
author="Honza Král",
author_email="honza.kral#gmail.com",
maintainer="Seth Michael Larson",
maintainer_email="seth.larson#elastic.co",
packages=find_packages(where=".", exclude=("test_elasticsearch_dsl*",)),
python_requires=">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*",
classifiers=[
"Development Status :: 4 - Beta",
"License :: OSI Approved :: Apache Software License",
"Intended Audience :: Developers",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 2",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.4",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
],
install_requires=install_requires,
test_suite="test_elasticsearch_dsl.run_tests.run_all",
tests_require=tests_require,
extras_require={"develop": tests_require + ["sphinx", "sphinx_rtd_theme"]},
)
I have the following tree:
myPackage
|_myPackage
| |_mainScript.py
| |_f1.py
| |_f2.py
| |_Rscript.R
| |_ __init__.py
|_setup.py
|_MANIFEST.in
|_README.md
My aim is to create a setup.py file to install myPackage and to make it callable directly using the mypackage command from terminal.
the setup block from the setup.py code looks like this:
setup(
name=NAME,
version="1.0.0",
long_description=ldesc,
long_description_content_type="text/markdown",
author=AUTHOR,
author_email=EMAIL,
python_requires=REQUIRES_PYTHON,
url=URL,
packages=["myPackage"],
install_requires=REQUIRED,
package_data={"": ["*.R"]},
include_package_data=True,
entry_points={
"console_scripts": [
"mypackage=myPackage:main",
],
},
#include_package_data=True,
classifiers=[
"License :: OSI Approved :: GNU Lesser Public License v3 or Later",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.6",
"Programming Language :: R",
"Programming Language :: R :: 3",
"Programming Language :: R :: 3.6",
"Development Status :: 3 - Alpha",
"Operating System :: OS Independant",
],
)
Installation works, but I get the errorModuelNotFoundError: No module nmed "myPackage".
I also tried to use:
package_dir = {"": "myPackage"},
packages = find_packages()
scripts=["myPackage/mainScript.py.py"]
However, it returns the same error.
I would appreciate some help on this. I'm using Python3.6.0 and Ubuntu.
Thank you!
How about
"console_scripts": ["mypackage=myPackage.mainScript:main"],
assuming that's where def main(): lives?
I am trying to build a wheel and source distribution on windows 10 for a project of mine, but the build freezes at removing 'release-exporter-1.0' (and everything under it) for sdist and creating build\bdist.win-amd64\wheel\release_exporter-1.0.dist-info\WHEEL for bdist_wheel.
Following is my setup.py
setup(
name='release-exporter',
version=version(),
install_requires=get_requirements('requirements.txt'),
packages=find_packages(),
url='https://github.com/akshaybabloo/release-exporter',
license='MIT',
author='Akshay Raj Gollahalli',
author_email='akshay#gollahalli.com',
description='Release exporter for GitHub and GitLab.',
keywords="changelog releases",
classifiers=[
'License :: OSI Approved :: MIT License',
'Programming Language :: Python :: 3 :: Only',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Intended Audience :: Developers',
'Environment :: Console',
'Development Status :: 5 - Production/Stable',
'Topic :: Utilities'
],
entry_points={
'console_scripts': [
'rex = release_exporter:main'
]
},
)
I have tried to manually give the package name from ['release_exporter'] to using find_packages() of setup tools. I also thought the keyword should be a string, so I changed it from ['changelog', 'releases'] to "changelog releases". But still no luck.
Also, I have tried to set --verbose flag by doing python setup.py sdist --verbose, but it doesn't work. I think the bug is not rectified yet -> https://bugs.python.org/issue7202
Any help would be appreciated.
Update
I am using Python 3.6.3
Its a bug in Python 3.6.3 -> https://docs.python.org/3.6/whatsnew/changelog.html#build. Just in case if anyone has a problem, update your Python to Python 3.4.4.
I'm trying to use pip to get an environment set up, and running pip install -e ./ from the root directory of my project isn't picking everything up. I've got a setup.py file with a requires section that looks like so:
requires = [
'phonenumbers',
'inflect',
'repoze.sendmail==4.1',
'pyramid',
'pyramid_chameleon',
'pyramid_debugtoolbar',
'pyramid_mailer',
'pyramid_tm',
'transaction',
'zope.sqlalchemy',
'waitress',
'pyramid_beaker',
'cryptacular',
'pycrypto',
'webtest',
'alembic',
'psycopg2',
'python-dateutil',
'sqlalchemy-utils',
'cryptacular',
'arrow',
'jsonpickle',
'sqlalchemy',
'pyramid_storage',
'boto',
'requests'
]
When the command is run, some libraries, such as boto, won't be installed. Does anyone know why these packages would be missed?
Edit: Here's the call to setup in setup.py, with some irrelevent bits ommited:
dependency_links = [
'git+https://github.com/benthor/inflect.py#egg=inflect',
]
setup(
classifiers=[
"Programming Language :: Python",
"Framework :: Pyramid",
"Topic :: Internet :: WWW/HTTP",
"Topic :: Internet :: WWW/HTTP :: WSGI :: Application",
],
author='',
author_email='',
url='',
keywords='web wsgi bfg pylons pyramid',
packages=find_packages(),
include_package_data=True,
zip_safe=False,
test_suite='test',
install_requires=requires,
dependency_links=dependency_links
)
The requires argument to setup() doesn't actually do anything, and for all intents and purposes should be considered deprecated and useless.
Use install_requires instead.