Add a dll/so to a python built distribution - python

I've compiled the python wrapper of nanomsg and I want to create a python installer for the package.The package can be created by running
python setup.py bdist --format=wininst
However I would like nanomsg.dll/nanomsg.so to be included in the installer/package but I haven't found any documentation regarding this issue.

As stated in the documentation here one needs to add the following code to his setup.py script:
setup(
name='nanomsg',
version=__version__,
packages=[str('nanomsg'), str('_nanomsg_ctypes'), str('nanomsg_wrappers')],
data_files=[(
'lib\\site-packages\\', ["C:\\Dev\\external\\nanomsg\\x86\\Release\\nanomsg.dll"]
)],
)

Related

Created python package script not appearing to be installed

I'm on MacOSX (12.0.1) and with Python 3.9. I want to create a simple python package for personal use. Upon creating the package using python setup.py install, almost everything works: I can import the package when using python, etc. However, I've tried to follow every tutorial online to create an associated executable script. I.e., a command that I can execute from the shell that contains some functionality from the package I made. However, nothing has worked.
My setup.py code:
from setuptools import setup
setup(name='my_package',
version='1.0.0',
description='heeheehoohoo',
author='Me',
author_email='me#me',
url='me.com',
packages=['my_package'],
entry_points={
'console_scripts': ['mypkg=my_package:run']},
install_requires=['cairosvg',
'selenium',
'PyPDF2',
],
include_package_data=True,
zip_safe=False
)
And under my_package/__init__.py I have:
from . mine import main
def run():
import argparse
parser = argparse.ArgumentParser(prog = 'eeeeeee', description = 'eeeeee')
parser.add_argument('eeeeee', help = 'eeeeeee')
args = parser.parse_args()
print(f'eeeee ...')
main(args.eeeeeee)
print(f'Success!')
Everything gets installed, yet for some reason when I try to execute $ mypkg, I get zsh: command not found: mypkg. From python, I can import the function and directly try to execute run(). And strangest of all, each tutorial I have seen that has done anything like this can execute the commands without a problem once they'd executed python setup.py install.
Thank you!
Setting pip to the respective version of python and using pip install . instead of python setup.py install did the trick. However, it's still strange that python setup.py install does not work...

How do include cython files in python meson-managed project?

How do I properly include cython source files in a python meson project managed by the meson build system?
Cython as a first class language is still in progress (I'm the author of that work), right now the right way is with a generator or custom target, then compile an extension module:
pyx_c = custom_target(
'cython_file.c',
output : 'cython_file.c',
input : 'cython_file.pyx',
command : [cython, '#INPUT#', '-o', '#OUTPUT#'],
)
import('python').find_installation().extension_module(
'my_extension_module'
pyx_c,
install : true
)
Here's an example from the meson test suite, which is pretty close to my example above.
EDIT: cython as a first class language has landed. So if you can rely on Meson 0.59.0, you can just do:
import('python').find_installation().extension_module(
'my_extension_module'
'cython_file.pyx',
install : true
)
The simplest way I found (completely code-side) was to add them like any other source file and when you need to import them in a python file
just add
from pyximport import install
install(language_level=3)
before importing.
Best way is #dcbaker's though. I wrote an example pygobject cython application to show that here.

How to create setup.py with library file as stand alone

I have a problem, i develop an application with python and i use some libraries like flask, sqlalchemy, etc...
The problem is that i have a define version of each library, and I want to deploy this python application in another computer without internet,
can I create a package or use setup.py and include the other package with path ?
I've already try this code, but the library aren't imported they said that :
ModuleNotFoundError: No module named 'cx_Oracle'
My code is:
from distutils.core import setup
setup(
# Application name:
name="MyApplication",
# Version number (initial):
version="0.1.0",
# Packages
packages=["App","App/service"],
include_package_data=True,
install_requires=[
"flask","cx_Oracle","pandas","sqlalchemy"
],
)
install_requires is a setuptools setup.py keyword that should be used to specify what a project minimally needs to run correctly.
It won’t install those libraries.
Maybe you should try pyinstaller (https://www.pyinstaller.org) to make ready runnable file to run on the other computer.

Crosscompile Python bdist_wininst executeables

I'm using a 64bit Windows machine with 64bit python3. I need to build a installable package for a windows 32bit machine and stumbled upon the cross compile feature of the bdist feature: https://docs.python.org/3/distutils/builtdist.html
I'm using a setup.py like this:
from ez_setup import use_setuptools
use_setuptools()
from setuptools import setup, find_packages
setup(name='mypackage',
version='1.0',
description='Some Description',
install_requires=['requests'],
package_dir={'': 'src'},
packages=[''],
entry_points = {'console_scripts': ['somescript = foobar:main']},
)
And build the install packages like so:
python setup.py build --plat-name=win32 bdist_wininst --user-access-control auto
python setup.py build --plat-name=win-amd64 bdist_wininst --user-access-control auto
In both cases I get the correct executeable format for the specified architecture but the defined console_script somescript was not executeable after installation.
The python documentation says that I need to crosscompile the whole python package for windows - but I'am uncertain if this is even necessary because the installer was for the right architecture and I got no error message while the build process.
Is there something wrong with the command? Do I really need to crosscompile or is it sufficiant to have a second 32bit installation of python?
As I found out this is a reported bug https://github.com/pypa/setuptools/issues/253
The setuptools do only check for the OS architecture and ignore the plat-name string for the installation of scripts.
Workaround (until this issue is closed): Use the target architecture for building the wininst.

Python - install script to system

how can I make setup.py file for my own script? I have to make my script global.
(add it to /usr/bin) so I could run it from console just type: scriptName arguments.
OS: Linux.
EDIT:
Now my script is installable, but how can i make it global? So that i could run it from console just name typing.
EDIT: This answer deals only with installing executable scripts into /usr/bin. I assume you have basic knowledge on how setup.py files work.
Create your script and place it in your project like this:
yourprojectdir/
setup.py
scripts/
myscript.sh
In your setup.py file do this:
from setuptools import setup
# you may need setuptools instead of distutils
setup(
# basic stuff here
scripts = [
'scripts/myscript.sh'
]
)
Then type
python setup.py install
Basically that's it. There's a chance that your script will land not exactly in /usr/bin, but in some other directory. If this is the case, type
python setup.py install --help
and search for --install-scripts parameter and friends.
I know that this question is quite old, but just in case, I post how I solved the problem for myself, that was wanting to setup a package for PyPI, that, when installing it with pip, would install it as a system package, not just for Python.
setup(
# rest of setup
console_scripts={
'console_scripts': [
'<app> = <package>.<app>:main'
]
},
)
Details

Categories

Resources