I have written a python package I'm trying to install. With a structure:
packagename
|
|--- setup.py
|--- module_name
|
|--- library.c
The library.c file has been successfully installed outside of this package using:
gcc library.c -Wall -pedantic -o spec_conv -lm -O2
My setup.py file looks like:
from setuptools import setup, Extension
with open("README.md", "r") as fh:
long_description = fh.read()
module = Extension('library',
sources = ['module_name/library.c'],
extra_compile_args=['-Wall', '-pedantic', '-o', 'library', '-lm', '-O2'])
setup(
name="module_name", # Replace with your own username
version="0.0.1",
author="",
author_email="",
description="",
long_description=long_description,
long_description_content_type="text/markdown",
packages=setuptools.find_packages(),
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
],
python_requires='>=3.6',
install_requires=[
'pandas',
'pexpect'],
#cmdclass={'install': CustomInstall},
#include_package_data=True,
ext_modules=[module],
)
When I run pip install -e . the compile returns an error message:
https://pastebin.com/hMLA95G9
Following on from #9769953's comment I've tried to edit the setup.py to directly link to the full path of the file:
from pathlib import Path
ROOT_PATH = Path(__file__).parent.resolve()
module = Extension('spec_con',
sources = ['spec_conv/spec_con.c'],
extra_compile_args=['-Wall', '-pedantic', '-o', f'{ROOT_PATH}/module_name/library', '-lm', '-O2'],
library_dirs=["/home/alletro/python_packages"])
But I still get the same error.
The error is from the linker, that can't find the object file build by the compiler. The object file can't be found, because you specify the object file path manually, and it ends up in the wrong place.
The solution is to remove the '-o', 'library' items from the extra_compile_args option to Extension.
That way, Distutils and gcc will then automatically provide the correct name for the resulting object file (in particular, the correct full directory path), which can then be picked by the linker successfully.
Related
I am working on a project which I have to share as a standalone SDK with my team. For some reason files other than *.py are not being added to my distribution file
My project structure is as given below
My Setup.py is like this
import setuptools
from glob import glob
from os.path import basename
from os.path import splitext
with open("README.md", "r") as fh:
long_description = fh.read()
with open('requirements.txt') as f:
install_requires = f.read().splitlines()[2:]
with open('requirements-dev.txt') as f:
tests_require = f.read().splitlines()[2:]
extras = {
'test': tests_require,
}
setuptools.setup(
name='eu-taxonomy-sdk',
version='0.0.2',
author='Bhushan Fegade',
author_email='bhushan.fegade#morningtar.com',
description='a calculation library for eu-taxonomy',
long_description=long_description,
long_description_content_type='text/markdown',
url='https://msstash.morningstar.com/scm/dataapi/eu-taxonomy-sdk.git',
packages=setuptools.find_packages(where='src'),
package_dir={'': 'src'},
package_data={'eu-taxonomy-sdk': [ 'config/*', 'category/config/*' ]},
py_modules=[splitext(basename(path))[0] for path in glob('src/*.py')],
license='Apache Software License',
classifiers=[
'Programming Language :: Python :: 3',
'License :: OSI Approved :: Apache Software License',
'Operating System :: OS Independent',
],
install_requires=install_requires,
python_requires='~=3.8',
tests_require=tests_require,
extras_require=extras,
test_suite='tests'
)
I am using the following commands to generate a distributable file
python setup.py build
python setup.py sdist
I have tried making some changes in the setup.py file but the distributable file inside the config folder is always empty with only the init.py file and no other file is present.
I want to know if there is a way to keep those other files(CSV, parq) in the final distributable file.
Add a MANIFEST.in file that describes the files you need included.
E.g.
recursive-include src *.csv *.parq
Here is my setup.py
from setuptools import setup, find_packages
import versioneer
REQUIRES = [
"requests",
"subprocess32",
"systemd"
]
CLASSIFIERS = [
...
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.6"
]
setup(
author="IBM",
cmdclass=versioneer.get_cmdclass(),
description="A collections of utilities",
entry_points={},
install_requires=REQUIRES,
keywords=["management", "segment_sqls"],
license="XXX",
long_description="""Utilities for instance management and house keeping""",
packages=find_packages(),
tests_require=["pytest"],
url="https://github.ibm.com/myrepo/management",
name="management",
version=versioneer.get_version(),
classifiers=CLASSIFIERS
)
I am trying to run python3 setup.py sdist upload -r local to package and upload to my artifactory.The package's tar.gz is uploaded to artifactory with all files except the ones under segment_sqls. Here is my directory structure. init.py under segment_sqls is packaged but not the actual sql files. Is there any additional param that needs to be specified in setup.py to include all files?
I have a single python file right now and I am asked to convert it into a python module where the user can install it using python setup.py install. I am not sure how to do that. I have followed some instructions online and created the setup.py file and the init.py file. The setup.py file looks like this:
import setuptools
with open("README.md", "r") as fh:
long_description = fh.read()
setuptools.setup(
name="",
version="0.0.1",
author="",
author_email="",
description="",
long_description=long_description,
long_description_content_type="text/markdown",
url="https://github.com/pypa/sampleproject",
packages=setuptools.find_packages(),
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
],
python_requires='>=3.6',
)
I am not sure if this setup.py file is correct.Also I don't know what I am supposed to do next. Can anyone help me and tell me what am I supposed to do? Is there tutorial that teaches this? I can't really find anything related. Also is my setup.py correct? Thanks!
There are several ways to do packaging. packaging Python Projects on python.org and setuptools docs are a good start.
Unfortunately, examples tend to focus on package distributions, not single modules. Instead of packages, use the py_modules keyword. Assuming your module is called "test.py", this setup.py will work
import setuptools
with open("README.md", "r") as fh:
long_description = fh.read()
setuptools.setup(
name="test",
version="0.0.1",
author="",
author_email="",
description="",
long_description=long_description,
long_description_content_type="text/markdown",
url="https://github.com/pypa/sampleproject",
py_modules = ["test"],
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
],
python_requires='>=3.6',
)
If you think this will expand to multiple modules, then you can go back to using
setuptools.find_packages(). In this case, you want a subdirectory named after your desired package and put the init in there
some_random_project_file
+-- setup.py
README.md
LICENCE
+-- test
+-- __init__.py
test.py
I wrote a Python C extension, and it works great. Installing via python setup.py install works. However, pip cannot find my header files - so a pip installation doesn't work.
> pip install
Collecting jcalg1==1.0.1
Downloading https://files.pythonhosted.org/packages/a1/83/08b5fc2fbd36c8ac0668ae64c05cc88f3f6bd8fe68f058b19b11a463afa1/jcalg1-1.0.1.tar.gz
Installing collected packages: jcalg1
Running setup.py install for jcalg1 ... error
ERROR: Command errored out with exit status 1:
(...)
src\main.cpp(7): fatal error C1083: Cannot open include file: 'jcalg1.h': No such file or directory
(...)
This is my setup.py, the header file is located in the src folder.
from setuptools import setup,Extension
import setuptools
from setuptools import find_packages
import pathlib
# The actual C extension
jc_module = Extension('jcalg1', include_dirs=["src"], sources = ['src\main.cpp'], libraries =["src\jcalg1_static"])
# The directory containing this file
HERE = pathlib.Path(__file__).parent
# The text of the README file
README = (HERE / "README.md").read_text()
# This call to setup() does all the work
setup(
name="jcalg1",
version="1.0.1",
description="Interface to the JCALG1 compression library",
long_description=README,
long_description_content_type="text/markdown",
url="https://github.com/CallMeAlexO/jcalg1",
author="Alex Osheter",
author_email="alex.osheter#gmail.com",
license="MIT",
classifiers=[
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.7",
],
ext_modules = [ jc_module ],
packages=find_packages()
)
You can create a MANIFEST.in file in your project root directory:
include src\*.h
include src\*.lib
Then rebuild your package. It will add the header files and library files into your package.
I'm packaging my project via setup.py of a following structure:
import os
from setuptools import setup
def read(fname):
return open(os.path.join(os.path.dirname(__file__), fname)).read()
setup(
name = "blah",
version = "0.0.1",
author = "Chuck Norris",
author_email = "xyz#gmail.com",
description = ("blah blah blah."),
license = "BSD",
keywords = "django",
url = "http://packages.python.org/blah",
packages=['blah'],
long_description=read('README'),
classifiers=[
"Development Status :: 3 - Alpha",
"Topic :: Utilities",
"License :: OSI Approved :: BSD License",
],
)
My directory structure is
folder/
--blah/__init__.py
--blah/other stuff
--readme
--setup.py
When installing the .egg with pip, I get error IOError: [Errno 2] No such file or directory: '/tmp/pip-Us23IZ-build/setup.py'.
When unzipped, egg does not contain setup.py, indeed. I'm not sure whether it should, or not, or is it of any relevance to the error at all.
Thanks.
It is likely, you have setup.py in wrong directory.
Proper directory structure is:
projectroot/
setup.py
README
blah/
__init__.py
<whatever other modules your package needs>
Packaging (calling the setup.py to build an egg or other distribution package) shall be done from projectroot.
After creation of the egg file, you shall visit it (the egg file is zip archive) and check, if setup.py is present.