I have a small python script (without modules) that I want to package via pex and execute. However, i could not find any option in the documentation (https://pex.readthedocs.io/en/latest/buildingpex.html) to package script without an entry point
I am using the following command
pex requests ./app -o app.pex --python-shebang '#!/usr/bin/env python3.9'
You can use setuptools with PEX.
Flow setup.py sample:
from setuptools import setup, find_packages
setup(
name='cli',
version='0.1.0',
packages=find_packages(),
include_package_data=True,
install_requires=[
'Click',
],
entry_points={
'console_scripts': [
'cli=pkgname.main:cli',
],
}
)
And run this in terminal:
$ python setup.py bdist_pex --bdist-all
I figured out that it is not possible hence i created a module and a main function.
Related
I have a project with the below structure:
projectname/projectname/__main__.py
I execute the program using python -m projectname.
If I want to install it locally in my system so that I can just call projectname, How can I achieve this?
You'll want to make a file setup.py in the top-level projectname that installs the package and adds some command (e.g. yeet) to your path. That command will call some function inside projectname/__main__.py:
from setuptools import setup
setup(
name='mypackagename',
version='0.0.1',
packages=['mypackagename'],
install_requires=[
'tensorflow>=2.0.0', # put your modules from requirements.txt here
],
entry_points={
'console_scripts': [
'yeet=projectname:function_to_run',
],
},
)
Using pip, you can easily install a package in tar form as in:
pip install https://path/to/respository/ending/with/en_core_web_sm-2.1.0/en_core_web_sm-2.1.0.tar.gz
However, I can't seem to get python setup.py install to find this same remote repository.
In setup.py, I have:
from setuptools import setup
setup(name='blah',
version='0.1.0',
description='A library',
install_requires=[
'en_core_web_sm-2.1.0.tar.gz'
],
dependency_links=[
'https://path/to/respository/ending/with/en_core_web_sm-2.1.0/en_core_web_sm-2.1.0.tar.gz'
],
packages=['blah'])
My error message is:
No local packages or working download links found for en_core_web_sm-2.1.0.tar.gz
error: Could not find suitable distribution for Requirement.parse('en_core_web_sm-2.1.0.tar.gz')
How can I accomplish the same with setup.py that I can with pip?
Figured it out. This tip from the spacy docs:
https://spacy.io/usage/models#production
You need to add #egg=en_core_web_sm to the end of the dependency_link. Final file looks like this:
from setuptools import setup
setup(name='blah',
version='0.1.0',
description='A library',
install_requires=[
'en-core-web-sm'
],
dependency_links=[
'https://path/to/respository/ending/with/en_core_web_sm-2.1.0/en_core_web_sm-2.1.0.tar.gz#egg=en_core_web_sm'
],
packages=['blah'])
When trying to run develop or install task of setuptools I am getting the Relative module names not supported error.
The command run is $ python -m setup.py develop
My setup.py script is pretty simple with one entry point:
setup(
name='foo',
version='1.2.3',
# ...
include_package_data=True,
packages=find_packages(),
entry_points={
'console_scripts': [
'foo = somepkg.somemodule:mainfunc'
]
},
install_requires=['requests',],
setup_requires=['pytest-runner'],
tests_require=['pytest', 'betamax', 'flexmock']
)
The issue was solved by not running setup.py as a module, i.e. running
$ python setup.py develop
instead of
$ python -m setup.py develop
I am trying to create an rpm of a python package using setuptools. Using the following command on linux:
$ python setup.py bdist --formats=rpm
The RPM builds fine; however, the requirement (cryptography), does not appear as a dependency in the RPM.
Is there any way to specify which dependencies this package requires?
The setup.py file looks like this:
from setuptools import setup, find_packages
if __name__ == "__main__":
setup(
name="dummy",
version=0.1,
description="This is a dummy package",
install_requires=[
"cryptography>=1.3.4",
],
)
From the following setup.py file, I am trying to create a pure-python wheel from a project that should contain only python 2.7 code.
from setuptools import setup
setup(
name='foo',
version='0.0.1',
description='',
url='',
install_requires=[
'bpython',
'Django==1.8.2',
],
)
However, when I run python setup.py bdist_wheel the wheel file that is generated is platform specific foo-0.0.1-cp27-none-macosx_10_9_x86_64.whl wheel file instead of the expected foo-0.0.1-cp27-none-any.whl. When I try to install this wheel on a different platform it fails saying it is not compatible with this Python.
I there something I need to change about the setup.py file or python interpreter, perhaps, that will allow this wheel to be used on any platform?
The simplistic way is to add --universal to your commandline, as you can see from running python setup.py bdist_wheel --help:
--universal make a universal wheel (default: false)
Alternatively you can add a setup.cfg file next to your setup.py that
takes care of this:
[bdist_wheel]
universal = 1
If you don't like yet another configuration file clobbering your package,
you can just write such a file in your setup.py just before it calls setup() and then remove it after that call returns, this is what I do
in the shared setup.py for all my projects on PyPI e.g. used in ruamel.yaml.
Adding the classifiers field to my setup.py fixed this issue.
from setuptools import setup
setup(
name='foo',
version='0.0.1',
description='',
url='',
classifiers=[
'Programming Language :: Python :: 2.7',
],
install_requires=[
'bpython',
'Django==1.8.2',
],
)
This part of the filename is controlled by the bdist_wheel option called python tag:
python2 setup.py bdist_wheel --help | grep python-tag
--python-tag Python implementation compatibility tag (default: 'py2')
However the default is generally 'py2' (or 'py3' for a python3 runtime), so to get a platform-specific wheel you must have something else in your configuration that is not shown in the question.
Regardless, you can specify the tag explicitly in your setup file:
from setuptools import setup
setup(
name="foo",
version="0.0.1",
...
options={"bdist_wheel": {"python_tag": "cp27"}},
)
This configuration will create a wheel named foo-0.0.1-cp27-none-any.whl.